Page 1 of 1

checking date

Posted: Sat Jul 07, 2007 5:13 pm
by tokyo12
How do you do a date comparison?

if Ihave something like:

<xsl:value-of select="format-number(sum($something[ xyz ... ]

where xyz is checking the value of some variable like "valid=y", and I want to extend that check to say "if valid = y and date > 1 Jan 2007" how do I do it?

Should something like this work?

date > '01-Jan-2007' ?

date is coming from a sybase table.

Many thanks,
Mike

Posted: Mon Jul 09, 2007 12:52 pm
by sorin_ristache
Hello,

Yes, the > and < operators are correct but I suggest to compare values of type xs:date available in XSLT 2.0 which have the format YYYY-MM-DD. If you use a constant value and a node date then a test like

Code: Select all

date > 2007-01-01
will work but if you use two nodes then you have to convert to xs:date:

Code: Select all

xs:date(date1) > xs:date(date2)

Regards,
Sorin

Posted: Mon Jul 09, 2007 4:23 pm
by tokyo12
Many thanks for your reply. I will try this, I tried it in some other variations but not with the xs:date().

i found some functions like format-dateTime but I couldnt get them to work. Do they require a "xs:" constuct? What is that doing actually, is it specifying the namespace where the function date() is to be found?

Regards,
Mike

Posted: Mon Jul 09, 2007 5:02 pm
by sorin_ristache
Yes, the xs: prefix is for the namespace http://www.w3.org/2001/XMLSchema where the date type is defined. You have to associate the prefix to the namespace in the stylesheet before using the prefix, for example on the root element:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">

Regards,
Sorin