mirror of
https://github.com/alexandrev/xslt-lab.git
synced 2026-09-18 19:43:16 +00:00
53e90ef86e
Full coverage of XSLT 1.0, 2.0 and 3.0 elements and XPath functions: - 59 XSLT elements (xsl:stylesheet → xsl:use-accumulators) - 170 XPath functions (1.0 node/string/numeric/boolean, 2.0 sequence/ date/QName/string, 3.0 HOF/map/array/JSON/streaming) Each page: description, parameters table, return value, 2 runnable Saxon examples with input XML + stylesheet + output, notes, cross-links. xsltCompletions.js: all 229 entries now have blogSlug for hover links. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3.7 KiB
3.7 KiB
title, description, date, version, versionLabel, category, syntax, tags
| title | description | date | version | versionLabel | category | syntax | tags | |||
|---|---|---|---|---|---|---|---|---|---|---|
| xsl:sequence | Returns a sequence of items; the XSLT 2.0 equivalent of xsl:value-of for typed values and node sequences. | 2026-04-18T00:00:00Z | 2.0 | XSLT 2.0 | element | <xsl:sequence select="expression"/> |
|
Description
xsl:sequence evaluates an XPath expression and adds the resulting items — nodes, atomic values, or mixed sequences — directly to the result sequence of the current template or function. Unlike xsl:value-of, it preserves the type of each item: integers stay integers, nodes stay nodes, and sequences remain sequences.
It is the idiomatic way to return a value from an xsl:function, and the correct instruction to use when you want to pass typed data rather than a string representation.
Key differences from xsl:value-of:
xsl:value-of |
xsl:sequence |
|
|---|---|---|
| Output | Always a text node | Items of any type |
| Types preserved | No (stringified) | Yes |
| Nodes | Copies as text | Adds as reference or copy |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
select |
XPath expression | Yes | The expression whose result is added to the output sequence. |
Return value
The items produced by the select expression, added to the current output sequence. No wrapper node is created.
Examples
Returning a typed value from a function
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://example.com/my">
<xsl:output method="xml" indent="yes"/>
<xsl:function name="my:double" as="xs:integer">
<xsl:param name="n" as="xs:integer"/>
<xsl:sequence select="$n * 2"/>
</xsl:function>
<xsl:template match="/">
<result>
<xsl:value-of select="my:double(21)"/>
</result>
</xsl:template>
</xsl:stylesheet>
Output:
<result>42</result>
Returning a node sequence
Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<item status="active">Alpha</item>
<item status="inactive">Beta</item>
<item status="active">Gamma</item>
</catalog>
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://example.com/my">
<xsl:output method="xml" indent="yes"/>
<xsl:function name="my:active-items" as="element()*">
<xsl:param name="items" as="element()*"/>
<xsl:sequence select="$items[@status='active']"/>
</xsl:function>
<xsl:template match="/catalog">
<active>
<xsl:for-each select="my:active-items(item)">
<entry><xsl:value-of select="."/></entry>
</xsl:for-each>
</active>
</xsl:template>
</xsl:stylesheet>
Output:
<active>
<entry>Alpha</entry>
<entry>Gamma</entry>
</active>
Notes
xsl:sequenceis the only correct way to return typed values (integers, dates, booleans) fromxsl:function. Usingxsl:value-ofinside a function always produces a text node.- When
selectreturns nodes, they are added by reference to the sequence, not deep-copied. If you need independent copies, wrap withcopy-of(). xsl:sequencecan appear in any context where items are allowed, including insidexsl:choose,xsl:if, andxsl:for-each.- An empty
xsl:sequence select="()"adds nothing — useful as a no-op branch in a conditional.