Subject: Re: Building a calendar From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 01 Sep 1999 12:50:36 -0400 |
I'd like to build a calendar, a table really, by processing a set of events. My
mind keeps on thinking of loops, which I'm pretty sure XSLT lacks. Outside of
iteratively building the calendar within my stylesheet and checking for events
on each day, I can't think of a good way of tranforming few events into many
table cells. Hmm.
I have looked at Oren Ben-Kiki's queens.xsl to see if I could find any other ideas. I see that he uses recursion to build his tables.
T:\lander>type test.xml <?xml version="1.0"?> <CALENDAR> <MONTH start="4" end="30"> <!-- start is the day of the week that the month starts. Wednesday in this case --> <EVENT date="4"> <PARA>Some event description</PARA> </EVENT> <EVENT date="24"> <PARA>another event description</PARA> </EVENT> <!--Lots of time for vacation this month! --> </MONTH> <MONTH start="6" end="31"> <EVENT date="5"> <PARA>Some event description</PARA> <PARA>Second para of description</PARA> </EVENT> <EVENT date="17"> <PARA>first event description</PARA> </EVENT> <EVENT date="17"> <PARA>second event description</PARA> </EVENT> </MONTH> <!--May be more MONTHs --> </CALENDAR> T:\lander>type test.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="/"> <!--root rule--> <xsl:apply-templates select="CALENDAR"/> <!--restrict instances--> </xsl:template>
<xsl:template match="CALENDAR"> <!--each month belongs in a table--> <html> <xsl:for-each select="MONTH"> <table border="1" valign="top"> <xsl:call-template name="doweek"> <xsl:with-param name="start" select="@start - 1"/> <xsl:with-param name="end" select="@end"/> </xsl:call-template> </table> </xsl:for-each> </html> </xsl:template>
<xsl:template name="doweek"> <!--each week belongs in a row--> <xsl:param name="start" select="0"/> <xsl:param name="end"/> <xsl:param name="day" select="1"/> <xsl:if test="$day <= $end"> <tr valign="top"> <xsl:call-template name="doday"> <xsl:with-param name="day" select="$day"/> <xsl:with-param name="start" select="$start"/> <xsl:with-param name="end" select="$end"/> </xsl:call-template> </tr> <xsl:call-template name="doweek"> <xsl:with-param name="day" select="$day+7-$start"/> <xsl:with-param name="end" select="$end"/> </xsl:call-template> </xsl:if> </xsl:template>
<xsl:template name="doday"> <!--each day belongs in a column--> <xsl:param name="start" select="0"/> <!--only def'd first time--> <xsl:param name="end"/> <xsl:param name="day"/> <xsl:param name="weekday" select="7"/> <xsl:choose> <xsl:when test="$start>0"> <!--not started days yet--> <td> </td> <xsl:call-template name="doday"> <xsl:with-param name="start" select="$start - 1"/> <xsl:with-param name="end" select="$end"/> <xsl:with-param name="day" select="$day"/> <xsl:with-param name="weekday" select="$weekday - 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <!--a typical day of the week--> <td> <b><xsl:value-of select="substring('SFTWTMS', $weekday, 1)" /><xsl:text> </xsl:text><xsl:value-of select="$day"/>:</b><br/> <xsl:for-each select=".//EVENT[@date=$day]"> <p><i><xsl:value-of select="position()"/>: </i> <xsl:value-of select="PARA[1]"/></p> <xsl:for-each select="PARA[position()>1]"> <p><xsl:value-of select="."/></p> </xsl:for-each> </xsl:for-each> </td> <xsl:if test="$weekday > 1 and $day < $end"> <xsl:call-template name="doday"> <xsl:with-param name="end" select="$end"/> <xsl:with-param name="day" select="$day+1"/> <xsl:with-param name="weekday" select="$weekday - 1"/> </xsl:call-template> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template>
T:\lander>call xsl test.xml test.xsl test.htm T:\lander>dir test.htm
Volume in drive T has no label Volume Serial Number is 3550-B22A Directory of T:\lander
TEST HTM 2 554 99-09-01 12:49 test.htm 1 file(s) 2 554 bytes 0 dir(s) 196 673 536 bytes free
-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Website: XSL/XML/DSSSL/SGML services, training, libraries, products. Practical Transformation Using XSLT and XPath ISBN 1-894049-01-2 Next instructor-led training: MT'99 1999-12-05/06
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Building a calendar, Richard Lander | Thread | Re: Building a calendar, Richard Lander |
Re: XT Question -- Output always eq, Garriss James | Date | RE: selecting similar nodes, Kay Michael |
Month |