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

Re: Grouping with XSLT

Subject: Re: Grouping with XSLT
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 31 Oct 2001 19:00:38 +0000
xslt for each hours
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 &lt; 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 &lt; 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


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.