Why doesn’t copy-namespaces=”no” remove a namespace declaration that’s not referenced in the XSLT’s output document? I’m using the MarkLogic 5 XSLT processor.
Sample input
<root xmlns:temp="http://temp" xmlns:keep="http://keep">
<wrapper><temp:x>A</temp:x>BC<temp:x>D</temp:x></wrapper>
<keep:me>XYZ</keep:me>
</root>
Sample XSL
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:temp="http://temp"
xmlns:keep="http://keep"
exclude-result-prefixes="#all">
<xsl:template match="node()|@*" priority="-1" mode="#all">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="temp:x">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Expected output
<root xmlns:keep="http://keep">
<wrapper>ABCD</wrapper>
<keep:me>XYZ</keep:me>
</root>
Actual output
<root xmlns:temp="http://temp" xmlns:keep="http://keep">
<wrapper>ABCD</wrapper>
<keep:me>XYZ</keep:me>
</root>
I confirmed with MarkLogic support that this is a bug, and they are working on a fix.
In the meantime, I am using these templates in place of the identity template as a workaround: