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

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:apply-templates> 元素


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

Definition and Usage
定义和用法

The <xsl:apply-templates> element applies a template to the current element or to the current element's child nodes.
<xsl:apply-templates>元素将模版应用于当前元素或应用于当前元素的子节点。

If we add a select attribute to the <xsl:apply-templates> element it will process only the child element that matches the value of the attribute. We can use the select attribute to specify in which order the child nodes are to be processed.
如果我们想<xsl:apply-templates>元素中添加一个select[选择]属性,那么它仅处理与属性值相匹配的子元素。我们可以使用select属性指定子节点的处理顺序。


Syntax
语法

<xsl:apply-templates select="expression" mode="name">
 <!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>

Attributes
属性

属性 描述
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
可选参数。如果给相同的元素定义了多种处理方式,那么指定该参数可用于区分它们

Example 1
案例1

Wrap a single h1 element around each title element in the document:
将“h1”元素套入文档中的每个title[标题]元素中:

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

Example 2
案例2

Wrap a single h1 element around all the title elements which are children of message:
将一个单独的“h1”元素套入子消息元素内的所有title[标题]元素中:

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

Example 3
案例3

Wrap a single h1 element around all the child nodes of message that have the mode attribute set to "big":
将一个“h1”元素套入所有mode[模式]属性已设置为“big”的子消息元素节点中:

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

评论 (0) All

登陆 | 还没注册?