Home > Software engineering >  How To Remove XMLNS reference from top of Transformer XML Document
How To Remove XMLNS reference from top of Transformer XML Document

Time:03-25

Not sure how to tackle this problem, I have an XML document post transformation from XSLT.

There is a requirement to remove the whole string of text xmlns="urn....... from within the Document Tag.

Any help or suggestions would be appreciated.

enter image description here

Many Thank,

CodePudding user response:

You misinterpret the nature of your requirement. The namespace declaration puts all the elements (more precisely, all elements that do not have an overriding namespace declaration in scope) in the XML document in a namespace. In order to remove it, you must in effect rename all these elements to their local name.

Assuming there are no elements in other namespaces (and also no comments or processing instructions that need to be preserved), you could do it this way:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*">
    <xsl:element name="{local-name()}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>
  • Related