I know this question might get repeated and also I have went through similar articles and question but I have not found the exact solution.
Now the question
I am using XSLT or XPATH to transform the xml. Here in XML two string variables are there. one is OldDate
and second is CurrentDate
.
Ex : $oldDate = '29.05.2015 15:25:06'
$currentDate ='27.07.2015 14:28:02'.
Now I want to compare those two dates.
If $oldDate > $currentDate then 'OK' else 'Not Ok'.
As I am new to use XSLT and XPATH I did not get that how to proceed from the given answers in other articles.
It will be great-full to provide a perfect solution for this.
Thank you.
XSLT (2.0) recognizes dates in
YYYY-MM-DD
format only, and date-times inYYYY-MM-DDThh:mm:ss
format only. In order to compare the strings as dates, (or, in this case, date-times), you must first convert them to valid date-times. Since you need to do this more than once, it would be convenient to construct a function for this purpose:XSLT 2.0
Result
Note that this assumes your strings come in a
DD.MM.YYYY hh:mm:ss
format - i.e. that the days are padded to two digits - otherwise there's more work to be done.Given this input XML:
and this stylesheet:
it produces: