Sunday, February 13, 2011

Comparing Dates in XSLT

Dates manipulation is a very daunting task in XSLT, considering the very limited date-time functions that XSLT 1.0 offers. XSLT 2.0 is enhanced as far this case is concerned. I had to compare dates in XSLT 1.0 and I was contemplating of using a java embedding node, not until I found how to compare the dates in XSLT as below:

1. Convert the date into the format YYYY-MM-DD, either using a function or using existing string functions
2. Do a translate on the date available, translate($Date, '-', '')
3. By doing a translate, the date is converted to ISO date format
4. Do this to both the dates
5. The dates in the ISO format can be directly used for comparison like ISODate1 > ISODate2 etc


Cheers,
-AR
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License