This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Date Comparison using ">=" and "<=" doesn't work - WHY!?!?



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]