xslt之<xsl:apply-templates

apply-templates>元素中增加一个select属性,它将只对与属性匹配的子元素有效。我们可以用select属性来指定要处理的子节点。
--------------------------------------------------------------------------------
语法
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
属性
属性

说明
select
expression
select表达式是可选的用于指定要处理的节点。一个星号*选择了全部的节点集。如果属性省略了,那么所有的子节点都将被选择。
mode
name
mode也是可选的,如果对一个相同的元素有很多定义,那么用mode可以区分他们。
例子 1
对于文档中的每一个tiltle元素用h1元素包装。
<?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>
例子 2
对于文档中的所有message 元素的子元素tiltle用h1元素包装。
<?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>
例子 3
对于文档中的所有message 元素的所有子元素用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>
posted @ 2009-05-20 10:15  roboth  阅读(247)  评论(0编辑  收藏  举报