Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to remove namespaces for an element coming in my output after going through transformation using XSLT 1.0.

What I had:

I am having a input XML, in which one elements schema got changed. So as per the new schema, I renamed it. Now for that particular element, I am getting an extra namespace in the output XML.

Somehow, the XSL I am using is removing all the namespaces in xml like soap envelope, soap body etc, not only for the modified element.

Why only the changed element is giving namespace error. Any suggestions on this are welcome. How to remove the namespace coming after the element renamed.

XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope>
<xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<MyRequest>
<Details>
<ID>123</ID>
<Name>
<FirstName>John</FirstName>
</Name>
</Details>
</MyRequest>
</soapenv:Body>
</soapenv:Envelope>



XSL used

XML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"             version="1.0"
xmlsns:ns = "www.newschema"
exclude-element-prefix = "xsl ns">
<xsl:template match="Details" ns=www.Newschema>
<PartyDetails ns=www.Newschema>
<xsl:apply-templates select="node()"/>
</PartyDetails
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>



Output I want.

XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope(xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/")>
<soapenv:Body>
<MyRequest>
<PartyDetails>
<ID>123</ID>
<Name>
<FirstName>John</FirstName>
</Name>
</PartyDetails>
</MyRequest>
</soapenv:Body>
</soapenv:Envelope>
Posted
Comments
John C Rayan 20-Feb-15 14:19pm    
What error do you get?
John C Rayan 20-Feb-15 14:42pm    
is it because you are missing double quotes around the ns ns=www.Newschema
John C Rayan 20-Feb-15 14:51pm    
Can you please try with ns="www.Newschema" in PartyDetails element or <ns:partydetails> and let me know
John C Rayan 25-Feb-15 5:46am    
Hi Did you try this? can you reply and let me know

1 solution

Can you please try with ns="www.Newschema" in PartyDetails element or &lt;ns:partydetails&gt; and let me know 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900