xsl:array

New in XSLT 4.0. Constructs an array, whose content is established using either the contained sequence constructor or the select attribute.

Category: instruction
Content: sequence-constructor
Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element

Attributes

for-each?

expression

Can be used to provide an input sequence for evaluating the select attribute or sequence constructor.

select?

expression

The contents of the array may be given either by an expression in the select attribute, or by expanding the sequence constructor contained in the xsl:array element.

Saxon availability

Available in XSLT 4.0. Requires Saxon-PE or Saxon-EE. Implemented since Saxon 13. Implemented experimentally since Saxon 11. Available for all platforms.

Notes on the Saxon implementation

The xsl:array instruction is available from Saxon 13 in XSLT 4.0.

The XSLT 4.0 specification describes three methods for constructing arrays. In Saxon 13.0, only the first and third of these is fully implemented:

  • A simple array in which every member is a singleton item can be created by using either the select attribute or the sequence constructor to supply the sequence of items. Every item in the sequence becomes an individual member of the array.

  • The xsl:array-member instruction can be used to create members for an array.

Constructing an array using the for-each attribute is currently only partially implemented in Saxon. The specification says that "when the for-each attribute is present, then it is not necessary to use the xsl:array-member instruction". However in Saxon 13.0, when using the for-each attribute, the members must explicitly be constructed using the xsl:array-member instruction to ensure that they are parcels.

For example, an array whose members are computed by applying a mapping to a sequence of items can be created by using the for-each attribute with xsl:array-member:

<xsl:array for-each="1 to 4"> <xsl:array-member select="1 to ."/> </xsl:array>

constructs the array [1, (1, 2), (1, 2, 3), (1, 2, 3, 4)].

But attempting to construct the same array without use of the xsl:array-member instruction will currently fail:

<xsl:array for-each="1 to 4" select="1 to ."/>

Details

The content of an array is a sequence of sequences, which the XDM data model cannot represent directly. To work around this, the XSLT 4.0 specification represents the array members as parcels (zero-arity function items). A parcel encapsulates a value, which can be any sequence.

Examples

Example 1

Creating a simple array in which every member is a singleton item:

<xsl:array select="1 to 4"/>

constructs the array [1, 2, 3, 4].

Example 2

The xsl:array-member instruction can be used to create arbitrary members for an array:

<xsl:array> <xsl:array-member select="1 to 4"/> <xsl:array-member select="'A'"/> <xsl:array-member select="'B'"/> </xsl:array>

constructs the array [(1, 2, 3, 4), "A", "B"].

Links to W3C specifications

XSLT 4.0 Specification

See also

xsl:array-member