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 17th, 2009, 03:27 AM
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Post to remove namespace prefix form input xml using xslt

I want to remove namespace prefix form input xml using xslt

Namespace prefix "UDF" in red Color to be removed.

original Code :
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER REMOTEID="9fe354a2-e3b9-4440-93dc-2cb1f7c434a7-0000000f" VCHTYPE="Sales" ACTION="Create">
<ALLINVENTORYENTRIES.LIST>
<EXCISEALLOCATIONS.LIST>
<UDF:TRADERMFGREXCISEQTYDMK.LIST DESC="`TraderMfgrExciseQtyDMK`" ISLIST="YES" TYPE="Amount">
<UDF:TRADERMFGREXCISEQTYDMK DESC="`TraderMfgrExciseQtyDMK`">19821345.00</UDF:TRADERMFGREXCISEQTYDMK>
</UDF:TRADERMFGREXCISEQTYDMK.LIST>
</EXCISEALLOCATIONS.LIST>
</ALLINVENTORYENTRIES.LIST>
</vOUCHER>
</TALLYMESSAGE>

EXPECTED OUTPUT :
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER REMOTEID="9fe354a2-e3b9-4440-93dc-2cb1f7c434a7-0000000f" VCHTYPE="Sales" ACTION="Create">
<ALLINVENTORYENTRIES.LIST>
<EXCISEALLOCATIONS.LIST>
<TRADERMFGREXCISEQTYDMK.LIST DESC="`TraderMfgrExciseQtyDMK`" ISLIST="YES" TYPE="Amount">
<TRADERMFGREXCISEQTYDMK DESC="`TraderMfgrExciseQtyDMK`">19821345.00</TRADERMFGREXCISEQTYDMK>
</TRADERMFGREXCISEQTYDMK.LIST>
</EXCISEALLOCATIONS.LIST>
</ALLINVENTORYENTRIES.LIST>
</vOUCHER>
</TALLYMESSAGE>

I Tried this code:

<xsl:template match="*">
<xsl:element name="local-name()">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

I also tried this code
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>

But no changes in output


THANKS & REGARDS

Last edited by robin_stringss; May 17th, 2009 at 03:34 AM.. Reason: incomplete msg
 
Old May 17th, 2009, 04:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your transform is almost there but the name attribute of xsl:element expects a literal string so to use a dynamic path you need to surround it with curly braces:
Code:

<xsl:elementname="{local-name()}" >
May I ask why you need this transformation? The request to change an element by removing its namespace is ususally a sign of problems elsewhere.
__________________
Joe
http://joe.fawcett.name/
 
Old May 17th, 2009, 06:41 AM
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation

Quote:
Originally Posted by joefawcett View Post
Your transform is almost there but the name attribute of xsl:element expects a literal string so to use a dynamic path you need to surround it with curly braces:
Code:

<xsl:elementname="{local-name()}" >
May I ask why you need this transformation? The request to change an element by removing its namespace is ususally a sign of problems elsewhere.
Thanks for immediate reply friend

I tried with what you said about curly braces
But I get the same error as :
Failed to Load SourceXML to DOM: Reference to undeclared namespace prefix: 'UDF'.
Line 198, Position 96

but if I remove maually UDF: name space prefix then it works fine with my application

I require this tansformation for convertion of Voucher Type form One company to Other in Tally Software (an Accounting package)

Tanks & Regards
 
Old May 17th, 2009, 06:50 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That error message suggests a problem with the way you load the original document, not the transformation itself. Can you show a summary of your code and indicate what environment you are using?
__________________
Joe
http://joe.fawcett.name/
 
Old May 17th, 2009, 06:50 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well that error seems to come from the XML parser, no from the XSLT processor. The source XML does not seem to be namespace well-formed.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exclude a namespace with no prefix bonekrusher XSLT 6 January 23rd, 2009 08:48 AM
Remove namespace prefix from XmlBean ratzko BOOK: Professional Java Development with the Spring Framework 0 August 10th, 2008 01:23 PM
Adding Prefix and Namespace to XML Lerxt XSLT 6 November 8th, 2007 03:14 PM
How a additional prefix in a namespace comes? diang BOOK: ASP.NET Website Programming Problem-Design-Solution 0 July 13th, 2006 10:40 PM
attribute namespace prefix tsmith XSLT 1 August 12th, 2004 06:01 AM





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