当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > XSLT <xsl:template> 元素

XSL/XSLT
XSL 语言
XSLT 介绍
XSLT 浏览器
XSLT 转换
<xsl:template>
<xsl:value-of>
<xsl:for-each>
<xsl:sort>
<xsl:if>
<xsl:choose>
<xsl:apply-templates>
XSLT - 客户端
XSLT - 服务器端
XSLT - 编辑XML
XSLT 摘要
XSLT 元素参考
XSLT 函数
XSL 编辑器

XSL/XSLT 中的 XSLT <xsl:template> 元素


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 215 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The <xsl:template> element contains rules to apply when a specified node is matched.
 <xsl:template> 元素中包含了当指定的节点相匹配时的应用规则。

The match attribute is used to associate the template with an XML element. The match attribute can also be used to define a template for a whole branch of the XML document (i.e. match="/" defines the whole document).
这个match属性的作用是:与一个XML元素的模版相结合;match属性也可以用来给XML文档的整个分支结构定义一个模版(ie:match="/",即定义了整个文档)

Note: <xsl:template> is a top-level element.
注意:<xsl:template>元素是一个顶级元素。


Syntax
语法

<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
 <!-- Content:(<xsl:param>*,template) -->
</xsl:template>

Attributes
属性

属性 描述
name name

Optional. Specifies a name for the template.

可选参数。指定模版名称

Note: If this attribute is omitted there must be a match attribute
注意:如果忽略该属性那么必须使用一个match属性

match pattern

Optional. The match pattern for the template.

可选参数。指定模版的匹配样式

Note: If this attribute is omitted there must be a name attribute
注意:如果忽略该属性那么必须使用一个name属性

mode mode Optional. Specifies a mode for this template
可选参数。指定模版模式
priority number Optional. A number which indicates the numeric priority of the template
可选参数。指定一个用于指明模版优先级的数字

Example
案例

<?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>

查看XML 文件XSL 文件以及结果

评论 (0) All

登陆 | 还没注册?