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

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.

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