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

Re: How to create XSL for CALENDAR/MONTH layout?

Subject: Re: How to create XSL for CALENDAR/MONTH layout?
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 5 Jan 2001 18:35:53 +0000
xsl months node
Hi David,

> I have a calendar that displays 12 months of a year. Currently, all
> 12 months display across the page as one row. Instead, I'd like to
> arrange them a 3 rows with 4 months in each row. Any ideas how to do
> this: <tr>4 MONTHS HERE</tr>?

This is a grouping-by-position problem: you want to group the months
according to their position within the CALENDAR element.

As with any grouping problem, you can break it down into two steps:
1. finding the first node in a group
2. processing the group

The usual way of finding the first node in a group based on position
use the mod operator on the position of the node.  If you want to
group into groups of 4, then the position of the first node in each
group mod 4 will equal 1.  In your case, you can use the XPath:

  MONTH[position() mod 4 = 1]

to select the months that are first in each row.  I'd probably select
these by applying templates in 'row' mode inside the
CALENDAR-matching template:

<xsl:template match="CALENDAR">
  <xsl:apply-templates select="MONTH[position() mod 4 = 1"
                       mode="row" />
</xsl:template>

Then create a template that matches MONTHs in 'row' mode. Because
you've only selected the first in the group, this template will only
fire once per row. This template needs to create a row and then apply
templates to each of the months in the group. The group of months
consists of the MONTH you're currently on and its next 3 siblings,
i.e.:

  . | following-sibling::MONTH[position() &lt; 4]

So it should look something like:

<xsl:template match="MONTH" mode="row">
  <tr>
    <xsl:apply-templates
      select=". | following-sibling::MONTH[position() &lt; 4]" />
  </tr>
</xsl:template>

This will then use the MONTH-matching template that you already have.

If you want to, you can separate out the number of months that you
want in each row into a variable or parameter that you can change
during development, or even let the user change dynamically.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.