473,226 Members | 1,299 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,226 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 1196


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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.