Skip to content
Map & Array Functions

Map & Array Functions

Map Functions

Namespace: http://www.w3.org/2005/xpath-functions/map (prefix map:).

Function Description
map:get($map, $key) Get value for key
map:put($map, $key, $value) Return new map with added/updated entry
map:entry($key, $value) Create single-entry map
map:merge($maps) Merge sequence of maps
map:remove($map, $keys) Return map without specified keys
map:keys($map) All keys
map:contains($map, $key) True if key exists
map:size($map) Number of entries
map:find($map, $key) Find values for key in nested maps
map:for-each($map, $action) Apply function to each entry

Examples

let $m := map { "name": "Alice", "age": 30 }
return map:get($m, "name")                        (: "Alice" :)

map:for-each(
  map { "x": 1, "y": 2 },
  function($k, $v) { $k || "=" || $v }
)                                                  (: "x=1", "y=2" :)

Array Functions

Namespace: http://www.w3.org/2005/xpath-functions/array (prefix array:).

Function Description
array:get($array, $pos) Get member at position (1-based)
array:size($array) Number of members
array:head($array) First member
array:tail($array) All members except first
array:append($array, $member) Add member at end
array:subarray($array, $start, $length?) Extract sub-array
array:remove($array, $pos) Remove member at position
array:insert-before($array, $pos, $member) Insert at position
array:put($array, $pos, $member) Replace member at position
array:join($arrays) Concatenate arrays
array:reverse($array) Reverse order
array:flatten($input) Flatten nested arrays
array:for-each($array, $action) Apply function to each member
array:filter($array, $predicate) Keep members matching predicate
array:sort($array, $collation?, $key?) Sort members
array:fold-left($array, $zero, $f) Left fold
array:fold-right($array, $zero, $f) Right fold

Examples

array:for-each([1, 2, 3], function($x) { $x * 2 })
(: [2, 4, 6] :)

array:filter([1, 2, 3, 4, 5], function($x) { $x > 3 })
(: [4, 5] :)

array:flatten([1, [2, 3], [4, [5]]])
(: 1, 2, 3, 4, 5 :)