This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Grouping with XSLT
- To: "Michael Geiling" <mgeiling at web dot de>
- Subject: Re: [xsl] Grouping with XSLT
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Wed, 31 Oct 2001 19:00:38 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <200110311507.f9VF7Hu23438@mailgate5.cinetic.de>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Michael,
> and need to generate some sort of table (diary style) where I list
> the hours from 9-5 in a style like
> 9:00
> 9:15
> 9:30
> 9:45
> 10:00
> ...
Since you can never predict which hours are going to actually be
involved in an activity, I think you'd be safer generating these times
using a recursive template. To create a heading for every hour, you
could use something like:
<xsl:template name="createDiary">
<xsl:param name="hour" select="9" />
<h2><xsl:value-of select="format-number($hour, '00')" />:00</h2>
...
<xsl:if test="$hour < 18">
<xsl:call-template name="createDiary">
<xsl:with-param name="hour" select="$hour + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Since you're searching the date elements time and time again, it's
probably best to set up a key that indexes each date element by its
starth, as follows:
<xsl:key name="dates" match="date" use="number(starth)" />
Then you can retrieve all the date elements with a particular start
hour with:
key('dates', $hour)
and iterate over them within the createDiary template, as follows:
<xsl:template name="createDiary">
<xsl:param name="hour" select="9" />
<h2><xsl:value-of select="format-number($hour, '00')" />:00</h2>
<xsl:for-each select="key('dates', $hour)">
<xsl:sort select="startm" data-type="number" />
<p>
Start: <xsl:value-of select="concat(starth, ':', startm)" />,
<xsl:value-of select="activity" />
</p>
</xsl:for-each>
<xsl:if test="$hour < 18">
<xsl:call-template name="createDiary">
<xsl:with-param name="hour" select="$hour + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list