How to remove namespace from the output xml?

user475464 picture user475464 · Feb 19, 2012 · Viewed 28.5k times · Source

Below is my xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ms="http://www.test.com/schemas/test" 
xmlns:ns="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms ns">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<XMLResponse>           
    <xsl:apply-templates select="ms:ProductRS/ms:Product"/>
</XMLResponse>
</xsl:template>
<-- some templates here -->
</xsl:stylesheet>

In the output i getting like below

<?xml version="1.0" encoding="UTF-16"?>
<XMLResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Product>-----</Product>
</XMLResponse>

I need to remove xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" from the xml output

Answer

Siva Charan picture Siva Charan · Feb 19, 2012

To exclude a namespace then you should represent this way:-

exclude-result-prefixes="ms ns xsi"

Basically your stylesheet looks like this:-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ms="http://www.test.com/schemas/test" 
xmlns:ns="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms ns xsi">