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

RE: merging unknown nodes

Subject: RE: merging unknown nodes
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Wed, 1 Nov 2000 18:15:41 -0400 (EST)
nested loops unknown
> What I want to be able to do is transform this:
> 
> <PRODUCTS>
>     <PRODUCT name="bill_product">
>         <OPTIONLIST name="fred"> <!-- The first 'fred' option list -->
>             <OPTION>fred1</OPTION>
>             <OPTION>fred2</OPTION>
>         </OPTIONLIST>
>         <OPTIONLIST name="george">
>             <OPTION>george1</OPTION>
>         </OPTIONLIST>
>     </PRODUCT>
> 
>     <PRODUCT name="bob_product">
>         <OPTIONLIST name="fred">   <!-- The second 'fred' 
> optionlist -->
>             <OPTION>fred3</OPTION>
>             <OPTION>fred4</OPTION>
>         </OPTIONLIST>
>         <OPTIONLIST name="george">
>             <OPTION>george2</OPTION>
>         </OPTIONLIST>
>     </PRODUCT>
> <PRODUCTS>
> 
> Into this:
> 
> <OPTIONLIST name="fred">	<!-- All the 'fred' 
> optionlist's merged into
> one -->
>     <OPTION>fred1</OPTION>
>     <OPTION>fred2</OPTION>
>     <OPTION>fred3</OPTION>
>     <OPTION>fred4</OPTION>
> </OPTIONLIST>

This is a classic grouping problem, you will find solutions on the FAQ
(follow the links in the mail footer) under sorting and grouping.

Grouping problems always involve two nested loops. The outer loop finds a
representative instance of each group:

xsl:for-each select="//option[not(.=preceding::option)]"

The inner loop selects the remaining members of the group

xsl:for-each select="//option[.=current()]" 

Using "//" and "preceding", is expensive, the above illustrates the most
general solution, it's better to use preceding-sibling when possible. There
are also more efficient approaches using keys: look for the "Muenchian
grouping method".

Mike Kay




 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.