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.
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 3.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.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
This document has no official standing. It is produced by the editor as a proposal for community review. Insofar as it copies large amounts of text from the W3C XSLT 3.0 Recommendation, W3C copyright and similar provisions apply.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
XSLT uses the expression language defined by XPath 4.0 [XPath 4.0]. Expressions are used in XSLT for a variety of purposes including:
selecting nodes for processing;
specifying conditions for different ways of processing a node;
generating text to be inserted in a result tree.
[Definition: Within this specification, the term XPath expression, or simply expression, means a string that matches the production ExprXP defined in [XPath 4.0].]
XPath expressions may occur:
As the value of certain attributes on XSLT-defined instructions (for example, the select attribute of the xsl:apply-templates instruction)
Within curly brackets in attribute value templates and text value templates.
As the content of a text node within an xsl:select instruction.
In the above cases, the static processing (compilation) of XPath expressions takes place at the same time as the static processing of the stylesheet itself, while evaluation of the XPath expressions takes place dynamically during stylesheet evaluation. There are also, however:
XPath expressions where both the static processing and dynamic evaluation of the XPath expression takes place during static processing of the stylesheet. These are referred to as static expressions, and they perform the same function as preprocessing directives in other languages.
XPath expressions that are dynamically constructed (as character strings): both the static processing and dynamic evaluation of these expressions occurs during stylesheet evaluation. See ???.
In general:
It is a static error if an XPath expression does not match the XPath production ExprXP, or if it fails to satisfy other static constraints defined in the XPath specification, for example that all variable references must refer to variables that are in scope. Error codes are defined in [XPath 4.0].
The transformation fails with a dynamic error if any XPath expression is evaluated and raises a dynamic error. Error codes are defined in [XPath 4.0].
The transformation fails with a type error if an XPath expression raises a type error, or if the result of evaluating the XPath expression is evaluated and raises a type error, or if the XPath processor raises a type error during static analysis of an expression. Error codes are defined in [XPath 3.0].
There are some exceptions to these rules, for example:
Static errors may be suppressed where forwards compatible behavior is enabled (see 3.10 Forwards Compatible Processing).
Dynamic errors evaluating a predicate within a pattern do not cause the transformation to fail, they merely cause the pattern not to match.
[Definition: The context within a stylesheet where an XPath expression appears may specify the required type of the expression. The required type indicates the type of the value that the expression is expected to return.] If no required type is specified, the expression may return any value: in effect, the required type is then item()*.
[Definition: The term coercion rules means the coercion rules defined in [XPath 4.0], applied unless otherwise specified with XPath 1.0 compatibility mode set to false.]
Note:
In earlier versions of this specification, the coercion rules were referred to as the function conversion rules.
Note:
These are the rules defined in [XPath 4.0] for converting the supplied argument of a function call to the required type of that argument, as defined in the function signature. The same rules are used in XSLT for converting the value of a variable to the declared type of the variable, or the result of evaluating a function or template body to the declared type of the function or template. They are also used when parameters are supplied to a template using xsl:with-param. In all such cases, the rules that apply are the XPath 4.0 rules without XPath 1.0 compatibility mode. The rules with XPath 1.0 compatibility mode set to true are used only for XPath function calls, and for the operands of certain XPath operators.
This specification also invokes the XPath coercion rules to convert the result of evaluating an XSLT sequence constructor to a required type (for example, the sequence constructor enclosed in an xsl:variable, xsl:template, or xsl:function element).
Any dynamic error or type error that occurs when applying the coercion rules to convert a value to a required type results in the transformation failing, in the same way as if the error had occurred while evaluating an expression.
Note:
Note the distinction between the two kinds of error that may occur. Attempting to convert an integer to a date is a type error, because such a conversion is never possible. Type errors can be raised statically if they can be detected statically, whether or not the construct in question is ever evaluated. Attempting to convert the xs:untypedAtomic item 2003-02-29 to a date is a dynamic error rather than a type error, because the problem is with this particular value, not with its type. Dynamic errors are raised only if the instructions or expressions that cause them are actually evaluated. [XSLT 3.0 Erratum E21, bug 30236]
The XPath specification states (see Section A.3.4 End-of-Line HandlingXP) that the host language must specify whether the XPath processor normalizes all line breaks on input, before parsing, and if it does so, whether it uses the rules of [XML 1.0] or [XML 1.1]. In the case of XSLT, all handling of line breaks is the responsibility of the XML parser (which may support either XML 1.0 or XML 1.1); the XSLT and XPath processors perform no further changes.
Note:
Most XPath expressions in a stylesheet appear within XML attributes. They are therefore subject to XML line-ending normalization (for example, a CRLF sequence is normalized to LF) and also to XML attribute-value normalization, which replaces tabs and newlines by spaces. Normalization of whitespace can be prevented by using character references such as 	.
XPath expressions appearing in text nodes, (specifically, in text value templates — see 5.7.2 Text Value Templates, or in the xsl:select instruction) are subject to line-ending normalization but not attribute-value normalization.
In both cases it is unwise to include the characters U+0009 (TAB) , U+000A (NEWLINE) , and U+000D (CARRIAGE RETURN) , as literal characters within string literals. Instead they should be escaped as 	, 
, and 
 respectively, or constructed dynamically by a call on the char function. This can be conveniently embedded within a string template delimited by backticks: for example `Width:{char(9)}8mm`. (The advantage of using this form in preference to XML character references is that they are more likely to survive when the stylesheet is processed using tools such as XML editors.)
