I have the following xml:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig">
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
</ds:SignedInfo>
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfoData xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
</ds:SignedInfo/>
</ds:Signature>
The problem is, while I need the first ds namespace declaration in <ds:Signature>. the following ones (in <ds:SignedInfo> and <ds:SignedInfoData>) are not required. Is there any way to remove duplicate namespace declarations using XSLT 1.0 to get this output:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig">
<ds:SignedInfo>
</ds:SignedInfo>
<ds:SignedInfo>
<ds:SignedInfoData/>
</ds:SignedInfo>
</ds:Signature>
Eliminating the duplicated namespace declarations is something that happens by just copying the input, for instance with an identity transformation http://xsltransform.net/jxDigU1/1
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With