Conflict Resolution

Conflict Resolution
The problem of multiple patterns that match is handled by conflict resolution:
• Matching templates from imported modules are not considered if there is a matching template in the current module
• Matching templates with a lower priority are not considered. The default priority is determined as follows:
• Unqualified child or attribute names have a priority of 0.

• Processing-instructions with a target have a priority of 0.

• A namespace-qualified “*” child or attribute name has a priority of -0.25.

• An unqualified “*” has a priority of -0.5

• Any other template has a default priority of 0.5

• Template priority may be specified explicitly with the priority attribute on <xsl:template>

• “emphasis”, “html:p”, and “@foo” have a priority of 0

• “html:*” has a priority of -0.25

• “*” has a priority of -0.5

• “para/emphasis” has a priority of 0.5

• “emphasis/emphasis” has a priority of 0.5

• “emphasis[@role]” has a priority of 0.5

It is technically an error if the conflict resolution process yields more than one template, however, XSLTprocessors may (silently) recover from this error by selecting the template that occurs last in the stylesheet.
Effectively, this means that stylesheet template order is the final arbiter.

It is possible for a source node to match more than one template rule. The template rule to be used is determined as follows:

1. First, all matching template rules that have lower import precedence than the matching template rule or rules with the highest import precedence are eliminated from consideration.
2. Next, all matching template rules that have lower priority than the matching template rule or rules with the highest priority are eliminated from consideration. The priority of a template rule is specified by the priority attribute on the template rule. The value of this must be a real number (positive or negative), matching the production Number with an optional leading minus sign (-). [Definition: The default priority is computed as follows:]
o If the pattern contains multiple alternatives separated by |, then it is treated equivalently to a set of template rules, one for each alternative.

o If the pattern has the form of a QName preceded by a ChildOrAttributeAxisSpecifier or has the form processing-instruction(Literal) preceded by a ChildOrAttributeAxisSpecifier, then the priority is 0.

o If the pattern has the form NCName:* preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.25.

o Otherwise, if the pattern consists of just a NodeTest preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.5.

o Otherwise, the priority is 0.5.

Thus, the most common kind of pattern (a pattern that tests for a node with a particular type and a particular expanded-name) has priority 0. The next less specific kind of pattern (a pattern that tests for a node with a particular type and an expanded-name with a particular namespace URI) has priority -0.25.
Patterns less specific than this (patterns that just tests for nodes with particular types) have priority -0.5. Patterns more specific than the most common kind of pattern have priority 0.5.
It is an error if this leaves more than one matching template rule. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the matching template rules that are left, the one that occurs last in the stylesheet.
Scroll to Top