RE: [xsl] basic calendar date XML?

Subject: RE: [xsl] basic calendar date XML?
From: "Robert Koberg" <rob@xxxxxxxxxx>
Date: Thu, 23 Aug 2001 13:22:14 -0700
Well, I ended up doing it myself.  It was definitely one the more difficult
XSLs I have had to create, much more than I thought... Anyway here is what I
did:

XML
---------------------------------------------------------------------------
	<calendar>
		<year number="2001">
			<month name="September" day-count="30" start-day="Saturday"
end-day="Sunday">
				<grade-level role="Junior" grade="11">
					<day number="0">
						Plan Senior courses, Including AP courses.
					</day>
					<day number="0">
						You should be narrowing down your college choices or alternative
plans.
					</day>
					<day number="11">
						Registration Deadline for October SAT I and SAT II exam
					</day>
					<day number="28">
						Registration Deadline for November SAT I and SAT II exam
					</day>
					<day number="21">
						Registration Deadline for October ACT exam
					</day>
				</grade-level>
			</month>
		</year>
	</calendar>
============================================================================
=
XSL
----------------------------------------------------------------------------
-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE stylesheet [
	<!ENTITY % globaldefs SYSTEM "globaldefs-styling.ent">
	%globaldefs;
   ]>

<xsl:stylesheet
   version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:include href="wrapper.xsl"/>


<xsl:template match="calendar">

      <FORM NAME="form1" METHOD="post" ACTION="">
         <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="436"
BGCOLOR=
         "#cccccc" HEIGHT="30">
            <TR>
               <TD WIDTH="9">
                   
               </TD>
               <TD WIDTH="44" ALIGN="middle" VALIGN="center">
                  <A HREF="javascript:;" ONMOUSEOUT="MM_swapImgRestore()"
                  ONMOUSEOVER=

"MM_swapImage('prev','','/&context;/images/tln_but_tools-prev1-on.gif',1);MM
_swapImage('prev','','/&context;/images/tln_but_tools-prev1-on.gif',1)">
                  <IMG SRC="/&context;/images/tln_but_tools-prev1-off.gif"
                   WIDTH="39" HEIGHT="21" NAME="prev" ALT="Previous" BORDER=
                  "0"/></A>
               </TD>
               <TD WIDTH="100">
                  <SELECT NAME="select">
                     <OPTION SELECTED="selected">
                        September 2001
                     </OPTION>
                     <OPTION>
                        October 2001
                     </OPTION>
                  </SELECT>
               </TD>
               <TD WIDTH="44" ALIGN="middle" VALIGN="center">
                  <A HREF="javascript:;" ONMOUSEOUT="MM_swapImgRestore()"
                  ONMOUSEOVER=

"MM_swapImage('next','','/&context;/images/tln_but_tools-next1-on.gif',1)">
                  <IMG SRC="/&context;/images/tln_but_tools-next1-off.gif"
                   WIDTH="39" HEIGHT="21" NAME="next" ALT="Next" BORDER=
                  "0"/></A>
               </TD>
               <TD WIDTH="140">
                   
               </TD>
               <TD ALIGN="center">
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
      d = new Date();
      month = d.getMonth();
      day   = d.getDay();
      year  = d.getYear();

      document.write(month + "/" + day + "/" + year);

</SCRIPT>

               </TD>
            </TR>
         </TABLE>

      </FORM>

      <TABLE BORDER="1" CELLSPACING="3" CELLPADDING="0" BGCOLOR="#d0d3DA"
WIDTH="436" BORDERCOLOR="white">
         <TR ALIGN="center" VALIGN="middle">
            <TD ROWSPAN="6" WIDTH="3" BORDERCOLOR="#d0d3DA">
                
            </TD>
            <TD>
               <TABLE BORDER="1" CELLSPACING="3" CELLPADDING="0"
BGCOLOR="#d0d3DA" BORDERCOLOR="white">
                  <TR ALIGN="center" VALIGN="middle">
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        S
                     </TD>
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        M
                     </TD>
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        T
                     </TD>
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        W
                     </TD>
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        T
                     </TD>
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        F
                     </TD>
                     <TD WIDTH="36" HEIGHT="24" BGCOLOR="#FFFFFF">
                        S
                     </TD>
                  </TR>

                   <xsl:apply-templates select="year/month"/>

               </TABLE>
            </TD>

            <TD ROWSPAN="6" WIDTH="2" BORDERCOLOR="#d0d3DA">
                
            </TD>
            <TD ROWSPAN="6" WIDTH="125" BORDERCOLOR="#d0d3DA">
               <IMG SRC="/&context;/images/tln_pic_calender1.gif"
WIDTH="125" HEIGHT="161"/>
            </TD>
            <TD ROWSPAN="6" WIDTH="2" BORDERCOLOR="#d0d3DA">
                
            </TD>
         </TR>


      </TABLE>
</xsl:template>




