Friday, September 12, 2008

XSLT: Remove NameSpaces

This post will guide how to strip the namespaces from qualified XML document. This is most common requirement which comes during working.

Problem: Stripping all 'xmlns' attributes from qualified XML document

Solution:
Here is an XSLT that you can use to strip all namespaces from XML 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>


Learn with me...Way to go...

No comments: