[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: comparing a string to a number?
At 2003-09-17 09:16 -0400, cknell@xxxxxxxxxx wrote:
Yes, '1A' will always be "less than" '20' when compared as strings. String sorting is based on the numeric value (usually ASCII) of each successive character. Thus '10000000' will be "less than" '2'. I disagree .... in XPath 1.0 the "less than" infers numeric data typing on the operands, and does not preserve the string typing. Ref XPath 1.0 Section 3.4 paragraph starting with: ===8<--- When neither object to be compared is a node-set and the operator is <=, <, >= or >, then the objects are compared by converting both objects to numbers and comparing the numbers according to IEEE 754. The < comparison will be true if and only if the first number is less than the second number. ===8<--- Therefore ( '100000000' < '2' ) in XPath is *always* false because 1000000 is greater than 2. -----Original Message----- From: "Keller, Matt" <Keller.Matt@xxxxxxxxxxxxx> Sent: Tue, 16 Sep 2003 17:18:19 -0500 ... <xsl:if test="/Output/response/Field < '20'"> Since the numeric data type inference would change "1A" to NaN (not-a-number), and NaN doesn't compare true in numeric terms to anything (including itself), the value of ( "1A" < '20 ) will *always* be false. I hope this helps. .................. Ken
<xsl:template match="/"> <xsl:value-of select="'10000000' < '2'"/> </xsl:template> </xsl:stylesheet> T:\ftemp>saxon knell.xsl knell.xsl <?xml version="1.0" encoding="utf-8"?>false T:\ftemp> -- Next public European delivery: 3-day XSLT/2-day XSL-FO 2003-09-22 Next public US delivery: 3-day XSLT/2-day XSL-FO 2003-10-13 Instructor-led on-site corporate, government & user group training for XSLT and XSL-FO world-wide: please contact us for the details G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-11-X Practical Formatting Using XSL-FO Member of the XML Guild of Practitioners: http://XMLGuild.info Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc 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
|