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
|
| The contents of the array may be given either by an expression in the |
|
| 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 |
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"/>
.