4
votes

I am trying to create a hash-map/ key-value pair like structure in xquery. I am aware a map like structure exists in xquery: http://www.w3.org/2005/xpath-functions/map/

and even found documentation in Saxon: http://www.saxonica.com/html/documentation/functions/map/

However I am both unsure how to create a map or use it.

Here's my code so far:

declare namespace map="http://www.w3.org/2005/xpath-functions/map";
let $a := map:map()

But I get an error:

Cannot find a matching 1-argument function named
  {http://www.w3.org/2005/xpath-functions/map}map()

So how exactly do I use maps in xquery?

1

1 Answers

4
votes

The syntax is in XSLT 3.0 and XQuery 3.1 and has been through a few iterations as the working drafts have evolved. The current syntax (supported in Saxon 9.7) allows

map{}

for an empty map

map{'a':1, 'b':2}

for a map with a known number of entries (both the keys and the values can be arbitrary expressions), and

map:merge(for $x in //emp return map{$x!name : $x!@salary})

for a map with a statically-unknown number of entries.