[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?
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() < 4] So it should look something like: <xsl:template match="MONTH" mode="row"> <tr> <xsl:apply-templates select=". | following-sibling::MONTH[position() < 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|