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:
-
type(...)
-
atomic(...)
-
union(...)
-
tuple(...)
-
map(...)
-
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:
-
Within
<xsl:choose> <xsl:when test="$day = 'Monday'" select="1"/> <xsl:when test="$day = 'Tuesday'" select="2"/> <xsl:when test="$day = 'Wednesday'" select="3"/> <xsl:when test="$day = 'Thursday'" select="4"/> <xsl:when test="$day = 'Friday'" select="5"/> <xsl:otherwise select="-1"/> </xsl:choose>xsl:choose
, thexsl:when
andxsl:otherwise
instructions can define the returned value using aselect
attribute in place of a sequence constructor. For example: -
The
<xsl:if test="$day = 'Monday'" then="1" else="0"/>xsl:if
instruction can deliver its results usingthen
andelse
attributes in place of a contained sequence constructor. For example:If the
then
attribute is present, thexsl:if
instruction must be empty (have no children). Either attribute can be used independently; there is no requirement for both to be present.
These new forms of xsl:choose
and xsl:if
are particularly useful
to compute the return value of a function, replacing xsl:sequence
.