c3d2-web/xsl/calendar.xsl

172 lines
5.3 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
exclude-result-prefixes="xsl date">
<xsl:include href="ddate.xsl" />
<xsl:template match="/page/calendar-summary">
<table border="0" class="calendar">
<tr>
<th>Montag</th>
<th>Dienstag</th>
<th>Mittwoch</th>
<th>Donnerstag</th>
<th>Freitag</th>
<th>Samstag</th>
<th>Sonntag</th>
</tr>
<xsl:call-template name="output-week">
<xsl:with-param name="date">
<xsl:call-template name="get-past-monday">
<xsl:with-param name="date" select="concat(date:year(date:date()), '-', format-number(date:month-in-year(date:date()), '00'), '-01')"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="stopmonth" select="date:month-in-year(date:add(date:date(), 'P2M'))"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="output-week">
<xsl:param name="date"/>
<xsl:param name="stopmonth"/>
<tr>
<xsl:call-template name="output-day">
<xsl:with-param name="date" select="$date"/>
</xsl:call-template>
</tr>
<xsl:variable name="nextweek" select="date:add($date, 'P7D')"/>
<xsl:if test="date:month-in-year($nextweek) != $stopmonth">
<xsl:call-template name="output-week">
<xsl:with-param name="date" select="$nextweek"/>
<xsl:with-param name="stopmonth" select="$stopmonth"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!--
td/@class ist wie folgend aufgebaut:
* Beginnt immer mit 'cal'
* Dann 'week' für Wochentage, 'sun' für Sonntage
* '1' für aktuellen Monat, '2' für folgenden Monat, '3' für sonstige Monate
-->
<xsl:template name="output-day">
<xsl:param name="date"/>
<td>
<xsl:attribute name="class">
<xsl:text>cal</xsl:text>
<xsl:choose>
<xsl:when test="date:day-in-week($date) = 1">sun</xsl:when>
<xsl:otherwise>week</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="date:month-in-year($date) = date:month-in-year(date:date())">1</xsl:when>
<xsl:when test="date:month-in-year($date) = date:month-in-year(date:add(date:date(), 'P1M'))">2</xsl:when>
<xsl:otherwise>3</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:variable name="ddate">
<xsl:call-template name="ddate">
<xsl:with-param name="date" select="$date"/>
</xsl:call-template>
</xsl:variable>
<span class="day" title="{$ddate}">
<xsl:value-of select="date:day-in-month($date)"/>
</span>
<ul>
<xsl:for-each select="event">
<xsl:sort select="start"/>
<xsl:variable name="start">
<xsl:call-template name="strip-time-from-date">
<xsl:with-param name="date" select="start"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="end">
<xsl:call-template name="strip-time-from-date">
<xsl:with-param name="date" select="end"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="date">
<xsl:call-template name="strip-time-from-date">
<xsl:with-param name="date" select="$date"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="(date:seconds($start) &lt;= date:seconds($date)) and (date:seconds($date) &lt;= date:seconds($end))">
<li>
<a href="{link}">
<xsl:value-of select="title"/>
</a>
</li>
</xsl:if>
</xsl:for-each>
<xsl:variable name="dholiday">
<xsl:call-template name="ddate-holiday">
<xsl:with-param name="date" select="$date"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="string-length(normalize-space($dholiday)) &gt; 0">
<li><xsl:value-of select="normalize-space($dholiday)"/></li>
</xsl:if>
</ul>
</td>
<xsl:if test="date:day-in-week($date) != 1"> <!-- Sunday? Break and return to output-week... -->
<xsl:call-template name="output-day">
<xsl:with-param name="date" select="date:add($date, 'P1D')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="calendar-title">
<xsl:variable name="d1" select="date:date()"/>
<xsl:variable name="d2" select="date:add(date:date(), 'P1M')"/>
<xsl:text>Kalender: </xsl:text>
<xsl:call-template name="get-monthstring">
<xsl:with-param name="date" select="$d1"/>
</xsl:call-template>
<xsl:if test="date:year($d1) != date:year($d2)">
<xsl:text> </xsl:text>
<xsl:value-of select="date:year($d1)"/>
</xsl:if>
<xsl:text> &amp; </xsl:text>
<xsl:call-template name="get-monthstring">
<xsl:with-param name="date" select="$d2"/>
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:value-of select="date:year($d2)"/>
</xsl:template>
<xsl:template name="get-past-monday">
<xsl:param name="date"/>
<xsl:choose>
<xsl:when test="date:day-in-week($date) = 2">
<xsl:value-of select="$date"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="get-past-monday">
<xsl:with-param name="date" select="date:add($date, '-P1D')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>