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.

Example

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.

nodeset.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="https://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:

Output

<?xml version="1.0" encoding="utf-8"?>

<authors><author>Michael Howard</author><author>Michael Kay</author></authors>

See Also

XslTransform Class Implements the XSLT Processor