Hello Liam,

This is user defined, providing an external ordering function.  For nodes,
generate-id could be used of course, but others ordering functions are
possibles. For instance name($node), or $node/my_id, or
get_database_id($node). It really depends on what one want to do. For
functions, the xquery built in function lt works (at least with my
interpreter), but it can also be user-defined tuned.

For such maps, there are two Ctors (variations over the new function of the
W3C recommendation http://www.w3.org/TR/xslt-30/#map-functions) :

declare function lt($a,$b) as xs:boolean {key($a) lt key($b)};
declare function new() { pair(empty_entry() ,lt#2) };
declare function new($less as function(item(),item()) as xs:boolean)
{pair(empty_entry() ,$less)};
as well as the usual
declare function new(maps *);

Hence the default ordering function for keys is lt (this is not compatible
with the W3C recommendation, that suggest keys being segregated by
distinct-values).

I am already using this trick for my maps using John Snelson rbtree, it is
really useful for a lot of things. I should provide to John soonly a
modified version of his rbtree.xq providing these mechanisms if you are
interested in.

Cheers


2013/11/27 Liam R E Quin <[email protected]>

> On Wed, 2013-11-27 at 07:43 +0100, jean-marc Mercier wrote:
> > [...] functions or nodes can
> > not be accepted as keys,
>
> How would you retrieve an item from a map if the key was a function? If
> functions don't have identity how would you ensure keys were unique?
>
> For a node you could maybe use generate-id() as a surrogate.
>
> Liam
>
> --
> Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
> Pictures from old books: http://fromoldbooks.org/
> Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
>
>
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to