Re: [xsl] calendar generation

Subject: Re: [xsl] calendar generation
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 11 May 2010 12:12:06 -0400

This sounds like a fun problem.

To start, I'd simply determine how many days there were during the interval of interest, then iterate through a set of natural numbers (1 to the day count), using date arithmetic to add single days to the starting date. This would give me a sequence of date objects. (The methods you will need are all well-explained in Mike Kay's book.)

Here's something to get you started:

<xsl:variable name="start-date" select="xs:date('1776-01-01')"/>

<xsl:variable name="date-sequence" as="xs:date+">
  <xsl:sequence select="$start-date"/>
  <xsl:for-each select="1 to 365">
    <xsl:variable name="days"
    <xsl:sequence select="$start-date + $days"/>

<xsl:template match="/">
  <xsl:for-each select="$date-sequence">
    <xsl:value-of select="format-date(.,'[MNn] [D] [Y]')"/>

Notice in this case how 366 days are necessary to get all of 1776.

I'd then group them (groups starting with Sundays) into tabular form to make my calendar. The format-date function will be very useful for determining days of the week.


At 11:35 AM 5/11/2010, you wrote:
Hi there,

I'm sure I'm treading over well-trodden ground, but my glance through
the FAQ and googling doesn't turn up an easy XSLT2-based solution.

What I want to do is for any given year (well, they will be between
1788 and 1837 in this case) generate a tabular calendar of months and
days, with some of the days predictably being links to a resource for
that date.  (Type: cal 1788  in any linux system to get an idea of
what I mean.)   I have a list of what years/days/months the resource
has content for in a format like:

<year xml:id="g1789">
    <month xml:id="g1789-01">
       <day xml:id="g1789-01-01"/>
       <day xml:id="g1789-01-02"/>
       <day xml:id="g1789-01-03"/>
       <day xml:id="g1789-01-04"/>
       <day xml:id="g1789-01-05"/>
       <day xml:id="g1789-01-06"/>

And I know I can lookup these ids to test whether there is a
corresponding link in the resource.  That isn't really the problem.
What I want to know is whether someone has already done the code to
generate a year-view calendar in some sensible manner so I don't have
to figure out the date calculation of any individual date? Obviously
the intent of this is that it will be used for navigation on a
date-oriented historical resource.

Thanks for any suggestions!

====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread