checking date

Here should go questions about transforming XML with XSLT and FOP.
tokyo12
Posts: 2
Joined: Sat Jul 07, 2007 5:05 pm

checking date

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
tokyo12
Posts: 2
Joined: Sat Jul 07, 2007 5:05 pm

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
Post Reply