Group Dates by Year, Month and Day
Page 1 of 2
Written by
Gregory Scot Collins
Thursday, 17 August 2006, 1:35 AM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
IN THIS ARTICLE:
When working with lists of date-oriented items, such as calendar events, birthdays, etc., it often becomes desirable to group list items by their date. This article focuses on grouping by date parts, but could easily be altered to group by any kind of data. We will present a short list of holiday calendar events grouped by year, month and then day.
Create the Events.xml file
We need a simple XML file to transform that contains our list of holiday calendar events. Copy the contents of Listing 1 into a text editor, and then save the file as Events.xml.
Create the Calendar.xsl file
Now we need a transform to group the list of holiday events by date. This transform will first identify a unique set of years from the event dates. Below each year we will display a unique set of months for that year, utilizing a named template to display the full name of the month. Below each month we could simply list event details preceded by the day, but instead we will once more group by a unique set of days before listing the event details.
Copy the contents of Listing 2 into a text editor, and then save the file as Calendar.xsl. Be sure to save it in the same folder as the Events.xml file.
Stumble It!
Digg It!
del.icio.us




