-1

I want to take absolute value of TaxAmount but I tried ABS function it is not working.Do you have any idea?

My version is 2.0. I try xml file on the Internet Explorer.

I want to display it as positive sometimes it can be negative or positive

<div style="float:left; width:100pt">
        <h2>                                           
        :<xsl:value-of select="format-number(cbc:TaxAmount,'#,##0.00', 'us')"/>
        </h2>
</div>
hagi10
  • 23
  • 7
  • https://stackoverflow.com/questions/804421/how-can-i-calculate-the-absolute-value-of-a-number-in-xslt Or make a variable which multiplies the value by -1 if its positive – Christian Mosz Feb 17 '20 at 11:41
  • Internet Explorer doesn't support xslt 2.0 so it won't recognize the abs() function. Easiest way in XSLT 1.0 is to convert it to a string, strip out any "-", then convert back to a number: `number(translate(string($x), '-', ''))`. (I've shown the conversions here by explicit functions but you can rely on implicit conversion if you prefer). – Michael Kay Feb 17 '20 at 11:53
  • @MichaelKay I tried your style but I got number format error. `: ` – hagi10 Feb 17 '20 at 15:02
  • Can't help you with that because you haven't given enough context, I would need to see a complete source document and complete stylesheet. – Michael Kay Feb 17 '20 at 15:49

1 Answers1

1

You can use abs() function

<xsl:value-of select="format-number(abs(cbc:TaxAmount),'#,##0.00', 'us')"/>

You can use if statement

<xsl:choose>
     <xsl:when test="cbc:TaxAmount < 0">
       <xsl:value-of select="format-number(cbc:TaxAmount * -1,'#,##0.00', 'us')"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="format-number(cbc:TaxAmount,'#,##0.00', 'us')"/>
     </xsl:otherwise>
   </xsl:choose>
bakero98
  • 805
  • 7
  • 18