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

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:sort>


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

The <xsl:sort> element is used to sort the output.
<xsl:sort>元素用于对结果进行排序。


Where to put the Sort Information
在哪儿放置排序信息

To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file:
如果要对结果进行排序,可以在XSL文件里的<xsl:for-each>元素中添加一个<xsl:sort>元素:

<?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>
<table border="1">

<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>

<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Note: The select attribute indicates what XML element to sort on.
注意: 选择(select)属性需要指明对哪些XML元素进行排序。

The result of the transformation above will look like this:
上述代码的转换结果如下:

My CD Collection
我的CD集

Title Artist
Romanza Andrea Bocelli
One night only Bee Gees
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyler
The very best of Cat Stevens
Greatest Hits Dolly Parton
Sylvias Mother Dr.Hook
Eros Eros Ramazzotti
Still got the blues Gary Moore
Unchain my heart Joe Cocker
Soulsville Jorn Hoel
For the good times Kenny Rogers
Midt om natten Kim Larsen
Pavarotti Gala Concert Luciano Pavarotti
1999 Grammy Nominees Many
The dock of the bay Otis Redding
When a man loves a woman Percy Sledge
Maggie May Rod Stewart
Stop Sam Brown
Black angel Savage Rose
Picture book Simply Red
Bridge of Spies T`Pau
Red The Communards
Private Dancer Tina Turner
Tupelo Honey Van Morrison
Big Willie style Will Smith

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

评论 (0) All

登陆 | 还没注册?