[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: merging unknown nodes
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|