Maps in XPath 3.0

The XSLT Working Group has proposed extensions to XPath to handle maps. These extensions are available initially in XSLT 3.0 only, but are expected to move into XPath 3.1 and XQuery 3.1 in due course. In Saxon, these extensions are available in XPath whichever host language is used, so long as XPath 3.0 processing is enabled.

Maps are supported only in Saxon-PE and Saxon-EE.

A map is a new kind of XDM item (alongside nodes and atomic values). In fact, a map is a kind of function: you can think of it as a function defined extensionally (by tabulating the value of the function for all possible arguments) rather than intensionally (by means of an algorithm).

A map is a set of entries. Each entry is a key-value pair. The key is always an atomic value. The "value" is any XDM value: a sequence of nodes, atomic values, functions, or maps.

Maps, like sequences, are immutable. When you add an entry to a map, you get a new map; the original is unchanged. Saxon provides an efficient implementation of maps that achieves this without copying the whole map every time an entry is added.

Also like sequences, maps do not have an intrinsic type of their own, but rather have a type that can be inferred from what they contain. A map conforms to the type map(K, V) if all the keys are of type K and all the values are of type V. For example if the keys are all strings, and the values are all employee elements, then the map conforms to the type map(xs:string, element(employee)).

There are several ways to create a map:

It is also possible to create maps using the XSLT instructions xsl:map and xsl:map-entry.

Given a map $M, the value corresponding to a given key $K can be found either by invoking the map as a function: $M($K), or by calling map:get($M, $K).

The full list of functions that operate on maps is as follows. The prefix map represents the namespace URI