RE: [xsl] NaN

Subject: RE: [xsl] NaN
From: "Sathasivam, Elayaraja" <elayaraja.sathasivam@xxxxxxxxxxxxx>
Date: Tue, 9 Sep 2008 12:37:18 +0530
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: [xsl] 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: [xsl] 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