This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Grouping Issue?
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 21 Aug 2002 10:30:21 +0100
- Subject: Re: [xsl] Grouping Issue?
- Organization: Jeni Tennison Consulting Ltd
- References: <63C4AD0365821F4291ACF76C0672FA3506EF20@piper6.piper-group.int>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Andrew Welch wrote:
> You could try this, its a bit noddy and hard coded but if you are
> sure of your data it should be ok.
>
> First, select every third <month>
>
> <xsl:template match="tripdates">
> <xsl:apply-templates select="month[position() mod 3 = 1]"/>
> </xsl:template>
>
> Output a row of that <month> and the following two <month>s
>
> <xsl:template match="month">
> <tr>
> <xsl:apply-templates select="." mode="table"/>
> <xsl:apply-templates select="following-sibling::month[1]"
> mode="table"/>
> <xsl:apply-templates select="following-sibling::month[2]"
> mode="table"/>
> </tr>
> </xsl:template>
>
> Output the <td>'s for each <month>
> <xsl:template match="month" mode="table">
> <td><xsl:value-of select="."/></td>
> </xsl:template>
>
> It wouldnt be very hard to use a variable instead of hard coded
> value's - you would just need to modify the unmoded month template,
> probably with a call to a named template that would recursively
> apply-templates to the following-siblings. If you get stuck I can
> show you that.
It's not even that hard. Just apply templates to the following
siblings whose position() is less than $cols:
<xsl:variable name="cols" select="3" />
<xsl:template match="tripdates">
<xsl:apply-templates select="month[position() mod $cols = 1]"/>
</xsl:template>
<xsl:template match="month">
<tr>
<xsl:apply-templates mode="table"
select=". | following-sibling::month[position() < $cols]" />
</tr>
</xsl:template>
<xsl:template match="month" mode="table">
<td><xsl:value-of select="."/></td>
</xsl:template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list