XSLT <xsl:template>要素
XSLT 要素リファレンス(完全版)
定義と使い方
<xsl:template> 要素は、指定されたノードに一致したときに適用されるルールを含みます。
match 属性は、テンプレートを特定の XML 要素に関連付けるために使用します。match 属性は、XML ドキュメントのすべてのブランチにテンプレートを定義するためにも使用できます(例:match="/" はドキュメント全体を定義します)。
注意:<xsl:template> はトップレベル要素(top-level element)です。
構文
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
属性
| 属性 | 值 | 説明 |
|---|---|---|
| name | name | 任意。テンプレートに名前を定義します。 注:この属性を省略する場合は、match 属性を設定する必要があります。 |
| match | pattern | 任意。テンプレートのマッチングパターン。 注:この属性を省略する場合は、name 属性を設定する必要があります。 |
| mode | mode | 任意。テンプレートにモードを指定します。 |
| priority | number | 任意。テンプレートの優先度を表す番号。 |
例
<?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="/">
<html>
<body>
<h2>My CD Collection</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:#0080FF">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:#0080FF">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
、 、 。
XSLT 要素リファレンス(完全版) その他の拡張