XSLTます。<xsl:template>で
定義と使用法
ます。<xsl:template>では、適用したいときに指定したノードに一致するルールが含まれています。
match属性は、XML要素にテンプレートを関連付けるために使用されます。 カスタムテンプレート一致属性のすべての分岐は、(例えば、一致は= "/"全体のドキュメントを定義する)は、XML文書として使用することができます。
注:<のxsl:テンプレート>要素はトップ(トップレベルの要素)です。
文法
<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:#00ff00">
<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:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
XMLファイルを表示し 、 XSLファイルを表示し 、 結果を表示します 。
完全なXSLT要素のリファレンス・マニュアル