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

XSLT Help !

Hello,
I have a XML like this below:

*****************
<?xml version="1.0"?>
<root>
<row id="1" fname="Dan" lname="Wahlin"/>
<row id="2" fname="Heedy" lname="Wahlin"/>
<row id="3" fname="Danny" lname="Wahlin"/>
<row id="4" fname="Jeffery" lname="Wahlin"/>
</root>
********************

and I need it to be converted to this format.

****************
<?xml version="1.0"?>
<root>
<row>
<id>1</id>
<fname>Dan</fname>
<lname>Wahlin</lname>
</row>
<row>
<id>2</id>
<fname>Heedy</fname>
<lname>Wahlin</lname>
</row>
<row>
<id>3</id>
<fname>Danny</fname>
<lname>Wahlin</lname>
</row>
<row>
<id>4</id>
<fname>Jeffery</fname>
<lname>Wahlin</lname>
</row>
</root>
*********************

Can someone give a XSLT to do this?.

Thanks for your help.

Jun 8 '06 #1
2 1201


Ganesh Muthuvelu wrote:
<root>
<row id="1" fname="Dan" lname="Wahlin"/>
and I need it to be converted to this format.
<root>
<row>
<id>1</id>
<fname>Dan</fname>
<lname>Wahlin</lname>

Here is an example stylesheet:

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

<xsl:output method="xml" indent="yes" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="row">
<xsl:copy>
<xsl:apply-templates select="@*" mode="to-element" />
</xsl:copy>
</xsl:template>

<xsl:template match="@*" mode="to-element">
<xsl:element name="{name()}"><xsl:value-of select="." /></xsl:element>
</xsl:template>

</xsl:stylesheet>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 8 '06 #2
* Ganesh Muthuvelu wrote:
Hello,
I have a XML like this below:

*****************
<?xml version="1.0"?>
<root>
<row id="1" fname="Dan" lname="Wahlin"/>
<row id="2" fname="Heedy" lname="Wahlin"/>
<row id="3" fname="Danny" lname="Wahlin"/>
<row id="4" fname="Jeffery" lname="Wahlin"/>
</root>
********************

and I need it to be converted to this format.

****************
<?xml version="1.0"?>
<root>
<row>
<id>1</id>
<fname>Dan</fname>
<lname>Wahlin</lname>
</row> (snip)
</root>
*********************


You just need to iterate through the xpath expression "/root/row" in an
XSL for-each construct and for each attribute of the context element,
create a set of elements in the output XML. Nothing complicated is
required google holds the key.

Flibble
Jun 9 '06 #3

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...
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...
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...
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.