This topic has not yet been rated - Rate this topic

Support for the msxsl:node-set() Function

The msxsl:node-set function enables you to convert a result tree fragment into a node set. The resulting node set always contains a single node and is the root node of the tree.

NoteNote

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.

The msxsl:node-set function enables you to convert a result tree fragment into a node set. The resulting node set always contains a single node and is the root node of the tree.

In the following example, $var is a variable that is a node tree in the style sheet. The for-each statement combined with the node-set function allows the user to iterate over this node tree as a node set.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="http://www.contoso.com"
                version="1.0">
    <xsl:variable name="books">
        <book author="Michael Howard">Writing Secure Code</book>
        <book author="Michael Kay">XSLT Reference</book>
    </xsl:variable>

    <xsl:template match="/">
        <authors>
            <xsl:for-each select="msxsl:node-set($books)/book"> 
                <author><xsl:value-of select="@author"/)</author>
            </xsl:for-each>
        </authors>
    </xsl:template>
</xsl:stylesheet>

The output of the transformation is

<?xml version="1.0" encoding="utf-8"?>
<authors><author>Michael Howard</author><author>Michael Kay</author></authors>
Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.