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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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
(Deleted User) Subject: Copy element without namespace
Author: (Deleted User)
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>

   
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.