Re: [xsl] Grouping with XSLT

Subject: Re: [xsl] Grouping with XSLT
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 2 Nov 2001 11:15:47 +0000
Hi Michael,

> I get the table header after generating the diary. Do I
> misunderstand something in calling the template ?

I don't think so, although you're probably misunderstanding what it's
providing. Assuming that you haven't changed the template, you'll get
something like:


When you put HTML in a table element by outside a row or cell, then it
appears before the table.

> - I also want to have the actual time and activity in a table; is
> there a trick in how to put some table row generation into a
> recursive function ?

It's not particularly tricky. Rather than creating h2 elements,
generate tr elements with:

<xsl:template name="createDiary">
  <xsl:param name="hour" select="9" />
    <th><xsl:value-of select="format-number($hour, '00')" />:00</th>
  <xsl:if test="$hour &lt; 18">
    <xsl:call-template name="createDiary">
      <xsl:with-param name="hour" select="$hour + 1" />

> - for each hour I need to check if there is an activity ongoing
> where the start time is < than the actual hour; i.e. if an activity
> start at 9:15 and runs for 3 hours it should be listed in the 10:00
> and 11:00 row. Is it at all possible to use the 'key' to get the
> values of preceeding nodes for comparison ?

Well, a key can only get hold of an activity if there is a way of
assigning creating a key value for every possible value it could take.
You *could* do this with a series of keys that went:

<xsl:key name="dates" match="date" use="number(starth)" />
<xsl:key name="dates" match="date[starth + 1 &lt; endh]"
         use="starth + 1" />
<xsl:key name="dates" match="date[starth + 2 &lt; endh]"
         use="starth + 2" />

but it's likely to be a bit tedious unless the maximum gap between the
start and end hour is small. (This would be easier with user-defined
functions that would allow you to generate a node set of the possible
hours that you could use for the key value.)

Otherwise, you can get all the activities that are ongoing in a
particular hour with:

  /dates/date[starth &lt;= $hour and
              (endh > $hour or
               (endh = $hour and endm = 0))]

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread