19

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

Alain BECKER
  • 787
  • 5
  • 15
user475464
  • 1,741
  • 10
  • 26
  • 38
  • What environment are you working in, and is the only reference to the xsi namespace in that XMLResponse line? – Joachim Isaksson Feb 19 '12 at 19:28
  • Why do you need to remove that namespace? Why do you want to? – John Saunders Feb 19 '12 at 19:47
  • @JohnSaunders I often find that the recipient system just cannot deal with namespace definitions in the XML. We have no control over the recipient system code. Sometimes the recipient can deal with expected namespaces, but not namespaces which were part of the original XSLT (e.g. xmlns:fn ... xpath-functions) but serve no purpose outside the XSLT. – lafual Jul 07 '21 at 08:56
  • @lafual See the accepted answer for how to omit namespaces. – John Saunders Jul 09 '21 at 01:18

1 Answers1

49

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">
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • 1
    Alternatively, if the xsi prefix is not used anywhere in the stylesheet, and not wanted in the output, then just remove the declaration. – Michael Kay Feb 19 '12 at 22:45
  • 1
    But on "copy-of" it's not work( On each copy-of needs to supply copy-namespaces="no", but I try to find best approach... – antoniOS May 26 '20 at 06:43