The difficulty in Christian's case lays in the variable string length. The string length is part of ordering algorithm. For a reverse order one would need to create a string with an inverse string length. I would not know how to create a function nor how to define a collation that does this. I'm not sure if Michael's solution: returning an inverse binary image, how intriguing that one may be, tackles this. (can't check this) So, I would still put my money on the reverse()-method.
Rob PS. The composite sort key is another tough cookie to crumble. I feel challenged. -----Oorspronkelijk bericht----- Van: [email protected] [mailto:[email protected]] Namens Michael Kay Verzonden: donderdag 3 december 2015 15:19 Aan: Michael Kay CC: [email protected]; Christian Grün; Rob Stapper Onderwerp: Re: [xquery-talk] fn:sort: sort for strings in descending order > On 3 Dec 2015, at 13:10, Michael Kay <[email protected]> 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 _______________________________________________ [email protected] http://x-query.com/mailman/listinfo/talk --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com _______________________________________________ [email protected] http://x-query.com/mailman/listinfo/talk
