« XML is Ten! | Main | Reading only headers in an File/FTP Adapter and skipping the payload »

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.






  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  2. exclude-result-prefixes="xsl">  
  3.   
  4.  <xsl:template match="*">  
  5.     <xsl:element name="{local-name()}">  
  6.       <xsl:apply-templates select="@* | node()"/>  
  7.     </xsl:element>  
  8.   </xsl:template>  
  9.   <xsl:template match="@* | text()">  
  10.     <xsl:copy/>  
  11.   </xsl:template>  
  12. </xsl:stylesheet>

Comments (2)

Hany Harraz:

what if I want to change a namspace
lets say that what I have is
< soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q0="http://address" >
< soapenv:Body>
< q0:findByLocation>
< city/>
< state>NC< /state>
< /q0:findByLocation>
< /soapenv:Body>
< /soapenv:Envelope>

and I want to change namespace q0 to be "http://east.address"

then how do i do that?

n gunaran:

hany harraz,
I'm looking for a solution for a similar problem did you find a solution if so please share it.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on March 6, 2008 7:18 PM.

The previous post in this blog was XML is Ten!.

The next post in this blog is Reading only headers in an File/FTP Adapter and skipping the payload.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle