XSLT Error Reference

XTRE0540

All versions XSLT recoverable error
Error message
Ambiguous rule match for /root/item[1]

Two or more templates match the same node with equal priority. Saxon warns (or errors in strict mode) and picks the last one declared — make the intent explicit.

What it means

During xsl:apply-templates, a node matched two templates with the same import precedence and priority. The spec calls this a recoverable error: processors may pick the template that appears last in the stylesheet and continue — Saxon does that and prints XTRE0540 as a warning by default.

Common causes

  1. Overlapping patterns with equal default priority — e.g. match="item" in two included files.
  2. Copy-pasted templates left behind after refactoring.
  3. A generic and a specific pattern that compute the same priority — default priorities are subtle (item = 0, ns:item = 0, * = −0.5, patterns with predicates = 0.5).

How to fix it

Make the choice explicit instead of relying on declaration order:

  • Add an explicit priority: <xsl:template match="item" priority="2">.
  • Use modes to separate concerns: <xsl:template match="item" mode="summary">.
  • Delete the leftover duplicate if it is dead code.
  • To find which templates collide, run with tracing in XSLT Playground — the trace shows which template fired for each node. See also template matching explained.