[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Adding Missing Elements

Subject: Re: Adding Missing Elements
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Tue, 13 Sep 2005 21:48:36 +0200
xsl missing element
Hi,

Tempore 18:01:35, die 09/13/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Emerson, Matt <Matt.Emerson@xxxxxxx>:

Given these possible variations and based on some processing elsewhere
in the document, I would like to make sure that <node> always has
<item>B</item> in its list...possibly adding <list> if it is not
present.

Can someone give me some suggestions on the best way to do this?
"The best way to do this" does not exist, it's amatter of personal personal style.

Here's a solution that I perceive as most elegant:

<xsl:stylesheet version="1.0" xmlns:var="myvar"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
<xsl:output method="xml" indent="yes"/>

<var:root>
	<list>
		<item>B</item>
	</list>
</var:root>

<xsl:variable name="var" select="document('')/xsl:stylesheet/var:root/*"/>

<xsl:template match="node()|@*">
	<xsl:copy>
		<xsl:apply-templates select="node()|@*" />
	</xsl:copy>
</xsl:template>

<xsl:template match="node|list|item">
	<xsl:element name="{local-name()}">
		<xsl:apply-templates select="@*" />
		<xsl:apply-templates select="
			$var[current()/self::node][not(current()/list)]|
			$var[current()/self::list]/item[not(.=current()/item)]|
			node()" />
	</xsl:element>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+Et ipsa scientia potestas estB;  - Francis Bacon , Meditationes sacrae

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.