Schematron: Support for validation

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

Schematron: Support for validation

Post by DanOvergaard » 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

tavy
Posts: 284
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron: Support for validation

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

Hello,

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 (xsl-list@lists.mulberrytech.com), There are several XSL experts who can answer there, and also I am registered on the list and can answer.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

DanOvergaard
Posts: 5
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)
    OIOUBL_Codelist_Schematron.xml
    OIOUBL_Common_Schematron.xml
The XSL file that is used to validate the
  • OIOUBL_Invoice_Schematron.xsl
Test files
  • FromNemHandel.xml
    INV_LegalMonetaryTotal-PayableRoundingAmount_BZ1710.xml
    OIOUBL_Invoice_PayableAmount_0=-0_BZ1465.xml
Fles.zip
(185.99 KiB) Downloaded 12 times

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


Note
I have also send a mail to xsl-list@lists.mulberrytech.com as you suggested
Fles.zip
(185.99 KiB) Downloaded 11 times

tavy
Posts: 284
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron: Support for validation

Post by tavy » Fri Jun 18, 2021 4:21 pm

Hello,

Unfortunately, it is hard for me to understand the examples. I tried to make some simple examples but they seem work in Oxygen. If you could create some simple examples that can be run in Oxygen XML Editor , and reproduce the issue you reported, I will try to debug them.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

DanOvergaard
Posts: 5
Joined: Thu Jan 07, 2021 10:44 am

Re: Schematron: Support for validation

Post by DanOvergaard » Fri Jul 02, 2021 3:41 pm

Hi Octavian,

Sorry for my late reply, but I have been assigned to other more pressing issues :-)

I will come back with some simplified examples, but not until late August.

So shall I close the case and create a new at that time or keep this open ?


Best regards
Dan

Radu
Posts: 7535
Joined: Fri Jul 09, 2004 5:18 pm

Re: Schematron: Support for validation

Post by Radu » Mon Jul 05, 2021 6:53 am

Hi Dan,

Octavian took a few days off, there's no problem in you coming back when you have some small samples for this.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply