XSLT <xsl:apply-templates>要素
完全な XSLT 要素リファレンス
定義と使用法
<xsl:apply-templates> 要素は、現在の要素または現在の要素の子ノードにテンプレートを適用します。
<xsl:apply-templates> 要素に select 属性を追加すると、その属性の値に一致する子要素のみが処理されます。select 属性を使用して、処理する子ノードの順序を指定できます。
構文
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
属性
| 属性 | 值 | 説明 |
|---|---|---|
| select | expression | 省略可能。処理するノードを指定します。アスタリスクはノードセット全体を選択します。この属性を省略すると、現在のノードのすべての子ノードが選択されます。 |
| mode | name | 省略可能。同じ要素に対して複数の処理方法が定義されている場合、mode を使用してそれらを区別できます。 |
例 1
ドキュメント内の各 title 要素を h1 要素で囲みます:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>
</xsl:stylesheet>
例 2
ドキュメント内で message の子要素であるすべての title 要素を h1 要素で囲みます:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="title"/></h1>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="title"/></h1>
</xsl:template>
</xsl:stylesheet>
例 3
ドキュメント内で mode 属性が "big" に設定されている message のすべての子ノードを h1 要素で囲みます:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="*" mode="big"/></h1>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="*" mode="big"/></h1>
</xsl:template>
</xsl:stylesheet>
完全な XSLT 要素リファレンス その他の拡張