This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Date Comparison using ">=" and "<=" doesn't work - WHY!?!?
- From: "David N Bertoni/Cambridge/IBM" <david_n_bertoni at us dot ibm dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 11 Mar 2002 20:15:52 -0800
- Subject: Re: [xsl] Date Comparison using ">=" and "<=" doesn't work - WHY!?!?
- Reply-to: xsl-list at lists dot mulberrytech dot com
The arguments for the relational operators <, <=, >, and >= are converted
to numbers before performing the comparison. Since the string literals
'2/12/02' '2/15/02' are not a valid numbers in XPath, they are converted to
NaN. NaN has a very "interesting" property when compared to other numbers
(including itself) -- the result is always false.
XPath 1.0 has no notion of collation comparison between strings using these
operators (although that will probably change in XPath 2.0), nor is there a
data type.
An easy way to handle this is to encode dates in such a way that they can
be compared as numbers. For your example, as 20020210 and 20020215. If
you don't have control over your source document, you'll need to do some
fancy string manipulation, or write an extension function which does the
conversion.
Dave
"Gregory Pearson"
<GregP@nbsys.com> To: <XSL-List@lists.mulberrytech.com>
Sent by: cc: (bcc: David N Bertoni/Cambridge/IBM)
owner-xsl-list@lists.mulbe Subject: [xsl] Date Comparison using ">=" and "<=" doesn't work - WHY!?!?
rrytech.com
03/11/2002 03:28 PM
Please respond to xsl-list
Hi.
This works:
Style.XMLDocument.selectNodes
("//xsl:apply-templates/@select")(1).value = "record[Date = '2/12/02']";
This does NOT work:
Style.XMLDocument.selectNodes
("//xsl:apply-templates/@select")(1).value = "record[Date >= '2/10/02' and
Date <= '2/15/02']";
IS IT NOT POSSIBLE TO USER ">=" AND "<=" FOR DATES?
Thanks!!
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list