XSLT Patterns
Since Saxon 9.9, 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. 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).
In particular the syntax ma-type predicate*
is allowed, where ma-type
is any of:
- ~type-alias
- tuple(...)
- map(...)
- array(...)
For example if a type alias has been declared:
<saxon:type-alias name="cx:complex" type="tuple(r: xs:double, i: xs:double)"/>Then it can be used in a match pattern to match instances of the type, with or without predicates:
<xsl:template match="~cx:complex[?i=0]">{?r}</xsl:template><xsl:template match="~cx:complex">{?r}{if (?i ge 0) then '+' else ''}{?i}i</xsl:template>The construct ~T
at the start of a pattern can be regarded as an abbreviation for
.[. instance of ~T]
.