XSLT Error Reference
XPST0081
Namespace prefix 'x' has not been declaredAn XPath expression uses a namespace prefix that is not declared in the stylesheet. Declaring the prefix on xsl:stylesheet fixes it.
What it means
An XPath expression (in select, match, test…) uses a prefix like soap: or ns0: that the stylesheet never binds to a namespace URI. Prefixes are resolved in the stylesheet, not in the source document — it does not matter that the input XML declares them.
Common causes
- The prefix is only declared in the source XML. The stylesheet needs its own
xmlns:soap="…"declaration even if the input already has one. - Typo or renamed prefix —
select="soapenv:Body"while the stylesheet declaresxmlns:soap. - Copy-pasted XPath from another stylesheet that declared different prefixes.
How to fix it
Declare the prefix on the root element of the stylesheet with the same URI used in the source document (the prefix text itself may differ; the URI is what matters):
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:template match="/soap:Envelope/soap:Body">
…
</xsl:template>
</xsl:stylesheet>
For elements in a default namespace (no prefix in the source), you still need a prefix in XPath 1.0/2.0 — bind any prefix to that URI and use it (xmlns:d="urn:default-ns" → d:root/d:item). In XSLT 3.0 you can use xpath-default-namespace="urn:default-ns" instead.