Schematron: Support for validation

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 4
Joined: Thu Jan 07, 2021 10:44 am

Schematron: Support for validation

Post by DanOvergaard » Wed Jun 09, 2021 3:58 pm


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:when test="$number = -0">
<xsl:value-of select="format-number(0, $format)"/>
<xsl:value-of select="format-number($number, $format)"/>
<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:variable name="B">
<xsl:call-template name="format-number">
<xsl:with-param name="number" select="
sum(cbc:LineExtensionAmount) +
sum(../cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount) +
sum(cbc:ChargeTotalAmount) -
sum(cbc:AllowanceTotalAmount) -
sum(cbc:PrepaidAmount) +
) * -1
<xsl:with-param name="format" select="'##.00'"/>

<xsl:when test="$A = $B">………

/Dan Overgaard

Posts: 280
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron: Support for validation

Post by tavy » Fri Jun 11, 2021 10:07 am


I can try to help you if you provide more information in order to reproduce the problem: What version of Oxygen do you use? What version of Saxon do you use for transformation? Maybe you can send also a sample XML file.

I recommend you to write on the XSL List (, There are several XSL experts who can answer there, and also I am registered on the list and can answer.

Best Regards,
Octavian Nadolu
<oXygen/> XML Editor

Posts: 4
Joined: Thu Jan 07, 2021 10:44 am

Re: Schematron: Support for validation

Post by DanOvergaard » Mon Jun 14, 2021 11:50 am

Hi Octavian,

Thanks for your feedback 😊

My challenge are that I don’t know how to solve the problem in the Schematron file – The file that is used to build the XSL-fil for validating. I need to find a logic that handle
  • The problem with SAXON vs .Net (not version specific), but that .Net see “-0 = 0” as TRUE where SASON see it a FALSE
    The problem with tiny numbers are - in XSLT 1.0 – is treated as double and when adding decimal, numbers rounding occurs.
So I need to match two variables where one of them are a sum of multiple values . The sum of the multiple values end up as a very tiny number (eg.: -1.8189894035458565E-12) that are negative. So I need to:
  • Ensure that the “sum” of the two valuables are formatted to ##.00
    Ensure the that the two values both have the same sign

I have attached the following files
The files that is used to build the XLS
  • OIOUBL_Invoice_Schematron.xml: The schematron file that build the XSL file below (The logic is found on line 1292)
The XSL file that is used to validate the
  • OIOUBL_Invoice_Schematron.xsl
Test files
  • FromNemHandel.xml
(185.99 KiB) Downloaded 1 time

Please let me know if it’s unclear what I try 😊

I have also send a mail to as you suggested
(185.99 KiB) Not downloaded yet

Post Reply