当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > <xsl:apply-templates>
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 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:template match="/"> <xsl:template match="cd"> <xsl:template match="title"> <xsl:template match="artist"> </xsl:stylesheet> |
The result of the transformation will look like this:
转换结果如下:
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文件, 以及 最终结果.