Is there a way in XPath 3.1 (not XQuery) to sort the results?
I’ve looked through the spec and can’t find anything. But I thought sorting was supported in 3.1.
Yes, see fn:sort
in XPath and XQuery Functions and Operators 3.1:
Summary
Sorts a supplied sequence, based on the value of a sort key supplied as a function.
Signatures
fn:sort($input as item()*) as item()* fn:sort($input as item()*, $collation as xs:string?) as item()* fn:sort($input as item()*, $collation as xs:string?, $key as function(item()) as xs:anyAtomicType*) as item()*
[…]
Examples
The expression
fn:sort((1, 4, 6, 5, 3))
returns(1, 3, 4, 5, 6)
.[…]