XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / sequence
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 6.)
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
The instruction xsl:sequence generates and returns a sequence of nodes and/or atomic values.
Classification | Instruction |
Function group | Create a sequence |
Introduced | XSLT 2.0 |
Position in the stylesheet and permitted contents:
The instruction xsl:sequence can be used anywhere within sequence constructors. It is also often the final element of an xsl:function declaration in a stylesheet function, constructing and returning its result sequence.
The instruction is usually empty. Its only permitted contents are xsl:fallback instructions, which XSLT 2.0 processors ignore and which are intended only for XSLT 1.0 processors in FC mode. A sequence constructor is therefore never allowed.
Attributes:
Standard attributes apply. In addition, xsl:sequence has a required select attribute.
select
Value | xpath-expression |
Usage | required |
Introduced | XSLT 2.0 |
The XPath expression in the required select attribute creates the sequence returned by the instruction. If no select attribute is present, the instruction returns the empty sequence.
Usage:
The instruction returns a sequence determined by the XPath expression in its select attribute. It may contain nodes and atomic values. The permitted contents of xsl:sequence are xsl:fallback instructions; otherwise it remains empty.
Note: The sequence specified by the select attribute cannot be sorted directly. However, a sorted sequence can be constructed using xsl:perform-sort.
Examples:
Example 1 – Creating a sequence with xsl:sequence:
<xsl:variable name="seq1">
<xsl:sequence select="(1, 2, 3, 4)"></xsl:sequence>
</xsl:variable>
stores in $seq1 a sequence of xs:integer values (1,2,3,4), which can be output as follows:
<xsl:value-of select="$seq1" separator=","/>
This produces the output string “1,2,3,4,5”.
Example 2 – xsl:sequence in a function declaration:
<xsl:function name="mein:addierer">
<xsl:param name="wert1"/>
<xsl:param name="wert2"/>
<xsl:sequence select="$wert1 + $wert2"/>
</xsl:function>
The call mein:addierer(17, 4) uses xsl:sequence to return result sequence (21), which can, for example, be output as a string with <xsl:value-of select="mein:addierer(17, 4)"/>.
Example 3 – Creating a node sequence with duplicates:
<xsl:sequence select="(//test, //test)"/>
creates a sequence containing every <test> element in the context document twice. This example is admittedly somewhat contrived: essentially, two sequences of the corresponding nodes in document order are concatenated.
Element definition:
XSLT 1.0:
Element unavailable in XSLT 1.0.
XSLT 2.0:
<!-- Category: instruction -->
<xsl:sequence
select = expression >
<!-- Content: xsl:fallback* -->
</xsl:sequence>
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn