Schematron: Support for validation
Posted: Wed Jun 09, 2021 3:58 pm
Hi,
I am not 100% sure that this is the right forum but I hope to find help
My problem is that an addition of multiple totals end up in a very tiny number (-1.8189894035458565E-12) rather than 0 (In XSLT 1.0 every number is treated as double and when adding decimal, numbers rounding occurs). I then format the result ##.00 to ensure 0, but MSXML and Saxon handle format-number different where Saxon is that format-numb keeps the sign even if the result is 0, so I end up with matching 0 = -0 and my test fail.
I have built the XLS “Function” below that will handled the problem but I can’t work out how to build a Schematron “function” that will be do the same when transformed into XLS. Can anybody help ?
<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>
<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">………
/Dan Overgaard
I am not 100% sure that this is the right forum but I hope to find help
My problem is that an addition of multiple totals end up in a very tiny number (-1.8189894035458565E-12) rather than 0 (In XSLT 1.0 every number is treated as double and when adding decimal, numbers rounding occurs). I then format the result ##.00 to ensure 0, but MSXML and Saxon handle format-number different where Saxon is that format-numb keeps the sign even if the result is 0, so I end up with matching 0 = -0 and my test fail.
I have built the XLS “Function” below that will handled the problem but I can’t work out how to build a Schematron “function” that will be do the same when transformed into XLS. Can anybody help ?
<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>
<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">………
/Dan Overgaard