XSLT Syntax Extensions

Most Saxon extensions to the XSLT 3.0 language have been implemented using the extensibility mechanisms defined in the W3C XSLT 3.0 specification: they are typically implemented as extension instructions, declarations, attributes, or functions in the Saxon namespace.

A few experimental extensions have also been implemented by changing the native syntax. These are intended for usability evaluation, with a view to inclusion in some future version of the XSLT language. These extensions (described in this section) are available only if explicitly enabled. This can be achieved using the configuration option Feature.ALLOW_SYNTAX_EXTENSIONS (use --allowSyntaxExtensions:on on the command line, or global/@allowSyntaxExtensions="true" in the configuration file).

Enabling syntax extensions not only allows the use of the XSLT extensions described in this section, it also allows XPath extensions to be used in expressions and sequence types within the stylesheet, as described in XPath and XQuery Syntax Extensions.

Match Patterns

The syntax of match patterns is extended to make it easier to match maps and arrays. As for the XPath syntax extensions, these extensions are available only if explicitly enabled.

In particular the syntax ma-type predicate* is allowed in a pattern, where ma-type is any of:

  1. type(...)
  2. atomic(...)
  3. union(...)
  4. tuple(...)
  5. map(...)
  6. array(...)

For example if a type alias has been declared:

<saxon:item-type name="cx:complex" type="tuple(r as xs:double, i as xs:double)"/>

Then it can be used in a match pattern to match instances of the type, with or without predicates:

<xsl:template match="type(cx:complex)[?i=0]">{?r}</xsl:template><xsl:template match="type(cx:complex)">{?r}{if (?i ge 0) then '+' else ''}{?i}i</xsl:template>

The construct type(T) at the start of a pattern can be regarded as an abbreviation for .[. instance of type(T)].

Conditional Instructions

If syntax extensions are enabled, then the xsl:choose and xsl:if instructions are enhanced as follows:

These new forms of xsl:choose and xsl:if are particularly useful to compute the return value of a function, replacing xsl:sequence.