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

RE: Adding a node to an existing node set

Subject: RE: Adding a node to an existing node set
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 23 Jul 2002 07:53:49 +0300
adding to node set

> Say the XPath expression ="/parent/child" returns all
> children, how can I add a new child element and have
> the resulting node set assigned to a variable.
> I tried 
> <xsl:variable name="newTree">
>     <xsl:copy-of select="/parent/child"/>
>     <child age="1">foo</child>
> </xsl:variable>

That would work. Note, however, that here you're binding a RTF to the variable, and that is immutable.

> However there seems to be a difference between
> <xsl:variable name="newTree" select="/parent/child"/>
> and 
> <xsl:variable name="newTree">
>     <xsl:copy-of select="/parent/child"/>
> </xsl:variable>

Yes, the former binds a node-set to the variable, the latter a RTF. See http://www.w3.org/TR/xslt#section-Result-Tree-Fragments

> Amont other things, the attributes seem to have
> disappeared.

Which attributes? If all child elements have an age attribute, they will be preserved. Which XSLT processor are you using?

> Also when I try 
> <xsl:variable name="newTree">
>     <xsl:for-each select="/parent/child">
>        <xsl:copy-of select="."/>
>     </xsl:for-each>
> </xsl:variable>
> Saxon complains saying : "Cannot write an attribute
> when there is no open start tag"

Err... it shouldn't, since the for-each selects a node-set of element nodes, and no attributes are copies directly. That would suggest that the problem is not in the code above, but rather somewhere else in you stylesheet.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.