saxon:array

The saxon:array instruction is used to create an array from a sequence of items. Like the "curly array constructor" in XPath 3.1, each member of the created array will be a singleton item.

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

Attributes

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 saxon:array element.

composite?

boolean

Implemented since Saxon 11. If this attribute is present with the value "yes", then the contained sequence constructor must deliver a sequence of parcels (items of type record(value, *)) and each parcel becomes one member of the constructed array. If the attribute is absent or has the value "no", then the sequence returned by the sequence constructor is converted to an array, one item per array member.

Saxon availability

Requires Saxon-PE or Saxon-EE. Implemented since Saxon 9.8. Available for all platforms.

Details

The content model is the same as xsl:sequence: either a select attribute, or a contained sequence constructor, but not both. The effect is the same as evaluating the equivalent xsl:sequence instruction and then passing the result into a curly array constructor.

The saxon:array instruction can be exported to a SEF file; the resulting SEF file can be used by SaxonJ but not by SaxonJS.

Examples

The following example groups transaction elements by date, returning the result as a nested array structure: specifically, an outer array, itself containing arrays of transaction elements, where all the transactions for a particular day are grouped as members of an inner array.

<xsl:variable name="groups" as="array(array(element(*))"> <saxon:array> <xsl:for-each-group select="transaction" group-by="@date"> <saxon:array select="current-group()"/> </xsl:for-each-group> </saxon:array> </xsl:variable>

Rather than binding the resulting array to a variable, another useful technique is to serialize it as JSON using <xsl:output method="json" build-tree="no"/>.

See also

saxon:array-member

xsl:array