xsl:sort
Used within an xsl:for-each, xsl:apply-templates, xsl:for-each-group, or xsl:perform-sort to indicate the order in which the selected elements are processed.
Content: sequence-constructor
Permitted parent elements:
xsl:apply-templates
; xsl:for-each
; xsl:for-each-group
; xsl:perform-sort
Attributes
|
| A string expression that calculates the sort key. Default value ".". |
|
| Determines the algorithm used for alphabetic
collating, as an ISO language code such as |
|
| Determines the sort order; the default is
|
|
| The name of a collating sequence. If present it must be a collation URI recognized by Saxon: see Sorting and collations. |
|
| Permitted only on the first
|
|
| Relevant only for
|
|
| Determines whether collating is based on
alphabetic sequence or numeric sequence. The permitted values are either
|
Saxon availability
Available in XSLT 1.0 and later versions. Available in all Saxon editions. Available for all platforms.
Notes on the Saxon implementation
The SaxonJ implementation uses java.util.Arrays.sort(): see the
Javadoc documentation for that method for information about the performance
characteristics of the sort algorithm. The SaxonCS implementation uses
System.Array.sort(): see the .NET documentation for details of
the sort algorithm used.
In XSLT 4.0, composite sort keys are allowed, but this is not yet implemented in Saxon 13.
Details
When using the Unicode Collation Algorithm, only the order and
data-type control attributes are relevant - all other controls
are attached as query parameters to the collation URI.
Several sort keys are allowed: they are written in major-to-minor order.
Examples
Example 1
Sorting with xsl:apply-templates. This example shows a template
for a <BOOKLIST> element which processes all the child
<BOOK> elements in order of their child
<AUTHOR> elements; books with the same author are in
descending order of the DATE attribute.
Example 2
Sorting with xsl:for-each. This example also shows a template
for a <BOOKLIST> element which processes all the child
<BOOK> elements in order of their child
<AUTHOR> elements.
Example 3
Sorting with xsl:for-each using Unicode Collation Algorithm.
<BOOK> elements are processed in order of their child
<TITLE> elements, sorted as if they were in French
dictionary order (where accents are compared in a reverse direction).