[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Date Comparison using ">=" and "<=" doesn't work -
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@xxxxxxxxx> To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> Sent by: cc: (bcc: David N Bertoni/Cambridge/IBM) owner-xsl-list@xxxxxxxxxxx Subject: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|