Name
<xsl:sort> — Defines a sort key for the current context. This element appears as a child of the <xsl:apply-templates> or <xsl:for-each> elements. Within those elements, the first <xsl:sort> defines the primary sort key, the second <xsl:sort> defines the secondary sort key, etc.
Category
Subinstruction (<xsl:sort> always appears as a child of the <xsl:apply-templates> or <xsl:for-each> elements)
Required Attributes
None.
Optional Attributes
- select
An XPath expression that defines the nodes to be sorted.
- lang
A string that defines the language used by the sort. The language codes are defined in RFC1766, available at http://www.ietf.org/rfc/rfc1766.txt.
- data-type
An attribute that defines the type of the items to be sorted. Allowable values are
numberandtext; the default istext. An XSLT processor has the option of supporting other values as well. Sorting the values32 10 120withdata-type="text"returns10 120 32, whiledata-type="number"returns10 32 120.- order
An attribute that defines the order of the sort. Allowable values are
ascendinganddescending.- case-order
An attribute that defines the order in which upper- and lowercase letters are sorted. Allowable values are
upper-firstandlower-first.
Content
None.
Appears in
<xsl:apply-templates> and <xsl:for-each>.
Defined in
XSLT section 10, Sorting.
Example
We’ll illustrate <xsl:sort> with this stylesheet:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access