map:entry

Returns a map that contains a single entry (a key-value pair).

Signature

map:entry(
    $key as xs:anyAtomicType, 
    $value as item()*
) as map(*)

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

The function map:entry returns a map which contains a single entry. The key of the entry in the new map is $key, and its associated value is $value.

Notes

The function call map:entry(K, V) produces the same result as the expression map{K : V}.

The function map:entry is intended primarily for use in conjunction with the function map:merge. For example, a map containing seven entries may be constructed like this:

map:merge((
   map:entry("Su", "Sunday"),
   map:entry("Mo", "Monday"),
   map:entry("Tu", "Tuesday"),
   map:entry("We", "Wednesday"),
   map:entry("Th", "Thursday"),
   map:entry("Fr", "Friday"),
   map:entry("Sa", "Saturday")
   ))

The map:merge function can be used to construct a map with a variable number of entries, for example:

map:merge(for $b in //book return map:entry($b/isbn, $b))

Examples

The expression map:entry("M", "Monday") returns map{"M":"Monday"}.