Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove namespace from the output xml?

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

like image 468
user475464 Avatar asked Feb 19 '12 19:02

user475464


People also ask

How to remove namespace from XML element in java?

The removeAttributeNS() method removes an attribute specified by namespace and name.

How to remove namespace from XML in XSLT?

The XSLTRANSFORM command converts the XML document using the first XSLT stylesheet and returns the following XML with all the namespace information removed.

How do I remove namespace prefix?

Once a namespace prefix is created, it cannot be changed or deleted. The workaround is to move all your code to a new Developer Organization, where you can setup the desired Namespace Prefix.


1 Answers

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">
like image 84
Siva Charan Avatar answered Oct 20 '22 13:10

Siva Charan