This specification defines the syntax and semantics of the XSLT 3.0 language.
A transformation in the XSLT language is expressed in the form of a stylesheet. A stylesheet is made up of one or more well-formed XML [XML 1.0] documents conforming to the Namespaces in XML Recommendation [Namespaces in XML].
A stylesheet generally includes elements that are defined by XSLT as well as elements
that are not defined by XSLT. XSLT-defined elements are distinguished by use of the
namespace http://www.w3.org/1999/XSL/Transform
(see 3.1 XSLT Namespace), which is referred to in this specification as the
XSLT namespace. Thus this specification
is a definition of the syntax and semantics of the XSLT namespace.
The term stylesheet reflects the fact that one of the important roles of XSLT is to add styling information to an XML source document, by transforming it into a document consisting of XSL formatting objects (see [XSL-FO]), or into another presentation-oriented format such as HTML, XHTML, or SVG. However, XSLT is used for a wide range of transformation tasks, not exclusively for formatting and presentation applications.
A transformation expressed in XSLT describes rules for transforming input data into output data. The inputs and outputs will all be instances of the XDM data model, described in [XDM 3.0]. In the simplest and most common case, the input is an XML document referred to as the source tree, and the output is an XML document referred to as the result tree. It is also possible to process multiple source documents, to generate multiple result documents, and to handle formats other than XML. The transformation is achieved by a set of template rules. A template rule associates a pattern, which typically matches nodes in the source document, with a sequence constructor. In many cases, evaluating the sequence constructor will cause new nodes to be constructed, which can be used to produce part of a result tree. The structure of the result trees can be completely different from the structure of the source trees. In constructing a result tree, nodes from the source trees can be filtered and reordered, and arbitrary structure can be added. This mechanism allows a stylesheet to be applicable to a wide class of documents that have similar source tree structures.
Stylesheets have a modular structure; they may contain several packages developed independently of each other, and each package may consist of several stylesheet modules.
[Definition: A stylesheet consists of one or more packages: specifically, one top-level package and zero or more library packages.]
[Definition: For a given transformation, one package functions as the top-level package. The
complete stylesheet is assembled by finding
the packages referenced directly or indirectly from the top-level package using
xsl:use-package
declarations: see 3.5.2 Dependencies between Packages.]
[Definition: Every package within a stylesheet, other than the top-level package, is referred to as a library package.]
[Definition: Within a package, one stylesheet module functions as the
principal stylesheet module. The complete package is assembled by
finding the stylesheet modules referenced directly or indirectly from the
principal stylesheet module using xsl:include
and
xsl:import
elements: see 3.11.2 Stylesheet Inclusion and 3.11.3 Stylesheet Import.]
A major focus for enhancements in XSLT 3.0 is the requirement to enable streaming of source documents. This is needed when source documents become too large to hold in main memory, and also for applications where it is important to start delivering results before the entire source document is available.
While implementations of XSLT that use streaming have always been theoretically possible, the nature of the language has made it very difficult to achieve this in practice. The approach adopted in this specification is twofold: it identifies a set of restrictions which, if followed by stylesheet authors, will enable implementations to adopt a streaming mode of operation without placing excessive demands on the optimization capabilities of the processor; and it provides new constructs to indicate that streaming is required, or to express transformations in a way that makes it easier for the processor to adopt a streaming execution plan.
Capabilities provided in this category include:
A new xsl:source-document
instruction, which reads and processes a
source document, optionally in streaming mode;
The ability to declare that a mode is a streaming mode, in which case all the template rules using that mode must be streamable;
A new xsl:iterate
instruction, which iterates over the items
in a sequence, allowing parameters for the processing of one item to be set
during the processing of the previous item;
A new xsl:merge
instruction, allowing multiple input streams
to be merged into a single output stream;
A new xsl:fork
instruction, allowing multiple computations to
be performed in parallel during a single pass through an input document;
Accumulators, which allow a value to be computed progressively during streamed processing of a document, and accessed as a function of a node in the document, without compromise to the functional nature of the XSLT language.
A second focus for enhancements in XSLT 3.0 is the introduction of a new mechanism for stylesheet modularity, called the package. Unlike the stylesheet modules of XSLT 1.0 and 2.0 (which remain available), a package defines an interface that regulates which functions, variables, templates and other components are visible outside the package, and which can be overridden. There are two main goals for this facility: it is designed to deliver software engineering benefits by improving the reusability and maintainability of code, and it is intended to streamline stylesheet deployment by allowing packages to be compiled independently of each other, and compiled instances of packages to be shared between multiple applications.
Other significant features in XSLT 3.0 include:
An xsl:evaluate
instruction allowing evaluation of XPath
expressions that are dynamically constructed as strings, or that are read from
a source document;
Enhancements to the syntax of patterns, in particular enabling the matching of atomic values as well as nodes;
An xsl:try
instruction to allow recovery from dynamic
errors;
The element xsl:global-context-item
, used to declare the
stylesheet’s expectations of the global context item (notably, its
type);
A new instruction xsl:assert
to assist developers in producing
correct and robust code.
XSLT 3.0 also delivers enhancements made to the XPath language and to the standard function library, including the following:
Variables can now be bound in XPath using the let
expression.
Functions are now first class values, and can be passed as arguments to other (higher-order) functions, making XSLT a fully-fledged functional programming language.
A number of new functions are available, for example trigonometric functions,
and the functions parse-xml
FO30 and
serialize
FO30 to convert between lexical and tree
representations of XML.
XSLT 3.0 also includes support for maps (a data structure consisting of key/value pairs, sometimes referred to in other programming languages as dictionaries, hashes, or associative arrays). This feature extends the data model, provides new syntax in XPath, and adds a number of new functions and operators. Initially developed as XSLT-specific extensions, maps have now been integrated into XPath 3.1 (see [XPath 3.1]). XSLT 3.0 does not require implementations to support XPath 3.1 in its entirety, but it does requires support for these specific features.
A full list of changes is at J Changes since XSLT 2.0.