saxon:sort

Sorts a sequence of items.

sort($seq as item()*) ➔ item()*

Arguments

 

$seq

item()*

The sequence to be sorted

Result

item()*

sort($seq as item()*, $sort-key as function(item()) as xs:anyAtomicType) ➔ item()*

Arguments

 

$seq

item()*

The sequence to be sorted

 

$sort-key

function(item()) as xs:anyAtomicType

A function used to compute the sort key

Result

item()*

Details

Namespace: http://saxon.sf.net/

The first form of the function sorts a sequence of nodes and/or atomic values. For atomic values, the value itself is used as the sort key. For nodes, the atomized value is used as the sort key. The atomized value must be a single atomic value. The values must all be comparable. Strings are sorted using codepoint collation.

The second form of the function sorts a sequence of nodes and/or atomic values, using the supplied function to compute the sort key for each item in the sequence. The computed sort key must either be a single atomic value, or a node that atomizes to a single atomic value, and the sort keys must all be comparable. Strings are sorted using codepoint collation.

The supplied function takes as its argument an item in the sequence to be sorted, and returns as its result an atomic value representing the sort key. The function is evaluated for each item in $seq in turn

Example: saxon:sort(sale, function($node) {$node/(@price * @qty)}) will evaluate price times quantity for each child <sale> element, and return the sale elements in ascending numeric order of this value.