Configurable rule optimization
Highly experimental configurable optimizations can be defined through children of the patternOptimization
element. Defining them
requires detailed knowledge of XPath models and is not recommended at this stage for any production purposes.
The following child elements can be used to describe specific optimizations:
The canonical form of these optimization directives is:
<directive pattern="pattern" when="condition"? mode="modes"? ... .../>where pattern is a pattern that is matched against some or all of a template match pattern (xsl:template/@match
),
condition is an optional predicate that can qualify expression-binding variables within the pattern and modes is a
description of applicable modes, almost exactly analogous to xsl:template/@mode
. The default for modes is
#all
; namespaced modes should be defined through EQNames.
Patterns
Patterns play a vital part in these optimization declarations, and are in part unified against template patterns. This is most easily illustrated with a simple indexation example:
<index pattern="*[tokenize(@class)=$S]" index.expr="tokenize(@class)" index.value="$S"/>This directive is tested against template match patterns (possibly restricted to declared modes) through a form of unification. If a template is:
<xsl:template match="*[tokenize(@class) = 'Appendix']">...then the patterns can be matched with an equivalence binding of $S := 'Appendix'
. In this case this rule is deemed to be
indexable: to determine the possible key for a node, the expression tokenize(@class)
will be executed, resulting in a (possibly
empty) sequence of strings. Similarly the rule itself will have been added to the list of rules (for this optimization) which are indexed
against the string 'Appendix'
.
The syntax and semantics of these patterns are in an experimental phase at present, and mostly geared to variability in and binding to string
values, such as the use of $S
in the example above. Currently:
- Variables in the pattern are bound to the expression they match in the template pattern parse tree. (Effectively they are named wildcards.) Currently it isn't therefore possible to match real variable references within a template pattern.
- Such variables may be predicated within evaluation of the
@when
expression, e.g.when="$S[starts-with('foo-')]"
: only if the predicate expression evaluates true with the variable bindings found during the unification will the indexation be permitted. - If the pattern matches, and any predication permits, then any variable bindings found in the pattern unification become in-scope for execution in generating the 'productions' of the directive, in this case the pair for the indexation.