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

RE: NaN

Subject: RE: NaN
From: "Sathasivam, Elayaraja" <elayaraja.sathasivam@xxxxxxxxxxxxx>
Date: Tue, 9 Sep 2008 12:37:18 +0530
RE:  NaN
Thanks Scott. It's working perfect.


Regards,
Raja
_________________________________________________________________
-----Original Message-----
From: Scott Trenda [mailto:Scott.Trenda@xxxxxxxx]
Sent: Tuesday, September 09, 2008 12:11 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  NaN

If I recall correctly, an empty node-set is NaN when converted to a number. So
it'll be NaN if the selected node doesn't exist - which will be true if you're
excluding it with [number() = number()]. You can do this instead:

<xsl:variable name="total" select="sum((Charge[@Id='77' and @Type='5' and
@PT='P']/@Amount | SAPCreditItem/@CreditAmount)[number()=number()])"/>

I believe that should work. If there's an XPath error in the union/predicate
expression, you can distribute the predicate onto each of the selectors and
take the union:

<xsl:variable name="total" select="sum(Charge[@Id='77' and @Type='5' and
@PT='P']/@Amount[number()=number()] |
SAPCreditItem/@CreditAmount[number()=number()])"/>

In either case, the idea is the same: you're building a node-set of the
numerical values and taking its sum, instead of adding something that may be
NaN.

~ Scott

-----Original Message-----
From: Sathasivam, Elayaraja
Sent: Tuesday, September 09, 2008 1:20 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  NaN

XSLT: Version 1.0
Platform: Windows XP

XML:
<Charge Id="77" Amount="139.97" CurrCode="EUR" Type="5" PT="P"/>
<SAPCreditItem CreditDate="20080520" CreditAmount=""/>

XSL:
<xsl:variable name="total" select="Charge[@Id='77' and @Type='5'
and  @PT='P']/@Amount + SAPCreditItem/@CreditAmount"/>

Result: <xsl:value-of select="$total"/>

I tried with, <xsl:variable name="total" select="Charge[@Id='77' and @Type='5'
and  @PT='P']/@Amount[number()=number()] +
SAPCreditItem/@CreditAmount[number()=number()]"/>...But again the output is
Nan.

How to avoid NaN. When the value is empty( CreditAmount="" ) as shown above.


Expected result: 139.97
Actual result: NaN



Regards,
Raja











This message contains information that may be privileged or confidential and
is the property of the Capgemini Group. It is
intended only for the person to whom it is addressed. If you are not the
intended recipient, you are not authorized to
read, print, retain, copy, disseminate, distribute, or use this message or any
part thereof. If you receive this message
in error, please notify the sender immediately and delete all copies of this
message.

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.