Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2011, 02:26 AM
Registered User
 
Join Date: May 2011
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to remove namespace?

Hi Experts,

My XSLT is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:sap-com:document:sap:rfc:functions" xmlns:ns1="http://test.com/XSLT_POC">
<xslutput method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="/ns0:YTEST_SUM.Response">
<ns1:YCUST_OUTPUT><OUT>
<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>
<xsl:value-of select="SUM"/>
<xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
</OUT>
</ns1:YCUST_OUTPUT>
</xsl:template>
</xsl:stylesheet>

My input XML is:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:YTEST_SUM.Response xmlns:ns0="urn:sap-com:document:sap:rfc:functions">
<SUM>12</SUM>
</ns0:YTEST_SUM.Response>


when I use the XSLT for this input XML then the output is:

<?xml version="1.0" encoding="utf-8"?>
<ns1:YCUST_OUTPUT xmlns:ns1="http://test.com/XSLT_POC" xmlns:ns0="urn:sap-com:document:sap:rfc:functions">
<OUT><![CDATA[12]]></OUT>
</ns1:YCUST_OUTPUT>

But I want it like this:

<?xml version="1.0" encoding="utf-8"?>
<ns1:YCUST_OUTPUT xmlns:ns1="http://test.com/XSLT_POC">
<OUT><![CDATA[12]]></OUT>
</ns1:YCUST_OUTPUT>

I don't want both the namespaces in the output root element. I want only ns1.

How can I achieve this? What changes I need to do in my XSLT?

Please help!

Thanks
Gopal
 
Old May 4th, 2011, 02:34 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Firstly, you can use the exclude-result-prefixes attribute on the xsl:stylesheet element to exclude unused namespaces from the result.

Secondly, why oh why are you using all that horrible code to output a CDATA element? You don't need it. Your XML processor will handle anything you output and ensure it is either encoded or embedded in a CDATA element for you if it is required.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove Namespace from root tag using xslt namespce prefix nisargmca XSLT 0 February 24th, 2010 01:08 AM
to remove namespace prefix form input xml using xslt robin_stringss XSLT 4 May 17th, 2009 06:50 AM
Remove root namespace help? JohnBampton XSLT 2 March 6th, 2009 06:49 AM
Remove namespace prefix from XmlBean ratzko BOOK: Professional Java Development with the Spring Framework 0 August 10th, 2008 01:23 PM
Remove namespace from output file jopet25 XSLT 12 March 9th, 2007 11:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.