Skip to content
Map & Array Functions

Map Functions

Maps are an XPath 3.1 data type representing key-value collections. Map functions are in namespace http://www.w3.org/2005/xpath-functions/map.

map:get

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

Returns the value associated with $key in the map, or the empty sequence if the key is not present.

map:keys

map:keys($map as map(*)) as xs:anyAtomicType*

Returns all keys in the map.

map:size

map:size($map as map(*)) as xs:integer

Returns the number of entries in the map.

map:contains

map:contains($map as map(*), $key as xs:anyAtomicType) as xs:boolean

Returns true if the map contains the given key.

map:put

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

Returns a new map with the key-value pair added or replaced.

map:merge

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

Merges a sequence of maps into a single map. Later entries override earlier ones for duplicate keys.

Map construction in XSLT

Maps can be constructed in XSLT using xsl:map and xsl:map-entry, or inline in XPath:

<!-- XSLT construction -->
<xsl:variable name="options" as="map(*)">
  <xsl:map>
    <xsl:map-entry key="'escape'" select="true()"/>
  </xsl:map>
</xsl:variable>

<!-- XPath inline construction -->
<xsl:variable name="options" select="map{'escape': true()}"/>

Array Functions

Array functions are in namespace http://www.w3.org/2005/xpath-functions/array.

array:size

array:size($array as array(*)) as xs:integer

Returns the number of members in the array.

array:get

array:get($array as array(*), $position as xs:integer) as item()*

Returns the member at the given position (1-based).