Skip to content

Instantly share code, notes, and snippets.

@francisluong
Created June 29, 2014 19:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save francisluong/b43e922b1a6d003bf1ea to your computer and use it in GitHub Desktop.
Save francisluong/b43e922b1a6d003bf1ea to your computer and use it in GitHub Desktop.
XSLT to Remove Namespaces
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<!-- stylesheet to remove all namespaces from a document -->
<!-- note: this will lead to attribute name clash if an element contains two attributes with same local name but different namespace prefix -->
<!-- template to copy elements -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<!-- template to copy attributes -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!-- template to copy the rest of the nodes -->
<xsl:template match="/|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment