[xquery-talk] fn:sort: sort for strings in descending order

Michael Kay mike at saxonica.com
Thu Dec 3 06:19:00 PST 2015


> On 3 Dec 2015, at 13:10, Michael Kay <mike at saxonica.com> wrote:
> 
> As Rob points out, the simplest solution for simple cases is to use reverse().
> 
> That doesn't work if you want a composite sort key - sort by ascending country then descending city. (Yes, an unconvincing use case, and frankly it's because of the difficulty of finding a convincing use case that we didn't include this capability).
> 
> If you know that the result of collation-key() will be xs:base64Binary then you can do it, I suspect, by 
> 
> fn:sort($places, function($p) { $p!country, $p!city => collation-key() => bin:not() } )
> 
> where bin:not is from http://expath.org/spec/binary#not
> 

Sorry, that's wrong. The empty string sorts first in ascending order, under this function it will still sort first in descending order. Need to do something a bit more subtle.

Michael Kay
Saxonica





More information about the talk mailing list