Node Sets in Transformations

Node sets are one of four basic data types that are returned from XML Path Language (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.

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. You can perform Extensible Stylesheet Language for Transformations (XSLT) transformations using the XslCompiledTransform class. See Using the XslCompiledTransform Class and Migrating From the XslTransform Class for more information.

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 XML Document Object Model (DOM). You can navigate a node set using a set of methods shown in Node Set Navigation Using XPathNavigator, unlike a result tree 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.

Style Sheet

<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

Reference

XPathNodeIterator

XPathNodeIterator

Concepts

XSLT Transformations with the XslTransform Class

XslTransform Class Implements the XSLT Processor