Determining Secular and Religious Holidays
Problem
You would like to know if a given date is a holiday.
Solution
The first type of holiday includes those that fall on the same day every year. For example, a function to determine the absolute day of American Independence for any year is simply:
<xsl:template name="date:independence-day"> <xsl:param name="year"/> <xsl:call-template name="date:date-to-absolute-day"> <xsl:with-param name="month" select="7"/> <xsl:with-param name="day" select="4"/> <xsl:with-param name="year" select="$year"/> </xsl:call-template> </xsl:template>
The second type of holiday falls on the same day of the week relative
to the start or end of a month. You can compute those days with the
help of the following utility, which wraps the
k-day-on-or-before-abs-day
template contained in
Recipe 3.8.
<xsl:template name="date:n-th-k-day"> <!-- The n'th occurance of k in the given month --> <!-- Postive n counts from beginning of month; negative from end. --> <xsl:param name="n"/> <!-- k = the day of the week (0 = Sun) --> <xsl:param name="k"/> <xsl:param name="month"/> <xsl:param name="year"/> <xsl:choose> <xsl:when test="$n > 0"> <xsl:variable name="k-day-on-or-before"> <xsl:variable name="abs-day"> <xsl:call-template name="date:date-to-absolute-day"> <xsl:with-param name="month" select="$month"/> <xsl:with-param name="day" select="7"/> <xsl:with-param name="year" select="$year"/> </xsl:call-template> </xsl:variable> <xsl:call-template name="date:k-day-on-or-before-abs-day"> ...
Get XSLT Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.