|
next
|
Subject: Problem with SAXO processor - XSLT test Author: Ivan Pedruzzi Date: 28 Aug 2020 01:16 PM Originally Posted: 27 Aug 2020 10:02 PM
|
Function format-number behaves differently across XSLT processors.
In XSLT 1.0 every number is treated as double and when adding decimal, numbers rounding occurs.
The following expression with your input does not return 0 but, rather -1.8189894035458565E-12, which is a very tiny number but not 0.
When multiply by -1 and formatted as ##.00 you get 0
sum(cbc:LineExtensionAmount) +
sum(../cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount) +
sum(cbc:ChargeTotalAmount) -
sum(cbc:AllowanceTotalAmount) -
sum(cbc:PrepaidAmount) +
sum(cbc:PayableRoundingAmount)
The following expression return -.00 which does not match the above result, therefore your = operator returns false.
format-number( sum(cbc:PayableAmount) * -1,'##.00')
The difference between MSXML and Saxon is that format-number keeps the sign even if the result is 0, you can try this simple test.
<xsl:value-of select="format-number( -0.00,'##.00')"/>
Saxon interprets the specification correctly but MSXML behaves more practically.
If you are restricted to XSLT 1.0 one possibility is to create a user defined template which wraps format-number as following
<xsl:template name="format-number">
<xsl:param name="number"/>
<xsl:param name="format"/>
<xsl:choose>
<xsl:when test="$number = -0">
<xsl:value-of select="format-number(0, $format)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($number, $format)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Your code will look like this
<xsl:variable name="A">
<xsl:call-template name="format-number">
<xsl:with-param name="number" select="sum(cbc:PayableAmount)"/>
<xsl:with-param name="format" select="'##.00'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="B">
<xsl:call-template name="format-number">
<xsl:with-param name="number" select="
format-number(
(
sum(cbc:LineExtensionAmount) +
sum(../cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount) +
sum(cbc:ChargeTotalAmount) -
sum(cbc:AllowanceTotalAmount) -
sum(cbc:PrepaidAmount) +
sum(cbc:PayableRoundingAmount)
) * -1
,'##.00')"/>
<xsl:with-param name="format" select="'##.00'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$A = $B">
....
Does it help?
Ivan Pedruzzi
Stylus Studio Team
|
|
|