This section describes three constructs that can be used to provide subroutine-like functionality that can be invoked from anywhere in the stylesheet: named templates (see 10.1 Named Templates), named attribute sets (see 10.2 Named Attribute Sets), and stylesheet functions (see 10.3 Stylesheet Functions).
[Definition: The following constructs are classified as invocation constructs: the instructions xsl:call-template, xsl:apply-templates, xsl:apply-imports, and xsl:next-match; XPath function calls that bind to stylesheet functions; XPath dynamic function calls; the functions accumulator-before and accumulator-after; the [xsl:]use-attribute-sets attribute. These all have the characteristic that they can cause evaluation of constructs that are not lexically contained within the calling construct.]
The two instructions described in this section, xsl:sequence and xsl:select, can be used to evaluate XPath expressions that are statically known: that is, the XPath expressions are statically processed during the static processing of the stylesheet, and are dynamically evaluated during the dynamic evaluation of the stylesheet. The xsl:sequence instruction can also be used to evaluate a sequence constructor.
xsl:select Instruction The xsl:select instruction is new in 4.0. [Issue 2004 PR 2008 20 May 2025]
<!-- Category: instruction -->
<xsl:select
as? = sequence-type〔'item()*'〕 >
<!-- Content: (xsl:fallback*#PCDATA) -->
</xsl:select>
The xsl:select instruction evaluates an XPath expression contained as a child node of the instruction. For example, the instruction:
<xsl:select as="map(*)"> { "title" : $title, "author" : $author } </xsl:select>
evaluates the contained XPath expression, in the current static and dynamic context, and returns (in this example) a map with two entries.
While the xsl:sequence instruction (with a select attribute) can also be used to evaluate an arbitrary XPath expression and return its result, the xsl:select instruction offers some potential advantages:
An XPath expression written within an XML attribute is subjected by the XML parser to attribute value normalization, which changes the arrangement of whitespace within the value. While this will rarely affect the actual meaning of the expression, it can mean that formatting is lost. Multi-line attribute values are therefore best avoided. The loss of formatting also makes it difficult for an XSLT processor to provide precise error locations.
When an XPath expression appears in an attribute value, then one of the characters U+0022 (QUOTATION MARK, ") or U+0027 (APOSTROPHE, ') becomes unavailable for use with the expression, unless written as " or ' respectively. When an expression is written within a text node, this problem does not arise, and both characters can be used without escaping.
The content of the xsl:select instruction can be written as a CDATA section, allowing operators such as < and <= to be written without escaping.
The instruction name xsl:sequence can easily confuse people reading the code in cases where the intent is to return a single item.
With the increasing richness of the XPath language, expressions of ten or twenty lines become increasingly common, and this instruction makes such expressions more manageable. This often arises when constructing maps and arrays designed to be serialized as JSON. For example, a function might be defined that takes an element node as input and constructs a map containing selected information:
<xsl:function name="f:book-to-json" as="map(*)"> <xsl:param name="book" selectas="elementelement(book)(book)"> <xsl:select> { "title" : string($book/title), "isbn" : string($book/isbn), "price" : number($book/@price), "author" : array { $book/author ! string() }, "date" : current-date()" } </xsl:select> </xsl:function>
Any xsl:fallback child instructions will be ignored by an XSLT 4.0 processor, but will be evaluated by an XSLT 3.0 or earlier processor running in forwards compatible mode. An xsl:fallback instruction may be preceded by a text node consisting entirely of whitespace, but must not be preceded by a text node containing non-whitespace characters. The XPath expression to be evaluated is therefore contained in the last text node child. (XML comments, processing instructions, and xsl:note elements will already have been removed.)
The effect of the xsl:select instruction is as follows:
Let E be the string value of the last text node child of the instruction, if any.
If E is absent, zero-length, or consists entirely of whitespace, then let V be the empty sequence.
Otherwise, let V be the result of evaluating E as an XPath expression in the current static and dynamic context.
The result of the xsl:select instruction is the result of using the coercion rules to convert V to the type appearing in the as attribute, defaulting to item()*.
Note:
The text node cannot contain text value templates.
Note:
The xsl:select instruction requires the XPath expression to be known statically (though it can refer to variables whose value is dynamic). The xsl:evaluate instruction, by contrast, can be used to evaluate XPath expressions that are constructed dynamically or read from an external document. The xsl:evaluate instruction is described in the next section.
Note:
Many instructions take their input either from an XPath expression contained in a select attribute, or from a sequence constructor forming the content of the instruction, the two options being mutually exclusive. Instructions that follow this pattern include xsl:break, xsl:on-completion, xsl:catch, xsl:on-empty, xsl:when, xsl:attribute, and many others. In most of these cases, writing an XPath expression within a child xsl:select element is equivalent to writing the same expression with a select attribute. However, there are a few subtle differences, for example in the case of xsl:attribute and xsl:value-of, the default separator is different (a single space when a select attribute is used, a zero-length string for a sequence constructor comprising an xsl:select instruction).