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

RE: Answers to review questions in "Beginning XSLT": C

Subject: RE: Answers to review questions in "Beginning XSLT": Chapter 5
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Tue, 11 Mar 2003 14:56:42 -0600
xslt nan test
I had written:

>    Question: is there a way to represent the numeric constant NaN
>    in an expression?  Apparently the unquoted NaN is not recognized
>    as such; I guess it's interpreted as "the value of the 
> child element
>    named NaN."

but earlier:
> 10. To test whether the current node's value is a number,
>    use test="number() or number() = 0" which gives the desired result.
>    Is there a simpler way?
> 
*>    I tried test="number() != NaN" but this was always false (Why?  Is
*>      NaN not recognized as the numeric constant?  No, I just 
*> learned that
*>      it's because NaN is not equal to itself!  See the FAQ,

I was confused about whether you could use NaN in an expression
to mean the non-number.  After more experimentation, it seems that
the answer is no; much of the time it will produce what you want,
but it is not defined to do so and sometimes won't.

NaN is not "special".  It's just a name.  If the current node
has a child named NaN, that child's string value is returned as the value
of NaN.
Obviously then NaN will result in an empty node set most of the time,
which if used in a numeric context will be converted to NaN.
And in a boolean context the empty node set is equivalent to NaN.
But if used in a string context it will produce the empty string
instead of "NaN".

So, a correct way to get NaN in your expression would be to use
"number('')" (or "number('NaN')"; see Kay pp. 89-90.)

Lars


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


Current Thread

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.