Name

xsl:sort

Synopsis

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

The xsl:sort instruction appears as a child of either xsl:apply-templates or xsl:for-each. It changes the order in which templates are applied to the context node list from document order to another order, such as alphabetic. You can perform multiple key sorts (e.g., sort first by last name, then by first name, then by middle name) using multiple xsl:sort elements in descending order of the keys’ importance.

Attributes

select, optional

The key to sort by. If select is omitted, then the sort key is set to the value of the current node.

data-type, optional, attribute value template

By default, sorting is purely alphabetic. However, alphabetic sorting leads to strange results with numbers. For instance, 10, 100, and 1,000 all sort before 2, 3, and 4. You can specify numeric sorting by setting data-type to number.

lang, optional, attribute value template

Sorting is language dependent. Setting the lang attribute to an RFC 1766 language code changes the language. The default language is system dependent.

order, optional, attribute value template

The order by which strings are sorted, either descending or ascending. The default is ascending order.

case-order, optional, attribute value template

upper-first or lower-first to specify whether uppercase letters sort before lowercase letters or vice ...

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.