Export (0) Print
Expand All

Node Sets in Transformations

Node sets are one of four basic data types that are returned from XPath expressions. A node set, which is an unordered collection of nodes without duplicates, created in document order, can be assigned to a variable in a style sheet. This node set, which is a result of an XPath expression used in a select attribute in a transformation, has the same behavior as a node set from the DOM. You can navigate a node set using a set of methods shown in Node Set Navigation Using XPathNavigator, unlike a node fragment or result tree fragment, which uses the XPathNodeIterator for navigation.

The following code sample shows how to iterate over a node set when a variable or parameter element in a style sheet evaluates to a node set.

Stylesheet

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:variable name="x" select="bookstore/book/title"></xsl:variable>

    <xsl:template match="/">
        <xsl:for-each select="$x">
            ******
            <xsl:value-of select="."></xsl:value-of>
            ******
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

Input

<bookstore>
   <book style="autobiography">
      <title>Seven Years in Trenton</title>
   </book>

   <book style="autobiography">
      <title>Seven Years in Trenton2</title>
   </book>

   <book style="textbook">
      <title>History of Trenton Vol 3</title>
   </book>
</bookstore>

Output:

            ******
            Seven Years in Trenton
            ******
        
            ******
            Seven Years in Trenton2
            ******
        
            ******
            History of Trenton Vol 3
            ******

See Also

XSLT Transformations with the XslTransform Class | XslTransform Class Implements the XSLT Processor | XPathNodeIterator Class | XPathNodeIterator Members

Show:
© 2014 Microsoft