<xsl:template match="month">

   <xsl:variable name="start-day-number">
      <xsl:call-template name="day-number">
         <xsl:with-param name="day-name" select="@start-day"/>
      </xsl:call-template>
   </xsl:variable>

   <xsl:variable name="end-day-number">
      <xsl:call-template name="day-number">
         <xsl:with-param name="day-name" select="@end-day"/>
      </xsl:call-template>
   </xsl:variable>


   <xsl:call-template name="day">
      <xsl:with-param name="count" select="1"/>
      <xsl:with-param name="start-day-number" select="$start-day-number"/>
      <xsl:with-param name="end-day-number" select="$end-day-number"/>
      <xsl:with-param name="day-count" select="@day-count"/>
   </xsl:call-template>

</xsl:template>

<xsl:template name="day-number">

   <xsl:param name="day-name"/>

   <xsl:choose>
      <xsl:when test="$day-name='Sunday'">
         <xsl:text>1</xsl:text>
      </xsl:when>
      <xsl:when test="$day-name='Monday'">
         <xsl:text>2</xsl:text>
      </xsl:when>
      <xsl:when test="$day-name='Tuesday'">
         <xsl:text>3</xsl:text>
      </xsl:when>
      <xsl:when test="$day-name='Wednesday'">
         <xsl:text>4</xsl:text>
      </xsl:when>
      <xsl:when test="$day-name='Thursday'">
         <xsl:text>5</xsl:text>
      </xsl:when>
      <xsl:when test="$day-name='Friday'">
         <xsl:text>6</xsl:text>
      </xsl:when>
      <xsl:when test="$day-name='Saturday'">
         <xsl:text>7</xsl:text>
      </xsl:when>
   </xsl:choose>

</xsl:template>

<xsl:template name="day">
   <xsl:param name="count"/>
   <xsl:param name="start-day-number"/>
   <xsl:param name="end-day-number"/>
   <xsl:param name="day-count"/>

   <xsl:variable name="division-result" select="(number($count) div 7)"/>
   <xsl:variable name="remainder" select="substring-after($division-result,
'.')"/>

   <xsl:if test="$count &lt;= 0">
      <xsl:text disable-output-escaping="yes">&lt;TR&gt;</xsl:text>
   </xsl:if>
   <xsl:choose>
      <xsl:when test="$count >= $start-day-number and $count &lt; $day-count
+ $start-day-number">
         <TD WIDTH="36" HEIGHT="24" ALIGN="right" VALIGN="middle">
            <A HREF="#"><xsl:value-of select="$count - $start-day-number +
1"/></A>

         </TD>
      </xsl:when>
      <xsl:otherwise>
         <TD BGCOLOR="#DFE3EA" WIDTH="36" HEIGHT="24" ALIGN="right"
VALIGN="middle">

         </TD>
      </xsl:otherwise>
   </xsl:choose>

   <xsl:choose>
      <xsl:when test="not(number($remainder)) and not($count = $day-count)">
         <xsl:text disable-output-escaping="yes">&lt;/TR&gt;</xsl:text>
      </xsl:when>
      <xsl:when test="not(number($remainder))">
         <xsl:text
disable-output-escaping="yes">&lt;/TR&gt;&lt;TR&gt;</xsl:text>
      </xsl:when>

   </xsl:choose>

   <xsl:if test="$count &lt; ((7 - $end-day-number) +($day-count +
$start-day-number) - 1)">
      <xsl:call-template name="day">
         <xsl:with-param name="count" select="number($count) + 1"/>
         <xsl:with-param name="start-day-number"
select="$start-day-number"/>
         <xsl:with-param name="end-day-number" select="$end-day-number"/>
         <xsl:with-param name="day-count" select="$day-count"/>
      </xsl:call-template>
   </xsl:if>

</xsl:template>

</xsl:stylesheet>
=======================================================================



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Joerg
Pietschmann
Sent: Thursday, August 23, 2001 12:38 AM
To: XSL List
Subject: RE: [xsl] basic calendar date XML?


"Robert Koberg" <rob@xxxxxxxxxx> wrote:
>
> I need to create a month-by-month calendar.  I looked in the archive and
> found a solution by G. Ken Holman but it did not provide the XML
necessary.
> I tried a search for your name and date and /or calendar and came up with
> nothing (I never found your solution - any more hints about the thread?)
[snip]
> Now that I think of it, I can just (find out and) stick the start day and
> end day in my XML that I have already created, so I don't need full
calendar
> data.

You don't have to, as these data can be calculated easily.
Look at
http://www.biglist.com/lists/xsl-list/archives/199909/msg00056.html
or perhaps even closer to your task
http://www.biglist.com/lists/xsl-list/archives/199909/msg00034.html
http://www.biglist.com/lists/xsl-list/archives/200101/msg00205.html
or look at
http://www.biglist.com/lists/xsl-list/archives/200103/msg00838.html
for other calculations.

HTH
J.Pietschmann

 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