473,399 Members | 2,858 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,399 software developers and data experts.

XSLT, XML to XML

Hello,

I would like to transform this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductList>

to this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductList>

Basically I am hoping to use XslTransform and an XSLT stylesheet to change
the format of some input XML so it can be read directly into a dataset.

Any advice would be appreciated.

Cheers,

Jason
Nov 12 '05 #1
5 1268
Jason wrote:
I would like to transform this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductList>

to this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductList>


I hardly see any difference between the two...

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Nov 12 '05 #2
I'm sorry, I cut and paste the example incorrectly. I would like to
transform this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductList>

To this;

<?xml version="1.0" standalone="yes"?>
<ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductDataSet>
Nov 12 '05 #3
U need only one template in your stylesheet for this:

<xsl:template match="/ProductList">
<ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:copy-of select="." />
</ProductDataSet>
</xsl:template>

Best, Ed.

Jason wrote:
I'm sorry, I cut and paste the example incorrectly. I would like to
transform this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductList>

To this;

<?xml version="1.0" standalone="yes"?>
<ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
<Product>
<ID>1</ID>
<Name>Gadget</Name>
</Product>
</ProductDataSet>


Nov 12 '05 #4
Gomolyako Eduard wrote:
U need only one template in your stylesheet for this:

<xsl:template match="/ProductList">
<ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:copy-of select="." />
</ProductDataSet>
</xsl:template>


No, that's not enough. xsl:copy-of copies element as is and so if in
source XML an element is in no namespace, it will be in no namespace in
output, XSLT processor must emit xmlns="" to the Product element then.

Try something like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="ProductList">
<ProductList xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates select="@*|node()"/>
</ProductList>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}"
namespace="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

If in your XML there is no attributes, comments or PIs, this can be
simplified to

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="ProductList">
<ProductList xmlns="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates/>
</ProductList>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}"
namespace="http://tempuri.org/ProductDataSet.xsd">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Nov 12 '05 #5
Thanks alot for your help guys, much appreciated.

Jason
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a...
2
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now...
1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.