I've looked through the spec and can't find anything. But I thought sorting was supported in 3.1.
Update (sorry, I have a tendency to assume people can read my mind and I don't list enough details):
We're doing this in Java so we call:
XPathCompiler.compile(query);
XPathExecutable.load()
So our query is normally "/root/employees/employee" to get a list of all employees (from Southwind.xml).
To put it in SQL-ish terms, we then want to give our users the ability to do something like this:
"/root/employees/employee order by lastname descending, firstname ascending".
Based on the answer below, how do I pass this in Java code? I see this example, but that I don't think is Java code (if it is, I don't understand the syntax).
And, can it sort on multiple nodes (ie sort on firstname if lastnames are equal)?
Yes, see
fn:sort
in XPath and XQuery Functions and Operators 3.1: