Re: improvements to fn:sort functions

The case that can't currently be handled easily is where you have multiple sort keys, some ascending and some descending. It gets a bit difficult to define a simple usable interface for that, especially given the (deliberate) decision that fn:sort does lexicographic sorting on a sequence of sort keys whose length is not statically predetermined.

One approach might be to provide an extended form of the collation-key() function which can be used something like this:

sort($data, by: sort-key([
    map{'select': ->{last-name), 'order': 'ascending', 'collation': $surname-collation},
    map('select': ->(first-name), 'order': 'descending', 'collation': $firstname-collation}]))

But I wonder if it's really needed, since both XSLT and XQuery have this level of capability already. We don't have to put everything into XPath.

Michael Kay
Saxonica

> On 15 Jan 2021, at 06:31, Christian Grün <cg@basex.org> wrote:
> 
> If the input is numeric, the function argument can be used for that:
> 
>   sort($data, (), function($key) { -$key })
> 
> In others, you can use a subsequent fn:reverse call:
> 
>   reverse(sort($data))
> 
> Maybe that's already sufficient?
> 
> 
> 
> Mukul Gandhi <gandhi.mukul@gmail.com <mailto:gandhi.mukul@gmail.com>> schrieb am Fr., 15. Jan. 2021, 05:53:
> Hi all,
>     Currently, there are three XPath 3.1 fn:sort functions defined (in the section 16.2.6 fn:sort of the XPath 3.1 F&O spec). There is no provision in these functions, to specify the sort order (i.e, ascending or descending sorting). I guess, currently only ascending sorting is available by these functions.
> 
> I propose, to add an optional trailing parameter [$sortOrder as xs:integer] to the three fn:sort functions. The value 0 can be for ascending sorting (which could be default), and value 1 for descending sorting.
> 
> 
> -- 
> Regards,
> Mukul Gandhi

Received on Friday, 15 January 2021 08:25:08 UTC