Choose keys without changing the source
fn:sort returns the original items in key order. Equal keys
keep their source order. The separate XPath
library uses inline functions to calculate several keys and capture
the chosen quantity direction.
Compare text “10” before “2” with numeric 2 before 10. In numeric mode, the examples put invalid or missing values last by authoring a validity key. Standard sort puts empty keys first; missing-last is an explicit choice in this library. Descending text reverses the input and output around a stable sort, preserving ties.
Numeric keys use xs:decimal; exponent notation, NaN and
infinities count as invalid values in these examples.
The row example orders valid quantities by group A–Z, then quantity; invalid and missing quantities follow all valid rows. Select a row and change direction: its previous source sibling remains the same. Authored row IDs must be unique and should remain stable during edits.
This slice supports numeric, boolean and string keys with Unicode codepoint collation. Locale collations, date/time keys, named function references and partial application remain unsupported. Inline functions stay inside XPath; CEM-QL receives sorted values or retained CEM nodes. Shared item, text and work limits apply. The XML reader accepts 32 KiB.
See also
XPath nodes and source navigation · XPath sequences and columns · Multi-format data tables · XPath validation previews