Take a look at the following code samples:
There are three default levels of priority assigned to patterns in templates.
- Patterns that match a class of nodes (e.g., *) in any namespace have a default priority of -0.5.
- Patterns that match a class of nodes in a specific namespace (e.g., cw:*) have a default priority of -0.25.
- Patterns that match a node name (e.g., firstname) have a default priority of 0.
- Patterns that match a node according to its context (e.g., firstname[following-sibling::lastname] and name/firstname) have a default priority of 0.5.
Only the template with the highest priority will be matched. But what happens if a node matches two templates with the same priority. Compare the following two examples.
Priorities can be explicitly assigned to templates using the priority attribute. By assigning a priority higher than .5 (e.g., 1), you ensure that the template in question will take precedence over any template that does not include an explicitly-defined priority. The example below illustrates this.