Rob, Michael, Thanks for your enlightening answers. The hint to fn:reverse was helpful – I completely missed it – and I was not aware of the punched-card technique (I overlooked that sort is stable).
One more use I case had in mind were top-k queries: fn:sort(...)[position() = 1 to 5] From the implementation point of view, such patterns can be sped up with a min heap. I now realize that the heap can simply be replaced with a max heap if an fn:sort call is wrapped by fn:reverse. Christian __________________________________ On Fri, Dec 4, 2015 at 11:21 AM, Michael Kay <m...@saxonica.com> wrote: >> >> PS. The composite sort key is another tough cookie to crumble. I feel >> challenged. >> > > Because fn:sort produces a stable sort, one can always go back to the old > punched-card technique of doing multiple sorts, in minor-to-major key order: > > $places => sort(function($x){$x!city}) => reverse() => > sort(function($x){$x!country}) > > Michael Kay > Saxonica _______________________________________________ talk@x-query.com http://x-query.com/mailman/listinfo/talk