Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSLT <xsl:sort> elements


May 28, 2021 XSL T


Table of contents


XSLT and lt;xsl: sort.gt; element

The XSLT and xsl:sort elements are used to sort the output.


XSLT <xsl:sort> elements XSLT element reference manual

Definitions and usages

The element is used to sort the output results.

Note: slt;xsl:sort> always located inside slt;xsl:for-each;or slt;xsl:apply-templates?gt;


Grammar

<xsl:sort select="expression"
lang="language-code"
data-type="text|number|qname"
order="ascending|descending"
case-order="upper-first|lower-first"/>

Property

属性 描述
select XPath-expression 可选。规定节点的排序关键字,即根据哪个节点或节点集来排序。
lang language-code 可选。规定排序所用的语言。
data-type text
number
qname
可选。规定被排序的数据的数据类型。默认是 "text"。
order ascending
descending
可选。规定排序顺序。默认是 "ascending"。
case-order upper-first
lower-first
可选。规定是首先按大写字母顺序还是小写字母顺序进行排序。


The following example will be sorted by artist as a keyword:

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


XSLT <xsl:sort> elements XSLT element reference manual