[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: xslt: Wrapping multiple elements in a parent eleme

Subject: RE: xslt: Wrapping multiple elements in a parent element
From: Sundar Shanmugasundaram <SSHANMUGASUNDARAM@xxxxxxxxxxxxx>
Date: Fri, 9 May 2003 11:42:06 +0530
xslt parent
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@xxxxxxx]
Sent: Friday, May 09, 2003 7:44 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.