Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: variables [Thread Next] Re: variablesTo: NULL Date: 4/8/2007 5:13:00 PM RedLars wrote: > The bit below, makes a sorted copy of the computer element and > children elements (attributes included) to the variable rtf? > <xsl:variable name="rtf"> > <xsl:for-each select="computer"> > <xsl:sort select="@number" data-type="number"/> > <xsl:copy-of select="."/> > </xsl:for-each> > </xsl:variable> Yes, that part sorts the computer elements thereby creating a result tree fragment containing the sorted computer elements under a root node. On a result tree fragment you cannot apply full XPath, rather you can mainly copy it to the final result tree. <http://www.w3.org/TR/xslt#section-Result-Tree-Fragments> > Unsure of the below code, it seems to convert the above 'tree- > structure' to a node-set. What does a node-set entail? Does that > enable one to traverse (for-each) the structure? > > <xs:variable name="sorted-computers" select="msxsl:node-set($rtf)" > xmlns:msxsl="urn:schemas-microsoft-com:xslt"> With XSLT 1.0 you transform an input tree to a result tree. On the input tree you can apply all sort of XPath expressions. However if you use a variable like above then you have a result tree fragment on which you cannot apply the full power of XPath. To be able to apply the full power of XPath you need to convert the result tree fragment to a node set. Doing that is not possible with the XSLT 1.0 standard functionality, you need an extension function for that like msxsl:node-set. > The final bit of code, is $Sorted-computer pointing to the root > element and therefore you need to specify further by adding /computer? > I thought the rtf variable only contained "computer" elements, so why > the need for /computer? > <xsl:for-each select="$sorted-computers/computer"> The variable contains the sorted computed elements, but under a root node. Using msxsl:node-set you get a node set with a root node containing the sorted computer elements. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
