I have a 150 MB (it can go even more sometimes) XML file. I need to remove all the namespaces.
It’s on Visual Basic 6.0, so I’m using DOM to load the XML. Loading is okay, I was skeptical at first, but somehow that part works fine.
I am trying the following XSLT, but it removes all the other attributes also. I want to keep all the attributes and elements, I just need to remove the namespaces. Apparently it’s because I have xsl:element but not attribute. How can I include the attributes there?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" />
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Your XSLT removes attributes also, because you don’t have a template that would copy them.
<xsl:template match="*">matches only elements, not attributes (or text, comments or processing instructions).Below is a stylesheet that removes all namespace definitions from the processed document but copies all other nodes and values: elements, attributes, comments, text and processing instructions. Please pay attention to 2 things
<xsl:attribute>element.…and the code:
You could also use
<xsl:template match="node()">instead of that last template but then you should usepriorityattribute to prevent elements matching to this template.