Created
June 29, 2014 19:16
-
-
Save francisluong/b43e922b1a6d003bf1ea to your computer and use it in GitHub Desktop.
XSLT to Remove Namespaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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