468,315 Members | 1,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

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 1092


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 discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.