当前位置: 首页 > 网络学院 > XML相关教程 > XSL/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 中的 <xsl:apply-templates>


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

The <xsl:apply-templates> element applies a template to the current element or to the current element's child nodes.
<xsl:apply-templates>元素的作用是把指定的模板应用到当前元素或当前元素的子节点上。


The <xsl:apply-templates> Element
<xsl:apply-templares>元素

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 the order in which the child nodes are processed.
如果我们向<xsl:apply-templates>元素中添加一个选择(select)属性,那么它将只处理与属性值相匹配的子元素。我们可以使用选择属性来指定元素在子节点中的处理顺序。

Look at the following XSL style sheet:
让我们看一下下面的这张XSL样式表:

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


The result of the transformation will look like this:
转换结果如下:

My CD Collection
我的CD集

Title: Empire Burlesque
Artist: Bob Dylan

Title: Hide your heart
Artist: Bonnie Tyler

Title: Greatest Hits
Artist: Dolly Parton

Title: Still got the blues
Artist: Gary Moore

Title: Eros
Artist: Eros Ramazzotti

Title: One night only
Artist: Bee Gees

Title: Sylvias Mother
Artist: Dr.Hook

Title: Maggie May
Artist: Rod Stewart

Title: Romanza
Artist: Andrea Bocelli

Title: When a man loves a woman
Artist: Percy Sledge

Title: Black angel
Artist: Savage Rose

Title: 1999 Grammy Nominees
Artist: Many

Title: For the good times
Artist: Kenny Rogers

Title: Big Willie style
Artist: Will Smith

Title: Tupelo Honey
Artist: Van Morrison

Title: Soulsville
Artist: Jorn Hoel

Title: The very best of
Artist: Cat Stevens

Title: Stop
Artist: Sam Brown

Title: Bridge of Spies
Artist: T`Pau

Title: Private Dancer
Artist: Tina Turner

Title: Midt om natten
Artist: Kim Larsen

Title: Pavarotti Gala Concert
Artist: Luciano Pavarotti

Title: The dock of the bay
Artist: Otis Redding

Title: Picture book
Artist: Simply Red

Title: Red
Artist: The Communards

Title: Unchain my heart
Artist: Joe Cocker

View the XML file, View the XSL file, and View the result.
XML文件, XSL文件, 以及 最终结果.

评论 (0) All

登陆 | 还没注册?