Steve,
I have solved this puzzle.
I have the following xml file :
<?xml version="1.0"?>
<Root>
<a>
<b>
<c>
<d>sundar</d>
<e>
<f>fff</f>
</e>
</c>
<d>sundar2</d>
</b>
</a>
<a>
<b>
<d>sundar3</d>
</b>
</a>
<d>sundar4</d>
</Root>
I am trying to group all the <d> elements separately and rest of the
document will be same.
<d> elements will be grouped under <D> element.
This is the stylesheet which does that:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="/Root">
<Root>
<xsl:apply-templates select="*[name(.)!='d']"/>
<D>
<xsl:apply-templates select="//d"/>
</D>
</Root>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name(.)}">
<xsl:value-of select="text()"/>
<xsl:apply-templates select="*[name(.)!='d']"/>
</xsl:element>
</xsl:template>
<xsl:template match="d">
<d>
<xsl:value-of select="text()"/>
</d>
</xsl:template>
</xsl:stylesheet>
Hope this helps you.
sundar
-----Original Message-----
From: Steven Curry [mailto:scurry1(_at_)msn(_dot_)com]
Sent: Friday, May 09, 2003 7:44 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] xslt: Wrapping multiple elements in a parent element
I need to do an xml to xml transformation where I take 1 or more elements of
a certain name (they are grouped together somewhere in the hierarchy) and
wrap them in a new parent element. The rest of the document should stay the
same. Any xslt suggestions? I'm sure there is any easy solution but I
haven't found it yet.
Thanks,
Steve
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list