saxon:for-each-member
The saxon:for-each-member
instruction is used to iterate over the members of an array.
Category: instruction
Content:
sequence-constructor
Permitted parent elements:
any XSLT element whose content model is
sequence-constructor; any literal result element
Attributes
|
|
An XPath expression that must evaluate to an array |
|
|
The name of a variable that will be bound to each member of the array in turn; the variable is in scope within the contained sequence constructor |
Details
The instruction evaluates the select
expression, which must return a single array.
The sequence constructor contained by the instruction is executed once for each member of the array. A member
of an array can be any sequence (not necessarily a single item). The variable named in the bind-to
attribute is in scope within the sequence constructor, and is bound, on each iteration, to the array member
being processed.
The result of the instruction is the sequence-concatenation of the results of the repeated iterations, respecting the original order of members in the array.
The context item, position, and size are not changed within the instruction; references to .
,
position()
, or last()
may therefore not have the expected effect.
Example:
<xsl:variable name="emp-array" select="parse-json('employees.json')"/> <saxon:for-each-member select="array:sort($emp-array, function($e){$e?ssn})" bind-to="emp"> <employee ssn="{$emp?ssn}"> <firstName>{$emp?first}</firstName> <lastName>{$emp?last}</lastName> </employee> </saxon:for-each-member>