The following associated resources are available: Specification in XML format, XSD 1.1 Schema for XSLT 4.0 Stylesheets (non-normative), Relax-NG Schema for XSLT 4.0 Stylesheets (non-normative), Stylesheet for XML-to-JSON conversion (non-normative)
Copyright © 2026 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This specification defines the syntax and semantics of XSLT 4.0, a language designed primarily for transforming XML documents into other XML documents, but also offering support for other data formats including JSON, HTML, and CSV.
XSLT 4.0 is a revised version of the XSLT 3.0 Recommendation [XSLT 3.0] published on 8 June 2017. Changes are presented in 1.2 What’s New in XSLT 4.0?.
XSLT 4.0 is designed to be used in conjunction with XPath 4.0, which is defined in [XPath 4.0]. XSLT shares the same data model as XPath 4.0, which is defined in [XDM 4.0], and it uses the library of functions and operators defined in [Functions and Operators 4.0]. XPath 4.0 and the underlying function library introduce a number of enhancements, for example the availability of union and record types.
This document contains hyperlinks to specific sections or definitions within other documents in this family of specifications. These links are indicated visually by a superscript identifying the target specification: for example XP for XPath 4.0, DM for the XDM data model version 4.0, FO for Functions and Operators version 4.0, SG for XSLT Streaming version 4.0.
An optional feature of the XSLT language is support for streamed transformations. The XSLT 4.0 specification has been modularized so that streaming is now described in a separate specification document. This has been done in order to make the specifications more manageable, both for editors and readers: it does not alter the status of streaming as an optional feature, available in some processors and not others.
This section describes the status of this document at the time of its publication. Other documents may supersede this document.
This document is a working draft developed and maintained by a W3C Community Group, the XQuery and XSLT Extensions Community Group unofficially known as QT4CG (where "QT" denotes Query and Transformation). This draft is work in progress and should not be considered either stable or complete. Standard W3C copyright and patent conditions apply.
The community group welcomes comments on the specification. Comments are best submitted as issues on the group's GitHub repository.
The community group maintains two extensive test suites, one oriented to XQuery and XPath, the other to XSLT. These can be found at qt4tests and xslt40-test respectively. New tests, or suggestions for correcting existing tests, are welcome. The test suites include extensive metadata describing the conditions for applicability of each test case as well as the expected results. They do not include any test drivers for executing the tests: each implementation is expected to provide its own test driver.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
This section describes instructions that directly create new nodes.
Changes in 4.0 (next | previous)
The xsl:text instruction can now have a select attribute, and it can take a sequence constructor as its content. The only remaining distinction between the xsl:text and xsl:value-of instructions is that whitespace text node children of xsl:text are treated as significant, rather than being stripped during stylesheet preprocessing. [Issue 323 PR 2251 14 October 2025]
This section describes three different ways of creating text nodes: by means of literal text nodes in the stylesheet, or by using the xsl:text and xsl:value-of instructions. It is also possible to create text nodes using the xsl:number instruction described in 12 Numbering.
If and when the sequence that results from evaluating a sequence constructor is used to form the content of a node, as described in 5.7.2 Constructing Simple Content and 5.7.1 Constructing Complex Content, adjacent text nodes in the sequence are merged. Within the sequence itself, however, they exist as distinct nodes.
The following function returns a sequence of three text nodes:
<xsl:function name="f:wrap"> <xsl:param name="s"/> <xsl:text>(</xsl:text> <xsl:value-of select="$s"/> <xsl:text>)</xsl:text> </xsl:function>
When this function is called as follows:
<xsl:value-of select="f:wrap('---')"/>the result is:
(---)
No additional spaces are inserted, because the calling xsl:value-of instruction merges adjacent text nodes before atomizing the sequence. However, the result of the instruction:
<xsl:value-of select="data(f:wrap('---'))"/>is:
( --- )
because in this case the three text nodes are atomized to form three strings, and spaces are inserted between adjacent strings.
This example reflects the traditional usage of xsl:text to output constant text and xsl:value-of to output variable text. In XSLT 4.0, however, either instruction can be used for either purpose, and in the example above either instruction could be replaced by the other.
It is possible to construct text nodes whose string value is zero-length. A zero-length text node, when atomized, produces a zero-length string. However, zero-length text nodes are ignored when they appear in a sequence that is used to form the content of a node, as described in 5.7.1 Constructing Complex Content and 5.7.2 Constructing Simple Content.
Changes in 4.0 (next | previous)
The attribute cdata is added to xsl:text and xsl:value-of to request serialization of a text node as a CDATA section. [Issue 2198 PR 2301 19 November 2025]
The XDM data model (see [XDM 4.0]) does not recognize CDATA sections as a special kind of node; CDATA is regarded simply as one way of serializing a text node. The elements <e>x < y</e> and <e><![CDATA[x < y]]></e> have exactly the same representation in XDM: an element node with a text node child, the string value of the text node being "x < y".
It is however possible to request that a text node should be serialized as a CDATA section. If all elements with a given name are to be serialized as CDATA, this can be achieved using the serialization parameter cdata-section-elements (available, for example, as an attribute on xsl:output and xsl:result-document). If CDATA serialization is to be used more selectively than this, it can also be requested using the cdata attribute on the xsl:text and xsl:value-of instructions.
The cdata attribute, if its effective value is yes, is a request to the processor to serialize the text node as a CDATA section. For example, the text node produced by the instruction <xsl:text cdata="yes">>>></xsl:text> might be serialized as <![CDATA[>>>]]>. Honoring this request requires close coupling between the processor and the serializer, and processors may therefore ignore the request. In particular, it is likely that a processor will ignore the request unless the result of the transformation is passed directly to the serializer, bypassing the construction of an in-memory result tree.
It is implementation-defined whether, and under what circumstances, the cdata attribute of the xsl:text and xsl:value-of instructions has any effect on the serialized output.
If the cdata attribute is present, regardless of its effective value, then the disable-output-escaping attribute is ignored.
Note:
The attribute is likely to have no effect in the following circumstances:
The output of the transformation is not sent directly to a serializer.
The serialization method is not xml or xhtml.
The text node produced by the xsl:text or xsl:value-of instruction is bound to a variable.
The text node is used as input to the process of constructing an attribute, comment, processing instruction, or another text node: see 5.7.2 Constructing Simple Content.
The text node is used as input to the process of constructing a temporary tree.
Note:
The attribute is an attribute value template, so the value can be made conditional on the actual content of the text. For example, the instruction:
<xsl:value-of select="$s" cdata="{matches($s, '[<&]')}"/>will request serialization as a CDATA section if the text contains either of the characters < or &.
The serializer should serialize the content of the text node following the same conventions as are used for cdata-section-elements: in particular, if the data includes the character sequence ]]>, then the CDATA section should be closed, and a new CDATA section opened, after the ]].
| Editorial note | |
Add this attribute to the schema for XSLT 4.0 | |