xsl-list
[Top] [All Lists]

RE: [xsl] NaN

2008-09-09 03:06:35


Thanks Scott. It's working perfect.


Regards,
Raja 
_________________________________________________________________
-----Original Message-----
From: Scott Trenda [mailto:Scott(_dot_)Trenda(_at_)oati(_dot_)net] 
Sent: Tuesday, September 09, 2008 12:11 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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[(_at_)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[(_at_)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(_at_)lists(_dot_)mulberrytech(_dot_)com
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[(_at_)Id='77' and @Type='5' 
and  (_at_)PT='P']/@Amount + SAPCreditItem/@CreditAmount"/>

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

I tried with, <xsl:variable name="total" select="Charge[(_at_)Id='77' and 
@Type='5' and  (_at_)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.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>