Sorting and Numbering

Sorting and Numbering
<xsl:sort case-order=”upper-first” | “lower-first” data-type=”number” “qname” | “text”

lang=”language-code” order=”ascending” | ” descending” select=”expression” >


The xsl:sort element is used to define a sort key. This sort key determines the order in which selected nodes are processed by the xsl:for-each or xsl:apply-templates elements.
A sort can be based upon more than one xsl:sort element. Each sort is applied in the order in which it occurs. Duplicate values are left in document order. After the first sort has reordered the nodes, the second sort is applied to any nodes that had duplicate values in the first sort. The third sort is applied to any nodes that had duplicate values in the second sort, and so on.
This is not a self-closing element. The separate closing element is mandatory.
case-order=”upper-first” | “lower-first”
The optional case-order attribute dictates whether the sort will have upper or lower case letters listed first in the sort. The default is to list upper case first.
data-type=”number” | “qname” | “text”
The optional data-type attribute specifies the data type of the strings. There are only three permitted types:
Value Effect
number The sort key is converted to a number.
qname The sort is based upon a user-defined data type.
text The sort is alphabetic.
The optional lang attribute is set to an Attribute Value Template or a string that dictates the language code which in turn specifies the language alphabet to be used for the sort. Clearly, the alphabet and numbers being used will determine the sort order. The default language is set by the operating system environment.
order=”ascending” | ” descending”
The optional order attribute dictates whether the sort is in increasing or decreasing order. The default is ascending.
The optional select attribute is an expression that defines the key upon which the sort will be based. The expression is evaluated and converted to a string that is used as the sort key. If no select attribute is provided (hence, no sort key), the selected nodes are sorted in document order.
Scroll to Top