Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: variables

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent