Stripping namespaces using XSLT
A common question often asked is "I have a namespace qualified XML document -
I need to remove all xmlns attributes from the same".
Here is an XSLT that you can use to strip all namespaces from your document.
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- exclude-result-prefixes="xsl">
-
- <xsl:template match="*">
- <xsl:element name="{local-name()}">
- <xsl:apply-templates select="@* | node()"/>
- </xsl:element>
- </xsl:template>
- <xsl:template match="@* | text()">
- <xsl:copy/>
- </xsl:template>
- </xsl:stylesheet>