Skip to main content

Module sorting

Module sorting 

Source
Expand description

XSLT sorting (§33, §85 Phase 8).

The <xsl:sort> element specifies sort criteria for <xsl:for-each> and <xsl:apply-templates>.

Sorting supports:

  • Multiple sort keys (primary, secondary, etc.)
  • Text and numeric data types
  • Ascending and descending order
  • Case-order (upper-first, lower-first)
  • Language-specific sorting

§UPSTREAM-PARITY

Upstream libxslt (sort.c) sorts node-sets using a qsort-like comparison driven by xsltSortNodeSet. Each _xsltSort holds one sort key with select, lang, data-type, order, and case-order attributes. Multiple sort keys are chained via next, with the first being the primary key.

Comparison semantics:

  • data-type="number": numeric comparison (NaN sorts as NaN after all)
  • data-type="text": byte-wise string comparison (upstream uses xmlStrcmp, extended by locale-aware comparison when available)
  • order="descending" inverts the comparison result

Constants§

XSLT_SORT_ASCENDING
Sort order constants
XSLT_SORT_CASE_LOWER_FIRST
XSLT_SORT_CASE_UPPER_FIRST
Case order constants
XSLT_SORT_DESCENDING
XSLT_SORT_NUMBER
XSLT_SORT_TEXT
Sort data type constants

Functions§

xsltCompareNodes
Compare two nodes according to a chain of sort specifications.
xsltCompareSingle
Compare two nodes according to a single sort key.
xsltCompileSort
Compile a sort specification from an xsl:sort instruction node.
xsltFreeSort
Free a sort specification.
xsltFreeSortList
Free a chain of sort specifications.
xsltSortNodeSet
Sort a node-set according to the sort specifications.