XSLT - 0

Posted on 2011-05-11
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!!
Question by:mavmanau
    LVL 19

    Expert Comment

    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),'###,###')"/>
    LVL 60

    Expert Comment

    by:Geert Bormans
    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
    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
    LVL 60

    Accepted Solution

    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:when test="string($interim-result) = '-0'">
                <xsl:value-of select="$interim-result"/>
    LVL 19

    Expert Comment

    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.
    LVL 60

    Expert Comment

    by:Geert Bormans
    "Beware of truly negative values"

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

    Author Comment

    what do you mean by truly in there is a number there??

    I am going to try your code with the interimresult variable in 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?

    LVL 60

    Expert Comment

    by:Geert Bormans
    "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")

    Author Closing Comment

    Thank you very much for the assist.  Worked perfectly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    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…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now