# XSLT 3.0 Support

Saxon 9.3 introduces support for a number of features defined in the draft XSLT 3.0 specification (previously known as XSLT 2.1). It must be noted that this is an early working draft, and everything is subject to change. If the W3C specification changes, Saxon will change to match, without regards to backwards compatibility. Use it at your own risk.

All these features require at least Saxon-PE. Streaming requires Saxon-EE.

XSLT 3.0 support must be explicitly enabled, for example by specifying `version="3.0"` in the stylesheet or by using the option `-xsltversion:3.0` on the command line. It can also be enabled from the configuration file or using methods in the API (for example, on the s9api `XsltCompiler` object).

The following features are implemented. For full details, see the W3C specifications.

xsl:evaluate

This is a new instruction providing a standard way to perform dynamic evaluation of XPath expressions. This effectively replaces the need for extensions such as `saxon:evaluate`, though that is likely to be retained for a long time as it is so widely used. This instruction is fully implemented, except that the precise rules for which functions can be called within the dynamic XPath expression may not be 100% aligned with the specification.

xsl:try and xsl:catch

The `xsl:try` and `xsl:catch` instructions provide a way for dynamic errors to be intercepted. This applies both to system-defined errors and to errors thrown explicitly using the `error()` function or by calling `xsl:message terminate="yes"` (which becomes something of a misnomer). The syntax allows catching of specific error codes. The Saxon implementation is complete, though there may be edge cases where the semantics are not precisely as defined in the specification; there may also be error conditions where Saxon is not using the most appropriate error code according to the specification.

xsl:iterate

The `xsl:iterate` instruction provides an alternative way of iterating over a sequence. Unlike `xsl:for-each`, it is explicitly sequential, processing one item at a time in order, which means it is possible to break out of the loop at any time using `xsl:break`. It is also possible to pass data from one iteration to the next using parameters, allowing the kind of processing that previously required recursion. The Saxon implementation is functionally complete.

xsl:mode

The `xsl:mode` declaration allows attributes of a mode to be declared. Most notably, the mode can be declared to be streamable, in which case all the template rules for that mode must satisfy the rules for streamability. This allows large source documents to be processed without building an entire tree in memory. (Streaming is available only in Saxon-EE, and is further described at Streamed processing of large documents.)

The following attributes are implemented:

- `name` (optional). The name of a mode; absence indicates the unnamed mode.

- `streamable = yes|no`. This indicates whether the mode allows documents to be processed using streaming.

- `on-no-match = stringify|copy|discard|fail`. This allows the stylesheet to specify how nodes are to be processed in the absence of a matching template rule.

- `on-multiple-match = fail | use-last`. Indicates what happens when more than one template rules with the same import precedence and priority matches a node.

- `warning-on-no-match = yes|no`. Indicates whether warnings are output when there is no user-defined template rule matching a node.

- `warning-on-multiple-match = yes|no`. Indicates whether warnings are output when there is no user-defined template rule matching a node.

The attribute `initial=yes|no` is not yet implemented. The rules for handling multiple `xsl:mode` declarations for the same mode (taking account of import precedence) are not yet implemented. The `xsl:context-item` element is not yet implemented.

As well as the `streamable` attribute of `xsl:mode`, the `on-no-match` attribute is implemented, with values `copy`, `discard`, `stringify`, or `fail`. This allows the stylesheet to specify how nodes are to be processed in the absence of a matching template rule.

XSLT 3.0 functions

The `unparsed-text-lines()` function is implemented.

The functions `copy-of()` and `snapshot()` are implemented.