|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: apples into baskets
> 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
|
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
|

Cart








