My XSLT skills are limited and I think I need help on this one. I basically need to display a particular message depending on the time of day. I could do this quite easily in C# but I like to make my life difficult so I am using XSLT because I need to develop my skills in this area and a user control is probably overkill for this anyway.
I don't think the comparison in the following example is not actually happening, perhaps XSLT can only compare simple data types such as strings and numbers and not dates?
<xsl:choose>
<xsl:when test="$currentTime > Exslt.ExsltDatesAndTimes:time('12:00:00') and $currentTime < Exslt.ExsltDatesAndTimes:time('17:00:00')">
Good Afternoon
</xsl:when>
<xsl:when test="$currentTime > Exslt.ExsltDatesAndTimes:time('17:00:00') and $currentTime < Exslt.ExsltDatesAndTimes:time('00:00:00')">
Good evening
</xsl:when>
<xsl:otherwise>
Good Morning
</xsl:otherwise>
</xsl:choose>
Any advice on where I am going wrong or a pointer to a better solution would be appreciated.
Thanks Matt, it works with the exception of midnight because that translates to 000000 so I had to fudge that to 235959 but hey what's 1 second really. It feels a little dirty but will do as a quick solution for the time being.
In case anyone else wants something like this, here is my complete solution:
You could use DateGreaterThan or DateGreaterThanOrEqual (I wouldn't use DateGreaterThanToday, as it only does a day based comparison, not time which simon is after), but I didn't go that route as it sounded like he wanted a pure XSLT suggestion, but yea, definatley one to concider if you are wanting to do the same.
Hi Matt, sure - good point, if you need the time as well you have to use one of the other functions. But I would at any time prefer one of the standard extension methods over trying to parse the number yourself, relying on specific date/time format etc.
I think in this case where the time is not an input it is probably ok but if the time comparison was a value being passed in then I agree it's not really a safe option.
Time comparison with XSLT
My XSLT skills are limited and I think I need help on this one. I basically need to display a particular message depending on the time of day. I could do this quite easily in C# but I like to make my life difficult so I am using XSLT because I need to develop my skills in this area and a user control is probably overkill for this anyway.
I don't think the comparison in the following example is not actually happening, perhaps XSLT can only compare simple data types such as strings and numbers and not dates?
Any advice on where I am going wrong or a pointer to a better solution would be appreciated.
You could convert the date into a number, then do a simple comparison on that? Take a look at an example here:
http://kodethoughts.blogspot.com/2007/10/sharepoint-comparing-dates-in-xslt.html
Matt
Thanks Matt, it works with the exception of midnight because that translates to 000000 so I had to fudge that to 235959 but hey what's 1 second really. It feels a little dirty but will do as a quick solution for the time being.
In case anyone else wants something like this, here is my complete solution:
Hi Simon, I would go for the date-comparison functions in the umbraco.library, e.g. DateGreaterThanToday
http://our.umbraco.org/wiki/reference/umbracolibrary
Tommy
Hi Tommy,
You could use DateGreaterThan or DateGreaterThanOrEqual (I wouldn't use DateGreaterThanToday, as it only does a day based comparison, not time which simon is after), but I didn't go that route as it sounded like he wanted a pure XSLT suggestion, but yea, definatley one to concider if you are wanting to do the same.
Matt
Hi Matt, sure - good point, if you need the time as well you have to use one of the other functions. But I would at any time prefer one of the standard extension methods over trying to parse the number yourself, relying on specific date/time format etc.
>Tommy
I think in this case where the time is not an input it is probably ok but if the time comparison was a value being passed in then I agree it's not really a safe option.
I think we more or less all agree ;-)
This also seems to work
Dan
Oooooh, thats a nice one.
Thanks, Simon, it helped me a lot!
Great, please make sure you vote for any posts you find helpful.
Simon
is working on a reply...