[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: NaN

Subject: Re: NaN
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 26 Feb 2002 18:06:02 +0000
xsl number nan
Hi Jason,

> I want to see if the value of an attribute or element is a number or
> string. I tried using number(@value) != 'NaN', but it always returns
> false. How can I find if a value is a string or number.

I think that you mean it always returns true? When you compare a
number (e.g. number(@value)) with a string (e.g. 'NaN'), then the
string gets converted to a number (so 'NaN' becomes NaN), and the
comparison is made. So if @value has the value 25 then the comparison
is between 25 and NaN, and 25 is not equal to NaN, so it returns true.
However, NaN has a weird quality - NaN is not equal to *any* number,
including NaN. So NaN != NaN also returns true.

There are two ways, therefore, that you can test whether the value
attribute holds a number. First, you can compare the result of
converting it to a number and then to a string with the string 'NaN':

  string(number(@value)) != 'NaN'

This will return true if @value is a number (because '25' is not equal
to 'NaN') and false if @value is not a number (because the string
'NaN' is equal to the string 'NaN').

Alternatively, you can use:

  number(@value) = number(@value)

This will return true if @value is a number (because 25 is equal to
25) and false if @value is not a number (because the number NaN is not
equal to the number NaN).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • NaN
    • Clark, Jason - Tue, 26 Feb 2002 12:15:03 -0500 (EST)
      • G. Ken Holman - Tue, 26 Feb 2002 12:47:57 -0500 (EST)
      • Jeni Tennison - Tue, 26 Feb 2002 13:02:35 -0500 (EST) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.