I have looked for this specific case, but have not found. I have this XML, that has other elements besides those three, but they are irrelevant. Relevant elements have two namespaces attached to it. I want to remove xmlns:two so in the output only first xmlns is present.
<?xml version="1.0" encoding="UTF-8"?>
<Header>
<one:id xmlns:one="http://x.com/xsd/so"
xmlns:two="http://x.com/xsd/woa.xsd">555</one:id>
<one:protocolVersion xmlns:one="http://x.com/xsd/so"
xmlns:two="http://x.com/xsd/woa.xsd">2.0</one:protocolVersion>
<one:userId xmlns:one="http://x.com/xsd/so"
xmlns:two="http://x.com/xsd/woa.xsd">12345</one:userId>
</Header>
Now what I want, is to remove xmlns:two
<?xml version="1.0" encoding="UTF-8"?>
<Header>
<one:id xmlns:one="http://x.com/xsd/so">555</one:id>
<one:protocolVersion xmlns:one="http://x.com/xsd/so">2.0</one:protocolVersion>
<one:userId xmlns:one="http://x.com/xsd/so">12345</one:userId>
</Header>
I have tried something like this, but it removes wrong namespace. It removes same namespace that is prefix.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:two="http://x.com/xsd/woa.xsd"
xmlns:one="http://x.com/xsd/so">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="one:id">
<xsl:element name="{local-name()}">
<xsl:copy-of select="namespace::*[not(. = namespace-uri(..))]"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
<one:id>tag, but a closing</xro:id>tag.