Lets say I have a list of nodes that contain an attribute datetime, and I want to select only the records that occur after $compare-datetime.
<records>
<record @datetime="2010-01-04T16:48:15.501-05:00"/>
<record @datetime="2010-01-03T16:48:15.501-05:00"/>
...etc...
</records>
In xquery to select items within a date range I would do
/records/record[xs:dateTime(@datetime) > xs:dateTime($compare-datetime)]
However in XSLT 1.0 I have tried alot of different approaches and alot of searching for answers, without any luck at getting this to work.
I am beginning to think that short of parsing the actual dateTime to an integer value, this is not a simple task in xslt.
I am hoping someone can give me a definite answer on that so I can at least know what I am up against.
Cheers,
Casey
I had the same problem as you. I built a C# method (so this only works with .Net XSLT):
with namespaces
and usage (snippet from my xslt doc)
May be it's not the best solution, but I have this:
XML input:
XSLT:
Result:
Negative difference would mean that first date occurs after the second date.
If the dates will always be in the same time zone, and have fixed-width fields (constant number of digits in each field), I believe you could take this approach: remove punctuation, leaving the numbers, and compare the numbers.
Then use
I am afraid that XSLT 1.0 has no built-in support for dateTimes. It's possible that you may find that someone has written a library - have a look on the XSLT FAQ
See http://www.dpawson.co.uk/xsl/rev2/dates.html#d14938e16 for what XSLT 2.0 can offer.