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




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


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 Saxon/J but not by Saxon-JS.


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