XSLT <xsl:apply-templates>
❮完全なXSLT要素リファレンス
定義と使用法
<xsl:apply-templates>要素は、現在の要素または現在の要素の子ノードにテンプレートを適用します。
select属性を<xsl:apply-templates>要素に追加すると、属性の値に一致する子要素のみが処理されます。select属性を使用して、子ノードを処理する順序を指定できます。
構文
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
属性
Attribute | Value | Description |
---|---|---|
select | expression | Optional. Specifies the nodes to be processed. An asterisk selects the entire node-set. If this attribute is omitted, all child nodes of the current node will be selected |
mode | name | Optional. If there are multiple ways of processing defined for the same element, distinguishes among them |
例1
ドキュメント内の各タイトル要素の周りに単一のh1要素をラップします。
<?xml version="1.0" encoding="UTF-8"?>
<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
メッセージの子であるすべてのタイトル要素の周りに単一のh1要素をラップします。
<?xml version="1.0" encoding="UTF-8"?>
<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"に設定されているメッセージのすべての子ノードの周りに単一のh1要素をラップします。
<?xml version="1.0" encoding="UTF-8"?>
<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要素リファレンス