cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Lanch <p...@aldigital.co.uk>
Subject Re: Best approach to display calendar
Date Tue, 29 Feb 2000 19:49:44 GMT
Steve Belt wrote:
> 
> I am trying to use Cocoon to display a calendar using an XML provided by my
> database. I would like to display the events, in HTML, formatted as you see
> in most scheduling applications (Table listing all hours of the day, then
> showing events, if any, in the adjoining cell). I can create an XSL which
> will create a table row for each event, however, I do not know how I can
> display hours and cells which have no events to them. The XSL examples I can
> find, in a manner of speaking, are "triggered" by elements in the XML; I, on
> the other hand, need to display tags
> 
> As I read through the documentation on Cocoon, I see several possible
> choices:
> 
>  I could manipulate my XML to match my calendar - ie, include nodes for
> hours that do not have events. However, this makes my XML less generic.

just so.

> I could use XSP to manipulate the original XML to insert the empty nodes,
> but I am not fluent in XSP, and am having trouble seeing how to do this.

me too - but i don't know much about XSP.

> Finally, perhaps this can all be handled by the XSL. However, as you can no
> doubt tell, I still have much to learn, and I cannot find any examples which
> show me how to accomplish this. Also, I want to be able to change my time
> intervals - ie 1-cell/hour, or 1-cell/half-hour, etc

i'd do it this way.

to "iterate" over 0 to 23 hrs (or 9 to 17 ...) when not all those
numbers are in the source doc, XSL has to use a tail-recursive named
template.  when the <event>s are children of the current node, you can
say-

<xsl:call-template name="calendar"/>

-to call something like this template-

<xsl:template name="calendar">
  <!-- declare "iterator": -->
  <xsl:param name="hour" select="0"/>
  <!-- do this row: -->
  <tr>
    <td><xsl:value-of select="$hour"/> hrs</td>
    <td><xsl:apply-templates select="event[time/hour = $hour]"/></td>
  </tr>
  <!-- if not finished, recurse: -->
  <xsl:if test="$hour &lt; 23>
    <xsl:call-template name="calendar">
      <xsl:with-param name="hour" select="$hour + 1"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

-and that calls an <xsl:template match="event"> when an event with the
right time is found - assuming <event>s contain <time>s which contain
<hour>s.

half hours, etc are more difficult; something with minute & interval
params would do it ...

you may find the XSL FAQ - http://freespace.virgin.net/b.pawson/ -
helpful if you haven't seen it, though afaik it doesn't cover exactly
this question.

-- 

cheers

phil

"I have remarked very clearly that I am often of one opinion
when I am lying down and of another when I am standing up ..."

Mime
View raw message