1<?xml version="1.0"?> 2 3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 4 5 6 7<!-- Author: Muhammad Athar Parvez --> 8 9<!-- Reference: http://www.incrementaldevelopment.com/xsltrick/parvez/#calendar --> 10 11<!-- Description: Print out an html calander of a month --> 12 13 14 15<xsl:output method="xml" encoding="UTF-8"/> 16 17 18 19<xsl:variable name="start" select="/month/@start"/> 20 21<xsl:variable name="count" select="/month/@days"/> 22 23 24 25<xsl:variable name="total" select="$start + $count - 1"/> 26 27<xsl:variable name="overflow" select="$total mod 7"/> 28 29 30 31<xsl:variable name="nelements"> 32 33<xsl:choose> 34 35<xsl:when test="$overflow > 0"><xsl:value-of select="$total + 7 - $overflow"/></xsl:when> 36 37<xsl:otherwise><xsl:value-of select="$total"/></xsl:otherwise> 38 39</xsl:choose> 40 41</xsl:variable> 42 43 44 45<xsl:template match="/"> 46 47 48 49<html> 50 51<head><title><xsl:value-of select="month/name"/></title></head> 52 53 54 55<body bgcolor="lightyellow"> 56 57 58 59<h1 align="center"><xsl:value-of select="month/name"/></h1> 60 61 62 63<table border="1" bgcolor="lightblue" noshade="yes" align="center"> 64 65<tr bgcolor="white"> 66 67<th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th> 68 69</tr> 70 71 72 73<xsl:call-template name="month"/> 74 75</table> 76 77 78 79</body></html> 80 81 82 83</xsl:template> 84 85 86 87<!-- Called only once for root --> 88 89<!-- Uses recursion with index + 7 for each week --> 90 91<xsl:template name="month"> 92 93<xsl:param name="index" select="1"/> 94 95 96 97<xsl:if test="$index < $nelements"> 98 99<xsl:call-template name="week"> 100 101<xsl:with-param name="index" select="$index"/> 102 103</xsl:call-template> 104 105 106 107<xsl:call-template name="month"> 108 109<xsl:with-param name="index" select="$index + 7"/> 110 111</xsl:call-template> 112 113</xsl:if> 114 115 116 117</xsl:template> 118 119 120 121<!-- Called repeatedly by month for each week --> 122 123<xsl:template name="week"> 124 125<xsl:param name="index" select="1"/> 126 127<tr> 128 129<xsl:call-template name="days"> 130 131<xsl:with-param name="index" select="$index"/> 132 133<xsl:with-param name="counter" select="$index + 6"/> 134 135</xsl:call-template> 136 137</tr> 138 139</xsl:template> 140 141 142 143<!-- Called by week --> 144 145<!-- Uses recursion with index + 1 for each day-of-week --> 146 147<xsl:template name="days"> 148 149<xsl:param name="index" select="1"/> 150 151<xsl:param name="counter" select="1"/> 152 153 154 155<xsl:choose> 156 157<xsl:when test="$index < $start"> 158 159<td>-</td> 160 161</xsl:when> 162 163 164 165<xsl:when test="$index - $start + 1 > $count"> 166 167<td>-</td> 168 169</xsl:when> 170 171 172 173<xsl:when test="$index > $start - 1"> 174 175<td><xsl:value-of select="$index - $start + 1"/></td> 176 177</xsl:when> 178 179 180 181</xsl:choose> 182 183 184 185<xsl:if test="$counter > $index"> 186 187<xsl:call-template name="days"> 188 189<xsl:with-param name="index" select="$index + 1"/> 190 191<xsl:with-param name="counter" select="$counter"/> 192 193</xsl:call-template> 194 195</xsl:if> 196 197 198 199</xsl:template> 200 201 <!-- 202 * Licensed to the Apache Software Foundation (ASF) under one 203 * or more contributor license agreements. See the NOTICE file 204 * distributed with this work for additional information 205 * regarding copyright ownership. The ASF licenses this file 206 * to you under the Apache License, Version 2.0 (the "License"); 207 * you may not use this file except in compliance with the License. 208 * You may obtain a copy of the License at 209 * 210 * http://www.apache.org/licenses/LICENSE-2.0 211 * 212 * Unless required by applicable law or agreed to in writing, software 213 * distributed under the License is distributed on an "AS IS" BASIS, 214 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 215 * See the License for the specific language governing permissions and 216 * limitations under the License. 217 --> 218 219</xsl:stylesheet> 220