[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] How to create XSL for CALENDAR/MONTH layout?
Subject: RE: [xsl] How to create XSL for CALENDAR/MONTH layout? From: Richard Lander <rlander@xxxxxxxxxxxxx> Date: Fri, 5 Jan 2001 12:07:10 -0800 |
Hello, As an aside to your current work, I thought I'd toss in a calendar application that I built some time ago. In truth, Ken Holman wrote 99% of the XSLT about 2 years ago. He just can't seem to sit on his hands! The idea here is that you specify all information. The XSLT just builds the calendar, so you might have something like: I can't remember exactly how this worked. I believe that start is the day on which to start (sunday = 1, monday=2 ...) and that end is end date (28|29|30|31). <CALENDAR> <TITLE>Year 2001 Calendar</TITLE> <MONTH id="jan" start="2" end="31"> <TITLE>January</TITLE> <EVENT date="5"> <TITLE>The day I wrote this email</TITLE> <PARA>I hope you find this information helpful</PARA> </EVENT> </MONTH> </CALENDAR> Here's the DTD declarations: <!ELEMENT CALENDAR (TITLE?, MONTH+)> <!ELEMENT MONTH (TITLE,EVENT+)> <!ATTLIST MONTH id ID #IMPLIED start CDATA #REQUIRED end CDATA #REQUIRED> <!ELEMENT EVENT (TITLE?,PARA+)> <!ATTLIST EVENT date CDATA #REQUIRED> Here's the XSLT, which contains some other unrelated code: <?xml version='1.0' standalone='no'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="TopicList"> <xsl:call-template name="TopicList"/> </xsl:variable> <!-- Calendar --> <xsl:template match="CALENDAR"> <!--each month belongs in a table--> <PAGES path="Calendar/"> <xsl:for-each select="MONTH"> <PAGE> <xsl:call-template name="IDCatcher"/> <TITLE class="MONTHTITLE"><xsl:value-of select="TITLE"/></TITLE> <COLUMNS> <COLUMN width="20%"> <xsl:call-template name="PlaceAllTopicsList"/> </COLUMN> <COLUMN width="*"> <table border="1" width="75%" align="center"> <col width="14%"/> <tbody> <tr class="Weekday"> <td width="87" valign="top">Sunday</td><td width="87" valign="top">Monday</td><td width="87" valign="top">Tuesday</td><td width="87" valign="top">Wednesday</td> <td width="87" valign="top">Thursday</td><td width="87" valign="top">Friday</td><td width="87" valign="top">Saturday</td> </tr> <xsl:call-template name="doweek"> <xsl:with-param name="start" select="@start - 1"/> <xsl:with-param name="end" select="@end"/> </xsl:call-template> </tbody> </table> <xsl:apply-templates select="."/> <LINKLIST type="block"> <xsl:for-each select="../MONTH"> <xsl:call-template name="WEBCatcher"> <xsl:with-param name="path" select="."/> <xsl:with-param name="title" select="TITLE"/> </xsl:call-template> </xsl:for-each> </LINKLIST> </COLUMN> </COLUMNS> </PAGE> </xsl:for-each> </PAGES> </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> <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 height="87" width="87" valign="top"> </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 height="87" width="87" valign="top"> <PARA class="CDATE"><xsl:value-of select="$day"/></PARA> <!-- <b><xsl:value-of select="substring('SFTWTMS', $weekday, 1)"/><xsl:text> </xsl:text> --> <xsl:for-each select=".//EVENT[@date=$day]"> <!-- <PARA class="CTEXT"><xsl:value-of select="position()"/>: <xsl:value-of select="PARA[1]"/></PARA> <xsl:for-each select="PARA[position()>1]"> <PARA class="CTEXT"><xsl:value-of select="."/></PARA> </xsl:for-each> --> <PARA class="CTEXT"><xsl:value-of select="TITLE"/></PARA> </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> <xsl:template match="MONTH"> <PARA class="EventsTitle"><xsl:value-of select="TITLE"/> Events</PARA> <table border="1" width="75%" align="center"> <col width="30%"/> <col width="*"/> <tbody> <tr class="Weekday"> <td>Event</td> <td>Description</td> </tr> <xsl:apply-templates/> </tbody> </table> </xsl:template> <xsl:template match="MONTH/TITLE"/> <xsl:template match="EVENT"> <tr> <td valign="top"><xsl:value-of select="@date"/> - <xsl:apply-templates select="TITLE"/></td> <td valign="top"><xsl:apply-templates select="PARA"/></td> </tr> </xsl:template> <xsl:template match="EVENT/TITLE"> <xsl:apply-templates/> </xsl:template> <xsl:template match="EVENT/PARA"> <PARA class="CTEXT"> <xsl:apply-templates/> </PARA> </xsl:template> </xsl:stylesheet> -----Original Message----- From: David Vogt [mailto:dvogt@xxxxxxxxxxxxx] Sent: Friday, January 05, 2001 4:36 AM To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' Subject: [xsl] How to create XSL for CALENDAR/MONTH layout? I have a calendar that displays 12 months of a year. Currently, all 12 months display across the page as one row. Instead, I'd like to arrange them a 3 rows with 4 months in each row. Any ideas how to do this: <tr>4 MONTHS HERE</tr>? The XML looks like this: <CALENDAR> <YEAR>2000</YEAR> <MONTH> <MONTHNAME>January</MONTHNAME> <WEEK> <WEEKNUMBER>1</WEEKNUMBER> <DAY>1</DAY> <DAY>2</DAY> <DAY>3</DAY> <DAY>4</DAY> <DAY>5</DAY> <DAY>6</DAY> <DAY>7</DAY> </WEEK> </MONTH> </CALENDAR> The XSL looks like this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="*|/"><xsl:apply-templates/></xsl:template> <xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template> <xsl:template match="/"> <HTML style=""> <HEAD style=""> <TITLE style="">Year View</TITLE> <LINK style="" href="calendar.css" rel="stylesheet"/> </HEAD> <BODY style=""> <TABLE style="" cellSpacing="0" cellPadding="0" width="597" align="left" border="0"> <TBODY style=""> <xsl:apply-templates/> </TBODY> </TABLE> </BODY> </HTML> </xsl:template> <xsl:template match="CALENDAR"> <tr> <xsl:apply-templates select="MONTH"/> </tr> </xsl:template> <xsl:template match="MONTH"> <td> <table cellspacing="0" cellpadding="0" width="162" border="0"> <tbody> <tr> <td><img src="c:\spacer_white.gif" width="2"></img></td> <td align="middle" bgcolor="#000066"> <table cellspacing="0" cellpadding="0" width="158" background="c:\stripes.gif" border="0"> <tbody> <tr falign="middle" background="c:\stripes.gif"> <td class="calTextWhite" height="22" width="100%" align="center"> <xsl:value-of select="MONTHNAME"/> </td> </tr> </tbody> </table> </td> </tr> <tr> <td><img src="c:\spacer_white.gif" width="2"></img></td> <td> <table cellspacing="0" cellpadding="0" width="158" bgcolor="#ffffff" border="0"> <tbody> <tr> <td class="calTextBlack" align="middle">M</td> <td class="calTextBlack" align="middle">Tu</td> <td class="calTextBlack" align="middle">W</td> <td class="calTextBlack" align="middle">Th</td> <td class="calTextBlack" align="middle">F</td> <td class="calTextBlack" align="middle">Sa</td> <td class="calTextBlack" align="middle">Su</td> </tr> <xsl:apply-templates select="WEEK"/> </tbody> </table> </td> </tr> </tbody> </table> </td> </xsl:template> <xsl:template match="WEEK"> <tr> <xsl:apply-templates select="DAY"/> </tr> </xsl:template> <xsl:template match="DAY"> <td class="calText" align="middle"> <xsl:value-of select="DAYNUMBER"/> </td> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to create XSL for CAL, Adam Van Den Hoven | Thread | [xsl] Programming without Assignmen, Dan . Diebolt |
RE: [xsl] How to create XSL for CAL, Adam Van Den Hoven | Date | [xsl] xsl:key and document(), Robert Goheen |
Month |