A stylesheet may now consist of multiple packages. The language specification for packages has been designed with a view to allowing packages to be compiled independently of each other. The specification provides control over the interface offered by a package to other packages; in particular it allows functions, variables, named templates and other components to be declared as public, private, final, or abstract.
A new xsl:mode
declaration is added.
A mode may be declared to be streamable, and rules are given that constrain what the template rules in a streamable mode can do.
An xsl:mode
declaration may define the action to be
taken when there is no matching template rule, and the action to be taken
when there are multiple matching template rules.
An xsl:mode
declaration may indicate that the template
rules in a given mode are designed to process typed (schema-validated)
nodes only, or untyped nodes only. It may also indicate that element
names appearing in match patterns for the mode are only to match elements
in the source document that have been validated against the corresponding
element declarations in the schema.
A default mode can be declared for a stylesheet module, making it easier to reuse existing stylesheet modules to construct a composite stylesheet.
Several new instructions are introduced with the aim of making it easier to write streamable transformations, although all of these instructions can also be used without streaming:
The xsl:source-document
instruction is provided to
read and process an input document using streaming.
The xsl:iterate
instruction allows iterative processing
of a sequence, with the ability for the processing of one item to depend
on the results of processing of previous items, and with the ability to
terminate the iteration before all the items in the sequence have been
processed.
The xsl:merge
instruction allows several input sequences
to be merged into a single output sequence, based on the value of a merge
key.
The xsl:fork
instruction allows multiple results to be
computed during a single pass of a streamed input document.
The xsl:sequence
instruction can now contain a sequence
constructor as an alternative to using the select
attribute.
This is primarily for use cases involving xsl:fork
.
New instructions
xsl:where-populated
, xsl:on-empty
,
and xsl:on-non-empty
are introduced to allow elements to
be generated only when relevant content exists (or does not exist),
without requiring the input to be processed more than once.
Other changes introduced to facilitate the writing of streamable transformations include:
The new top-level declaration
xsl:accumulator
is introduced. An accumulator
represents information about a node in a document that can be computed
during a streamed pass over the document, starting at the start and
ending at that node.
New functions copy-of
and
snapshot
are provided, to enable streaming
applications to operate in windowing mode, where the input document is
divided into a sequence of small subtrees processed one at a time.
Some further new instructions are provided, unrelated to streaming:
The xsl:try
instruction allows recovery from dynamic
errors.
A new xsl:evaluate
instruction is provided, to allow
evaluation of XPath expressions constructed dynamically from strings, or
read from a source document.
The xsl:assert
instruction allows
arbitrary assertions about the state of variables or the input document,
improving testability and robustness.
Static global variables and parameters can be declared. These act as compile-time
constants. The values of static variables can be used in initializing other static
variables, or in [xsl:]use-when
attributes, or in shadow attributes.
Shadow attributes allow any attribute of an XSLT instruction or declaration to
be parameterized by reference to static variables and parameters.
Text nodes within a sequence constructor may now contain
text value templates (XPath
expressions enclosed in curly brackets), if this is enabled by setting
expand-text="yes">
on an enclosing element. This reduces the
verbosity of code written to generate boilerplate text with variable inserts.
The syntax of patterns has been
generalized. Patterns may now match any item (not only nodes). In consequence,
xsl:apply-templates
can now process sequences of atomic
values as well as nodes, and xsl:for-each-group
with the
group-starting-with
and group-ending-with
options
can also process atomic sequences. As a further consequence, the items in the initial match selection supplied when initiating a
transformation are no longer required to be nodes.
A new datatype, called a map, has been introduced, together with supporting functions, operators, and type syntax. Maps allow more complex data structures to be created than is possible using atomic values and nodes alone. This has particular applications to streamed processing: since a streamed application can visit each node of its primary input document only once, it often needs more advanced data structures to retain what it has already seen in the document.
Miscellaneous changes to existing instructions and declarations include:
The regular expression supplied to the
xsl:analyze-string
instruction is now permitted to be
one that matches a zero-length string.
The xsl:copy
instruction now has a select
attribute, which is convenient when it is used inside a function where
there is no context item.
Composite keys are supported in
xsl:for-each-group
.
Two new attributes have been added to xsl:function
to
provide increased scope for optimization: new-each-time
and
cache
. The first indicates whether the identity of nodes
created by the function is significant to the application; the second
indicates whether the function is to cache its results (memoization).
The override
attribute of
xsl:function
is renamed
override-extension-function
, retaining the old name as a
deprecated synonym.
The rule requiring xsl:import
declarations to precede all other declarations in a stylesheet module has
been removed.
Composite keys are supported in
xsl:key
.
A new attribute on xsl:message
allows
specification of an error code.
The rules for handling conflicts between
xsl:strip-space
and
xsl:preserve-space
have changed. A conflict that can
be detected statically is now signaled as a static error; a run-time
conflict between two declarations having the same precedence and priority
is now resolved by taking whichever comes last in declaration order.
An xsl:template
declaration may
contain an xsl:context-item
element to declare the
required type of the context item when the template is called.
An empty xsl:value-of
instruction with
no select
attribute is now permitted; its effect is to
construct a zero-length text node.
The xsl:variable
and
xsl:param
elements may now specify
static="yes"
, denoting that the variable is available
statically (informally, “at compile time”). Static variables and
parameters make the [xsl:]use-when
mechanism more useful,
especially in conjunction with xsl:assert
.
New functions are available to import and export data in JSON format.
A basic XSLT Processor now recognizes all the built-in types defined in XML Schema.
A basic XSLT Processor will
now accept the attribute validation="lax"
and interpret it in the
same way as a schema-aware processor when there is no schema component
available to perform the validation.
Some functions, including generate-id
FO30,
format-date
FO30, format-dateTime
FO30,
format-number
FO30, format-time
FO30,
and unparsed-text
FO30 have been moved from this
specification to the Functions and Operators specification, to make them
available in other host languages.
The rule that effectively prevented references to external
documents in [xsl:]use-when
expressions has been removed.
A default value is defined for the named template to be used
when initiating a transformation (specifically,
xsl:initial-template
).
Serialization to HTML5 and XHTML5 is supported. To this end,
a new serialization parameter html-version
is provided in
xsl:output
and xsl:result-document
.
Other new serialization parameters include:
item-separator
, json-node-output-method
, parameter-document
,
suppress-indentation
.
The concept of recoverable dynamic errors has been dropped. Of the remaining
recoverable dynamic errors, some are no longer errors, and others are now
situations where the behavior of the processor is implementation-dependent. The adjective non-recoverable in
describing other dynamic errors becomes redundant and has therefore been
dropped (the term was in any case misleading since the introduction of a
try/catch mechanism). Error codes of the form XTREnnnn
have been
renumbered XTDEnnnn
.
Dynamic errors occurring during pattern evaluation are always masked (they cause the pattern to report a non-match.)
A family of collation URIs is defined for selecting collations based on the Unicode Collation Algorithm.
The effect of specifying the type xs:untyped
or
xs:untypedAtomic
when validating by type is now defined.
The set of constructs that set temporary output state has been reduced, and no longer includes
instructions that create nodes, such as xsl:attribute
and
xsl:value-of
. However, xsl:merge-key
has
been added to the list.
The possibilities for invocation of a stylesheet have been expanded; they now include the ability to directly execute a stylesheet function; to supply parameters to the initial template; and to return the results of the invoked template or function as a raw value, without construction of a result tree.
A number of changes affecting XSLT 3.0 have been made in other related specifications. Some of the more significant changes are as follows:
A number of new functions have been defined whose aim is to facilitate
streaming. These include unparsed-text-lines
FO30,
innermost
FO30, outermost
FO30.
XPath 3.0 supports a subset of the let
expression from XQuery.
XPath 3.0 supports function items as first-class values (functions can, for example, be bound to variables and passed as parameters to other functions.)
XPath 3.0 supports a new syntax for writing expanded names using the namespace
URI and local part only, avoiding the need to create a static context that
binds namespace prefixes. This is intended to be particularly useful when XPath
expressions are software-generated. Complementing this, a new function
path
FO30 is available to generate a
(namespace-context-independent) path to any node that can subsequently be
evaluated using the xsl:evaluate
instruction, or
otherwise.