msxsl:node-set 関数を使用すると、結果ツリー フラグメントをノード セットに変換できます。 結果として得られるノード セットには、常に単一のノードが含まれています。また、このノード セットは、常にそのツリーのルート ノードです。
![]() |
---|
.NET Framework Version 2.0 では、XslTransform クラスが廃止されています。XslCompiledTransform クラスを使用して XSLT (Extensible Stylesheet Language for Transformations) 変換を実行できます。詳細については、「XslCompiledTransform クラスの使用」および「XslTransform クラスからの移行」を参照してください。 |
msxsl:node-set 関数を使用すると、結果ツリー フラグメントをノード セットに変換できます。 結果として得られるノード セットには、常に単一のノードが含まれています。また、このノード セットは、常にそのツリーのルート ノードです。
例
$var という変数がスタイル シート内のノード ツリーである例を次に示します。 for-each ステートメントを 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>
出力
変換による出力は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<authors><author>Michael Howard</author><author>Michael Kay</author></authors>