?
Solved

XSLT - 0

Posted on 2011-05-11
8
Medium Priority
?
299 Views
Last Modified: 2012-05-11
Hi Guys,

Thank you for taking the time to read my question, your help is most appreciated.

I have the following line of code:

<xsl:value-of select="format-number(sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_agency)*-1 + sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_client)*-1,'###,###')"/>

and was wondering if there was a way that if it =0 that it just puts a zero rather than a -0?

Again your help is most appreciated!!
0
Comment
Question by:mavmanau
  • 4
  • 2
  • 2
8 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 35736735
Try this:

<xsl:value-of select="format-number(sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_agency)*(-1) + sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_client)*(-1),'###,###')"/>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35737019
It doesn't have anything to do with adding () or not
Priority rules in mathematical expressions make it equivalent and processors should not make a difference between the original XSLT and what Bardobrave posted

What you see happening is as follows
you force the result of the sums in a certain format with maximum three digits after the comma
the -0 indicates that the result is negative, but so small it can not be expressed properly since it is too close to zero

-0 means here eg -000000000.1

You could do one of the following
multiply with 1000, floor, div 1000
or
test the string result for '-0' end put '0' instead

both are easy, but if you need help with the code let me know

I would by the way rewrite your XSLT as follows
    <xsl:value-of select="format-number(-sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_agency) -sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_client) ,'###,###')"/>
it will not take away the '-0' but it is nicer
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 35737070
floor will not work because floor of -0.00000000001 = -0

try this
    <xsl:variable name="interim-result" select="format-number(-sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_agency) -sum($scplst11[$filterClientRowid = Client_row_id]/tr_to_client) ,'###,###')"></xsl:variable>
    <xsl:choose>
        <xsl:when test="string($interim-result) = '-0'">
         <xsl:text>0</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$interim-result"/>
        </xsl:otherwise>
    </xsl:choose>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Bardobrave
ID: 35737106
My XSLT is very rusty, but, if there is some absolute value function you can try it with those near 0 values. Beware of truly negative values if your calculation is able to produce them.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35737846
"Beware of truly negative values"

my point is exactly that it must be "truly negative" in order to render a "-0"
0
 

Author Comment

by:mavmanau
ID: 35743412
what do you mean by truly negative...as in there is a number there??

I am going to try your code with the interimresult variable in there.....as there are other parts of the code that also use that same value to do results and the XSL was throwing back infinity results.  

Would that be why NaN results are coming back as well as the infinity's?

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35743961
"truly negative" = not reamy minus zero but realy a negative number

NaN results are not infinity
one will be "NaN" and the other "infinity" (or "-infinity")
0
 

Author Closing Comment

by:mavmanau
ID: 35782479
Thank you very much for the assist.  Worked perfectly.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question