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>
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.