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 元素參考