XSLT <xsl:sort>
❮ XSLT 元素参考
定义和用法
The <xsl:sort> element is used to sort the output. (The <xsl:sort> 元素用于对输出进行排序。)
Note: <xsl:sort> is always within <xsl:for-each> or <xsl:apply-templates>. (注意: <xsl:sort> 始终位于 <xsl:for-each> 或 <xsl:apply-templates> 内部。)
语法
<xsl:sort select="expression"
lang="language-code"
data-type="text|number|qname"
order="ascending|descending"
case-order="upper-first|lower-first"/>
属性
Attribute | 值 | 描述 |
---|---|---|
select | XPath-expression (XPath 表达式) | Optional. Specifies which node/node-set to sort on (可选。指定要排序的节点/节点集) |
lang | language-code (语言代码) | Optional. Specifies which language is to be used by the sort (可选。指定排序时要使用的语言) |
data-type (数据类型) | text 数字 qname |
Optional. Specifies the data-type of the data to be sorted. Default is "text" (可选。指定要排序的数据的数据类型。默认值为“text”) |
order | ascending (升序) descending (降序) |
Optional. Specifies the sort order. Default is "ascending" (可选。指定排序顺序。默认值为“ascending”) |
case-order (大小写顺序) | upper-first (大写在前) lower-first (小写在前) |
Optional. Specifies whether upper- or lowercase letters are to be ordered first (可选。指定大写字母或小写字母的排序顺序) |
示例
The example below will sort the output by artist (下面的示例将按艺术家对输出进行排序)
示例
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>我的 CD 收藏</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>标题</th>
<th>艺术家</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>
自己动手试一试 »
❮ XSLT 元素参考