[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: A Calendar Project...

Subject: RE: A Calendar Project...
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Tue, 17 Jun 2003 18:36:17 +0100
xsl calendar
Hi

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Karl J. Stubsjoen
> Sent: Monday, June 16, 2003 4:41 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  A Calendar Project...
> 
> 
> What if I needed 8 weeks of Sundays... so from an XML source 
> of  40 weeks worth of dates... I'd like to grab 8 of them.  
> Is this something you would handle with keys? I have a 
> working demo of the calendar I've put together thus far, its 
> here: http://www.meetscoresonline.com/test/calendar.asp
> I'm using ASP to build the XML source dynamically... so 
> basically, the stylesheet simply spits out all the results 
> from the XML source.
> 
(...)

I've created a stylesheet to work with your calendar.xml
It have to have all days (in your you're missing 06 Jun 2003)

It uses months.xml that has the config of each month

---- calendar.xsl ----
    <xsl:template match="CAL">
        <xsl:variable name="offset">
            <xsl:call-template name="offset">
                <xsl:with-param name="date" select="DATE[1]/@D"/>
            </xsl:call-template>
        </xsl:variable>
        <table border="1">
            <tr>
                <td>Sunday</td>
                <td>Monday</td>
                <td>Tuesday</td>
                <td>Wednesday</td>
                <td>Thursday</td>
                <td>Friday</td>
                <td>Saturday</td>
            </tr>
            <xsl:call-template name="firstrow">
                <xsl:with-param name="offset" select="number($offset)"/>
            </xsl:call-template>
            <xsl:apply-templates select="DATE[(position() + number($offset))
mod 7=1]"/>
        </table>
    </xsl:template>
    <xsl:template match="DATE">
        <tr>
            <td align="center">
                <xsl:value-of
select="number(substring-after(substring-after(@D,'-'),'-'))"/>
            </td>
            <xsl:apply-templates mode="week"
select="following-sibling::DATE[position() &lt; 7]"/>
        </tr>
    </xsl:template>
    <xsl:template match="DATE" mode="week">
        <td align="center">
            <xsl:value-of
select="number(substring-after(substring-after(@D,'-'),'-'))"/>
        </td>
    </xsl:template>
    <xsl:template name="offset">
        <xsl:param name="date" select="."/>
        <xsl:variable name="y"
select="number(substring-before($date,'-'))"/>
        <xsl:variable name="m"
select="number(substring-before(substring-after($date,'-'),'-'))"/>
        <xsl:variable name="d"
select="number(substring-after(substring-after($date,'-'),'-'))"/>
        <xsl:variable name="nd" select="($y * 365 + ($y - $y mod 4) div 4 +
document('months.xml')/months/month[@num=$m]/@count + $d - 2) mod 7"/>
        <xsl:value-of select="$nd"/>
    </xsl:template>
    <xsl:template name="firstrow">
        <xsl:param name="offset" select="0"/>
        <xsl:if test="$offset > 0">
            <tr>
                <xsl:call-template name="rows">
                    <xsl:with-param name="count" select="$offset"/>
                </xsl:call-template>
                <xsl:apply-templates mode="week" select="DATE[position()
&lt; number($offset)]"/>
            </tr>
        </xsl:if>
    </xsl:template>
    <xsl:template name="rows">
        <xsl:param name="count" select="0"/>
        <xsl:choose>
            <xsl:when test="$count > 0">
                <td>?</td>
                <xsl:call-template name="rows">
                    <xsl:with-param name="count" select="$count - 1"/>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:template>

---- months.xml ----
<months>
    <month days="31" init="Jan" name="January" num="1" count="0"/>
    <month days="28" init="Feb" name="February" num="2" count="31"/>
    <month days="31" init="Mar" name="March" num="3" count="59"/>
    <month days="30" init="Apr" name="April" num="4" count="90"/>
    <month days="31" init="May" name="May" num="5" count="120"/>
    <month days="30" init="Jun" name="June" num="6" count="151"/>
    <month days="31" init="Jul" name="July" num="7" count="181"/>
    <month days="31" init="Aug" name="August" num="8" count="212"/>
    <month days="30" init="Sep" name="September" num="9" count="243"/>
    <month days="31" init="Oct" name="October" num="10" count="273"/>
    <month days="30" init="Nov" name="November" num="11" count="304"/>
    <month days="31" init="Dec" name="December" num="12" count="334"/>
</months>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.