<html>
<head>
<title>A Document</title>
</head>
<body>
<p>This is a <i>test</i>.
<i>Nested <b>emphasis</b></i>.</p>
</body>
</html>
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, XSLT processors 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.
Changing the Template Set
Now we have an algorithm for selecting exactly which pattern
matches, but what happens if the same elements must be processed in multiple
contexts? This happens, for example, when dealing with cross references, automatic
tables of contents, and multiple views of the same data.
<h2>Chapter Title</h2>
<p>This chapter is self-referential:
<i>Chapter Title</i>.</p>
The chapter title must be processed twice, once to produce the title
and once to produce the cross reference.
There is no dynamic mechanism for adjusting template priority, but there
is a mechanism for selecting specific sets of templates. That mechanism is
called "modes".
The other model for applying style is to select each action procedurally.
A series of templates is created, such that each template explicitly selects
and processes the necessary elements.