XSLT guide
Make XSLT match a default namespace
Fix XSLT templates that never fire when source elements use a default namespace, with patterns that work across XSLT versions.
7 min read · Updated 2026-08-21
The short answer
Unprefixed names in XSLT 1.0 match elements in no namespace, so they do not match source elements placed in a default namespace. Bind the source namespace to a stylesheet prefix and use it in match and select patterns. In XSLT 2.0 or 3.0, xpath-default-namespace can make unprefixed XPath element names target one chosen namespace, but an explicit prefix remains clearer when several vocabularies coexist.Name the source vocabulary explicitly
The stylesheet's default namespace controls literal result elements; it does not automatically become the namespace used by XPath names. Bind the source URI to a prefix even if the input document uses no prefix at all.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="urn:example:catalog"
exclude-result-prefixes="s">
<xsl:template match="s:catalog">
<ul><xsl:apply-templates select="s:item"/></ul>
</xsl:template>
<xsl:template match="s:item">
<li><xsl:value-of select="s:name"/></li>
</xsl:template>
</xsl:stylesheet>Use xpath-default-namespace deliberately
XSLT 2.0 and 3.0 allow xpath-default-namespace on stylesheet elements. It changes how unprefixed element names in XPath expressions and patterns are expanded; it does not rewrite the input or affect attribute names.
- Prefer an explicit prefix when matching SOAP, SAML, or mixed vocabularies.
- Remember that unprefixed attributes remain in no namespace.
- Use exclude-result-prefixes to avoid copying helper bindings unnecessarily.
- Test a source with the same URI under a different prefix.
Debug the selected nodes, not the output styling
Start with a template on / that prints count() for the intended selection. If the count is zero, inspect namespace URIs before changing priorities, modes, or output markup. A template cannot win conflict resolution if its pattern never matches.
Use XMLDir's XPath tester with an explicit prefix to prove the selection against the source, then copy that namespace binding into the stylesheet.
Prove the fix
- Prove the XPathConfirm the namespace-aware selection before editing template logic.
- Review match and selectSeparate template applicability from the nodes an instruction chooses.
- Inspect namespace scopeTrack expanded names across source and stylesheet prefixes.
Related guides
- Why XPath matches nothing in a default namespaceThe XPath 1.0 namespace rule behind an empty //loc result, with the prefix-bound solution and the local-name fallback.
- XSLT match vs select: know which expression runs whenDistinguish template patterns from XPath selections, trace modes and priority, and fix stylesheets that choose nodes but run the wrong rule.
- XML namespace prefix vs URIUnderstand why prefixes are replaceable aliases, why namespace URIs are compared literally, and how expanded names keep documents interoperable.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.