-
Notifications
You must be signed in to change notification settings - Fork 34
Description
XSLT Cannot Extract Namespaced Attributes (xslt-processor 3.4.0)
Summary
XSLT transformations cannot extract values from namespaced attributes in XML documents. All standard XPath methods for selecting namespaced attributes return empty strings.
Environment
- Package: xslt-processor
- Version: 3.4.0 (latest as of 2025-11-13)
- Node.js: v24.10.0
- Platform: Linux / WSL2
Minimal Reproducible Example
import xsltProcessor from 'xslt-processor';
const { XmlParser, Xslt } = xsltProcessor;
// Minimal XML with namespaced attribute
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:ns="http://example.com/namespace">
<element ns:attribute="TestValue" />
</root>`;
// XSLT attempting to extract namespaced attribute
const xslt = `<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://example.com/namespace">
<xsl:output method="text"/>
<xsl:template match="/root/element">
<xsl:text>Method 1 (@ns:attribute): </xsl:text>
<xsl:value-of select="@ns:attribute"/>
<xsl:text> </xsl:text>
<xsl:text>Method 2 (local-name): </xsl:text>
<xsl:value-of select="@*[local-name()='attribute']"/>
<xsl:text> </xsl:text>
<xsl:text>Method 3 (namespace-uri): </xsl:text>
<xsl:value-of select="@*[local-name()='attribute' and namespace-uri()='http://example.com/namespace']"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>`;
const xmlDoc = new XmlParser().xmlParse(xml);
const xsltDoc = new XmlParser().xmlParse(xslt);
const processor = new Xslt();
const result = await processor.xsltProcess(xmlDoc, xsltDoc);
console.log(result);
// Output: (completely empty - all three methods return nothing)Expected Output
Method 1 (@ns:attribute): TestValue
Method 2 (local-name): TestValue
Method 3 (namespace-uri): TestValue
Actual Output
(empty output - all methods return empty strings)
Tested Methods
All standard XPath methods for selecting namespaced attributes fail:
- Direct namespace prefix:
@ns:attribute- ❌ Returns empty - local-name():
@*[local-name()='attribute']- ❌ Returns empty - namespace-uri():
@*[local-name()='attribute' and namespace-uri()='...']- ❌ Returns empty
Real-World Impact
This limitation makes xslt-processor unsuitable for processing XML documents with namespaced attributes, which is common in:
- SAP ADT (ABAP Development Tools) XML responses
- SOAP/XML Web Services
- Atom feeds
- Many enterprise XML formats
Workaround
Use alternative XSLT processors that properly support namespaces:
- Saxon-JS (2.7.0) - Full XSLT 3.0 support, handles namespaces correctly
- Server-side processors - libxslt, Saxon, Xalan
Files to Reproduce
Complete minimal example available at:
minimal-example.mjs- Runnable test casepackage.json- Dependencies
To reproduce:
npm install
npm testRelated Issues
This appears to be a fundamental limitation in the XPath attribute selection implementation, not a configuration issue. The issue exists in both version 1.x and 3.x (latest).
Question
Is namespace-aware attribute selection intended to be supported in xslt-processor? If not, it would be helpful to document this limitation explicitly to help users choose appropriate alternatives for namespace-heavy XML processing.