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

Re: A - B

Subject: Re: A - B
From: "Marrow" <marrow@xxxxxxxxxxxxxx>
Date: Mon, 26 Aug 2002 10:59:24 +0100
decimal format nan
Hi,

Michael's format number solution was far better - and should work...

For example,

== XML ===============================
<?xml version="1.0"?>
<root>
  <A>37</A>
  <B/>
</root>
== end of XML ==========================

== XSL1 ===============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:decimal-format NaN="0"/>
<xsl:template match="/">
  <xsl:value-of select="format-number(root/A[1],'#.########') -
format-number(root/B[1],'#.########')"/>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 ==========================

will result in 37 as expected.

Or using sum() and checking that the node value actually represents a numeric
value, e.g.

== XSL2 ===============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
  <xsl:value-of select="sum(root/A[1][number(.) = number(.)]) -
sum(root/B[1][number(.) = number(.)])"/>
</xsl:template>
</xsl:stylesheet>
== end of XSL2 ==========================

should also result in 37.

Cheers
Marrow

-----Original Message-----
From: pcoustillas <pcoustillas@xxxxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Date: 26 August 2002 08:25
Subject: Re:  A - B


>  thanks, but if i have this XML :
><A>37</A>
><B/>
>
>and my XSL :
><xsl:decimal-format NaN="0" name="forme1" decimal-separator=","
>grouping-separator=" " />
>
>the result is 0 but i expect 37. i've been suggested to use
><xsl:value-of select="format-number(concat('0',11) - concat('0',1), '#
>##0,00','forme1')" />
>
>or
>
><xsl:value-of select="format-number(number(concat('0',11)) -
>number(concat('0',1)), '#  ##0,00','forme1')" />
>but it is a bit complicated... isn't there something more simple...
>
>To Marrow : i faced troubles while using sum with the tag <B/> i revieve
>"NaN"
>
>other suggestions ??
>
>Thank.
>
>Michael Leditschke a écrit:
>
>>Typically there's some special value you want
>>in the case where A and/or B don't exist or
>>are not numeric.
>>
>>One trick I've used in this case is
>>
>><xsl:decimal-format NaN="0"/>
>>
>>and
>>
>><xsl:variable name="fred" select="format-number(A-B)"/>
>>
>>This way you get "0" if the result is NaN.
>>
>>HTH
>>Michael
>>
>>
>>
>>>-----Original Message-----
>>>From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>>>[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of pcoustillas
>>>Sent: Friday, 23 August 2002 1:44 AM
>>>To: mulberrytech
>>>Subject:  A - B
>>>
>>>
>>>hi, how could i do A-B when A or B does not exist or is absent...
>>>because without a test i recieve "NaN". Thanks.
>>>
>>>
>>> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>>>
>>>
>>>
>>>
>>
>>
>> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>>
>>
>>
>
>
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Current Thread
  • Re: A - B, (continued)
    • Mike Brown - Thu, 22 Aug 2002 13:39:01 -0400 (EDT)
    • Michael Leditschke - Thu, 22 Aug 2002 20:07:56 -0400 (EDT)
    • Marrow - Thu, 22 Aug 2002 14:10:44 -0400 (EDT)
    • Marrow - Mon, 26 Aug 2002 06:03:02 -0400 (EDT) <=

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.