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

RE: combining the children of similar nodes under one

Subject: RE: combining the children of similar nodes under one node
From: "Jim Fuller" <jim.fuller@xxxxxxxxxxxxxx>
Date: Sun, 7 Mar 2004 18:04:10 -0000
xsl all nodes under
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> David Montalvo
> Sent: 07 March 2004 00:12
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  combining the children of similar nodes under one node
> 
> 
> in the following example code, notice that all three nodes have the 
> same name. I want to combine all nodes with the same name 
> into one node 
> with all of their <style>s and <types>s, where <style> and <type> are 
> not duplicated.
> 


You could do something like


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method = "xml"/>
	
	<xsl:template match="/">	

  <xsl:variable name="list"
select="/inventory/product/node()[not(.=following::product/node())]" />

 
 	<product>
 		<xsl:copy-of select="$list"/>
	</product>

	</xsl:template>
	
</xsl:stylesheet>

Gl, Jim Fuller

> <inventory>
> 	<product>
> 		<name>chair</name>
> 		<style>rocking</style>
> 	</product>
> 
> 	<product>
> 		<name>chair</name>
> 		<type>rocking</type> --> same value as <style> above
> 	</product>
> 	<product>
> 		<name>chair</name>
> 		<style>folding</style>
> 		<type>lawn</type>
> 	</product>
> </inventory>
> 
> When I'm in the first node, I grab it, when I'm in the second node, I 
> can check the preceding <style> value and skip it, when I'm in the 
> third node I grab it. That gives me:
> 
> 	<product>
> 		<name>chair</name>
> 		<style>rocking</style>
> 	</product>
> 	<product>
> 		<name>chair</name>
> 		<style>folding</style>
> 		<type>lawn</type>
> 	</product>
> 
> I figured out that, while in the second of these nodes, I can 
> check if 
> the preceding name is the same and, if so, get the preceding <style> 
> and add it to the second product node, giving me:
> 
> 	<product>
> 		<name>chair</name>
> 		<style>rocking</style>
> 	</product>
> 	<product>
> 		<name>chair</name>
> 		<style>rocking</style>
> 		<style>folding</style>
> 		<type>lawn</type>
> 	</product>
> 
> but I still have 2 products with the name "chair". how can I get the 
> result:
> 
> 	<product>
> 		<name>chair</name>
> 		<style>rocking</style>
> 		<style>folding</style>
> 		<type>lawn</type>
> 	</product>
> 
> One of the problems is that <style> and <type> are being used 
> interchangeably, but I think I compensated for that. My big 
> problem is 
> getting everything listed under one name with no duplicates.
> 
> -dave
> 
> 
> 
> 
>  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.