Subject:xslt 2.0 calendar Author:James Agnew Date:03 Apr 2006 04:48 AM
Hi
I'd like to be able to generate a simple calendar using xslt 2.0.
Is there a way to know:
1. How many days are in a given month
2. How to add a duration to a given date (e.g. add a day to '2006-03-31' to produce '2006-04-01')
There appears to be lots of new date formatting, extraction and duration functions in the xslt 2.0 spec but I can't find any that achieve the above. I'm using SS 2006 Enterprise R2 with Saxon 8.7.
Subject:xslt 2.0 calendar Author:Minollo I. Date:03 Apr 2006 11:04 AM
>1. How many days are in a given month
You could use a sequence of 12 items and index that on the required month... handling exceptions for leap years...
Or you can rely on XPath date functions, struggling a bit:
declare function local:getDaysInMonth($date as xs:date) as xs:integer
{
let $nextMonth := month-from-date($date)+1
return
if($nextMonth = 13) then 31
else
day-from-date(xs:date( concat(year-from-date($date),'-',if ($nextMonth>9) then $nextMonth else concat('0',$nextMonth),'-','01')) - xdt:dayTimeDuration('P1D'))
};
...then you can call:
local:getDaysInMonth('2006-04-01')
>2. How to add a duration to a given date (e.g. add a day to '2006-03-31' to produce '2006-04-01')