The syntax of match patterns is extended to make it easier to match maps and arrays. As with 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
is any of:
For example if a type alias has been declared:
Then it can be used in a match pattern to match instances of the type, with or without predicates:
type(T) at the start of a pattern can be regarded as an abbreviation for
.[. instance of type(T)].
Patterns for record types are particularly useful when JSON is processed using XSLT template rules. For example, a JSON object such as the following:
can be matched with a pattern such as
match="record(firstName, lastName, email, *)". Naming a few of the
properties that characterize the object is sufficient (but remember to make the record type extensible by including
at the end). There's generally no need to include all the properties, or to give their data types, because a test like this
is generally sufficient to be unambiguous. The order of properties, of course, is immaterial.
Predicates can be added as with any other pattern, for example
match="record(firstName, lastName, *)[?department='sales']".
The rules for calculating the default priority of these patterns are not yet stable; explicit priorities should be used if there is any risk of ambiguity.