473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XSLT: how to copy element without namespace?

Hi again,

I have one more question to inquiry from you guys that if I want to want to use XSLT copying from xml containing namespace to a new xml without namespace. How can I do it. I have written XSLT for this routine, but it still did not work as what I want yet, so can anyone give me some suggestion to work through it. Thank you in advance.


Source XML file.

<?xml version="1.0"?>
<order xmlns="http://test.com/OrderAdd" name="OrderAdd">
<orderheader>
<name>Jame</name>
<surname>Cool</surname>
<product>
<id>001</id>
<name>book</name>
<qty>3</qty>
</product>
<shiptoaddress>
<name>John Good</name>
<name>IT company</name>
</shiptoaddress>
</orderheader>
</order>


Existing XSLT file.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://test.com/OrderAdd">

<xsl:template match="t:order">
<gapi>
<xsl:apply-templates/>
</gapi>
</xsl:template>

<xsl:template match="t:*">
<orderheader>
<xsl:copy-of select="@*|node()" />
</orderheader>
</xsl:template>

</xsl:stylesheet>


Current result.

<?xml version="1.0" encoding="UTF-8"?>
<gapi xmlns:t="http://test.com/OrderAdd">
<orderheader>
<name xmlns="http://test.com/OrderAdd">Jame</name>
<surname xmlns="http://test.com/OrderAdd">Cool</surname>
<product xmlns="http://test.com/OrderAdd">
<id>001</id>
<name>book</name>
<qty>3</qty>
</product>
<shiptoaddress xmlns="http://test.com/OrderAdd">
<name>John Good</name>
<name>IT company</name>
</shiptoaddress>
</orderheader>
</gapi>

how to make to the following result?

<?xml version="1.0" encoding="UTF-8"?>
<gapi xmlns="http://test.com/OrderAdd">
<orderheader>
<name>Jame</name>
<surname>Cool</surname>
<product>
<id>001</id>
<name>book</name>
<qty>3</qty>
</product>
<shiptoaddress>
<name>John Good</name>
<name>IT company</name>
</shiptoaddress>
</orderheader>
</gapi>
Jan 11 '08 #1
2 24523
jkmyoung
2,057 Expert 2GB
  1. In your stylesheet node add the following: exclude-result-prefixes="t"
  2. Change your recursive template to use apply-templates instead of copy-of, except for attributes which you still copy.
  3. Declare elements dynamically, using <xsl:element> and local-name() function encased in braces.
Expand|Select|Wrap|Line Numbers
  1. <xsl:element name="{local-name()}">
  2.     <xsl:copy-of select="@*"/>
  3.     <xsl:apply-templates/>
  4. </xsl:element>
  5.  
Jan 11 '08 #2
Thank you very much, jkmyoung.
Jan 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
1
by: PBR | last post by:
Hi, I'm trying to do some grouping on a set elements based on one of the set's child element values. That seems to work OK. My problem is that I would like to allow for additional child elements...
4
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name space. ----source---- <document xmlns="..."...
3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
5
by: Jason | last post by:
Hello, I would like to transform this; <?xml version="1.0" encoding="utf-8" ?> <ProductList> <Product> <ID>1</ID> <Name>Gadget</Name> </Product>
10
by: Andy Fish | last post by:
hi, I have an XSLT which is producing XML output. many of the nodes in the output tree contain namespace declarations for namespaces that are used in the source document even though they are...
3
by: WideBoy | last post by:
Hi, I have a software generated schema which creates a few empty elements, e.g. <xsd:sequence/>. I would like to be able to delete these elements from the schema post-generation using XSLT. ...
6
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.