XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Suriya SimsuwatSubject: Copy element without namespace
Author: Suriya Simsuwat
Date: 11 Jan 2008 02:59 AM
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>

Postnext
Ramon AldanaSubject: Copy element without namespace
Author: Ramon Aldana
Date: 11 Jan 2008 03:50 AM
I use this.

<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

Postnext
Suriya SimsuwatSubject: Copy element without namespace
Author: Suriya Simsuwat
Date: 11 Jan 2008 04:09 AM
Thanks Ramon. Although I tried the code below, it still did not work for my case. I still got the same result as before.

<?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:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<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>

Postnext
Alberto MassariSubject: Copy element without namespace
Author: Alberto Massari
Date: 11 Jan 2008 09:41 AM
You are not building an output "without namespace", you are writing it in the same namespace of the input.
You should add a xmlns="...." declaration to your XSLT stylesheet, so that gapi ends up in the correct namespace.

Alberto

Posttop
James DurningSubject: Copy element without namespace
Author: James Durning
Date: 14 Jan 2008 03:09 PM
For reference for anyone searching this forum:

In your stylesheet node add the following: exclude-result-prefixes="t"
Change your recursive template to use apply-templates instead of copy-of, except for attributes which you still copy.
Declare elements dynamically, using <xsl:element> and local-name() function encased in braces.
Code: ( xml )
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.