[xquery-talk] map:union function?

Graydon Saunders graydonish at gmail.com
Sat Jul 18 10:12:04 PDT 2015

Hello --

map:merge returns only the last value associated with the key of a map.
Any other values are lost.

Sometimes something that returns all of the values is wanted; my particular
present use case is wanting to make sure I've got all the errors associated
with a particular XML node when each rule returns a map using the node
identifier as the key and the error code as the value, but I don't think
it's hard to think of other use cases.

It's certainly possible to write one's own function to do this but there's
several possible approaches.  A built-in could be more readily optimized by
the XQuery processor.  (Or at least I hope so!)

So where map:merge looks like:

map:merge($maps as map(*)*) as map(*)

so would

map:union($maps as map(*)*) as map(*)

The only change would be:

The supplied maps are combined as follows:


   There is one entry in the returned map for each distinct key present in
   the union of the input maps, where two keys are distinct if they are not
   the ·same key· <http://www.w3.org/TR/xpath-functions-31/#dt-same-key>.

   The associated value for each such key is *a sequence of values* taken
   from *every *map in the input sequence $input that contains an entry
   with this key.

Would this be a useful thing to add, generall?  (It would certainly be
useful to me!)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20150718/57952f50/attachment.html>

More information about the talk mailing list