Arrays in XPath

XPath 3.1 introduces arrays as a new data type. (Unlike maps, arrays are not defined for use in XSLT 3.0 unless XPath 3.1 is supported. But Saxon's XSLT 3.0 implementation always supports XPath 3.1.)

The main reason arrays were introduced was to allow JSON data structures to be represented faithfully. However there are many other ways you can take advantage of arrays.

Arrays differ from sequences in a number of ways:

Arrays, like all other XDM values, are immutable. When you append or replace or remove a member entry in an array, you get a new array; the original is unchanged. Unlike maps, Saxon does not currently optimize such operations: they are generally implemented by copying the entire array.

As with sequences and maps, arrays do not have an intrinsic type of their own, but rather have a type that can be inferred from what they contain. An array conforms to the type array(T) if all of its members are of type T. For example if the members are all strings, then the array conforms to the type array(xs:string).

There are several ways to create an array:

There are no XSLT 3.0 instructions for creating arrays, analogous to the instructions xsl:map and xsl:map-entry. Saxon however fills the gap with the instructions saxon:array and saxon:array-member: see Extension instructions.

The summary of the full list of functions that operate on arrays is as follows; for full details see the Functions Library. The prefix array represents the namespace URI http://www.w3.org/2005/xpath-functions/array.