Posts

XSLT error messages explained: the 17 most common Saxon errors and how to fix each one

02 Jul 2026

A practical triage guide to XSLT and Saxon errors — XPST0017, XPTY0004, XPDY0002, 'Content is not allowed in prolog' and more: what each means and the fastest fix.

Quick answer: most XSLT failures fall into three buckets. If the error code starts with XP/XT + “S” (XPST, XTSE) the stylesheet itself is invalid and nothing ran. If it starts with XP/XT + “D” (XPDY, XTDE) the stylesheet compiled but hit a problem at runtime with your data. If the message mentions the XML parser (SAXParseException, SXXP0003), your input document is not well-formed XML — the stylesheet never even got a chance. Find your exact error below.

Triage: read the code before the message

PrefixLayerMeaning
XPST…XPath, staticExpression invalid — typo, unknown function/variable/prefix
XPTY…XPath, typeValue has wrong type or cardinality (2.0+ strictness)
XPDY…XPath, dynamicExpression valid but failed on your data/context
XTSE…XSLT, staticStylesheet structure invalid
XTDE… / XTRE…XSLT, dynamicRuntime failure / recoverable condition
FO…Function libraryA standard function rejected its input
SXXP0003 / SAXParseExceptionXML parserInput is not well-formed XML

Stylesheet won’t compile (static errors)

Runs but fails on your data (dynamic & type errors)

Function library complaints

Your input XML is broken (parser errors)

A 3-step debugging workflow

  1. Reproduce small. Paste stylesheet + input into XSLT Playground and cut the input down to the smallest fragment that still fails — Saxon errors carry exact line numbers, so shrinking the case pinpoints the culprit.
  2. Check the layer with the table above: fix stylesheet, data, or input well-formedness — they need different tools.
  3. Trace it. For logic errors that don’t raise codes at all (wrong output, empty output), enable the execution trace to see which templates fired and with what context. The debugging patterns guide covers this in depth.

Browse the full XSLT & Saxon Error Reference for every error above, each with before/after fixes you can run.