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

RE: apples into baskets

Subject: RE: apples into baskets
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Fri, 2 Jun 2000 09:31:27 +0100
template of a basket
> What I am trying to do is to put fruits into baskets:
> 
> INPUT:
> 
> <basket/>
> <apples>3</apples>
> <oranges>5</oranges>
> <basket/>
> <apples>7</apples>
> <oranges>9</oranges>
> 

This falls into the broad category of grouping problems: see Dave Pawson's
FAQ. The most general solutions involve using a recursive named template to
process the list on element at a time. In this case I suspect something
along the following lines might work:

<xsl:template match="basket">
<basket>
   <xsl:apply-templates 
      select="following-sibling::*[
                 generate-id(preceding-sibling::basket[1])=
                 generate-id(current())]"/>
</basket>
</xsl:template>

In other words, for each <basket> element, process those of its
following-siblings that have that <basket> as their most recent <basket>
preceding-sibling.

It is of course horribly inefficient (order n squared) for a long list. So a
Muenchian solution using keys would be better:

<xsl:key name="bkey"
         match="apples|oranges|bananas" 
         use="generate-id(preceding-sibling::basket[1])"/>

<xsl:template match="basket">
  <xsl:apply-templates select="key('bkey', generate-id())"/>
</xsl:template>

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.