Subject: Re: Splitting data into smaller groups for HTML output.
From: Mike Rumble <mike.rumble@xxxxxxxxx>
Date: Mon, 31 Oct 2005 19:03:14 +0000
|
Thanks Wendell,
The way I'm looking to split the items into groups is as follows.
1 to 5 items - 1 group
6 to 10 items - 2 groups
11 to 15 items - 3 groups
16 - 20 items - 4 groups
21 - 25 items - 5 groups
So the number of groups will in fact depend on the number of <source>
nodes in the XML file. The <source> nodes will are already in the
correct order in the XML file so I don't need to sort them in any
other way in the XSL.
Cheers,
Mike.
On 10/31/05, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote:
> Mike,
>
> The one thing you don't say is by what rule you would like the
> splitting to occur (you only say "into two or more groups").
>
> If you wanted to split into exactly two groups, you could do:
>
> <xsl:template match="sources">
> <div>
> <xsl:apply-templates
> select="source[position() <= (last() div 2)"/>
> </div>
> <div>
> <xsl:apply-templates
> select="source[position() > (last() div 2)"/>
> </div>
> </xsl:template>
>
> Notice if you have an odd number of source element children, the
> first group will be short one item.
>
> There are other methods available for grouping them differently and
> even according to data-driven criteria, for example if you need to
> determine dynamically how many groups you want.
|