0

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,

Tricky9132
  • 29
  • 7
  • This tag is the namespace of your document. Have a look at this answer : https://stackoverflow.com/questions/857010/xsl-avoid-exporting-namespace-definitions-to-resulting-xml-documents – Sebastien Mar 24 '22 at 12:40
  • Please post a [mcve] not pictures of snippets of code. – michael.hor257k Mar 24 '22 at 12:49

1 Answers1

1

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>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Yep. And renaming things means that the programs which read them will no longer understand them correctly. Ask whoever gave you this assignment to explain what they are trying to do, because "removing the namespace" is almost certainly not it. – keshlam Mar 24 '22 at 17:11