Returns the value associated with a supplied key in a given map.
map:get
( $map
as map(*)
,$key
as xs:anyAtomicType
item()*
The function map:get
attempts to find an entry within the map supplied as $map
that has the same key as the supplied
value of $key
. If there is such an entry, it returns the associated value;
otherwise it returns an empty sequence.
let $week := map{0:"Sonntag", 1:"Montag", 2:"Dienstag",
3:"Mittwoch", 4:"Donnerstag", 5:"Freitag", 6:"Samstag"}
The expression map:get($week, 4)
returns "Donnerstag"
.
The expression map:get($week, 9)
returns ()
.
The expression map:get(map:entry(7,()), 7)
returns ()
.
A return value of ()
from map:get
could indicate that
the key is present in the map with an associated value of ()
, or it could
indicate that the key is not present in the map. The two cases can be distinguished by
calling map:contains
.
Invoking the map as a function item has the same effect
as calling get
: that is, when $map
is a map, the expression
$map($K)
is equivalent to map:get($map, $K)
. Similarly, the
expression map:get(map:get(map:get($map, 'employee'), 'name'), 'first')
can
be written as $map('employee')('name')('first')
.