Logical test in Schematron

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

Logical test in Schematron

Post by DanOvergaard »

Hi

I have a task to design a validation using schematron, but I can’t figure if it’s possible.

The validation is a two parts validation as following:
  • First, I need to ensure that variable 1 is converted to 0 if the original value is -0
  • Second, I need check if the value in the two variables are the same

I have the values in the following two variables
  • Variable 1: <sch:let name="PayableSum" value="format-number (sum(PayableAmount) ,'##.00')"/>
  • Variable 2: <sch:let name="TotalSum" value="format-number (sum(TotalAmout) ,'##.00')"/>

Question
How to “code” the logic below in “schematron” – if possible

If ("PayableSum" = -0) then
----Variable "AlteredPayableSum" = 0
Else
----Variable "AlteredPayableSum" = PayableSum


Final validation
  • <sch:assert test="$AlteredPayableSum = $TotalSum">The two amounts are not equal</sch:assert>


Hope somebody can help

Rgds,
Dan
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Logical test in Schematron

Post by tavy »

Hello Dan,

Probably you should not format the values before comparing them. A solution to compute the "AlteredPayableSum" is something like this:

Code: Select all

<sch:let name="PayableSum" value="sum(PayableAmount)"/>
<sch:let name="TotalSum" value="sum(TotalAmout)"/>
<sch:let name="AlteredPayableSum" value="if ($PayableSum = -0) then 0 else $PayableSum"/>
<sch:assert test="$AlteredPayableSum = $TotalSum">The two amounts are not equal</sch:assert>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

Re: Logical test in Schematron

Post by DanOvergaard »

Hi Octavian,

Thanks for your solution - it seams to work, but after conversion to XLST I get the following syntax error:

Error in expression if ($PayableSum = -0) then 0 else $PayableSum: Unknown system function: if

Is that because the transformation to XSLT enforce XSLT 1.0 ? If so is there a schematron solution for the test that can run XSLT 1.0

Best regards,
Dan
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Logical test in Schematron

Post by tavy »

Hello Dan,

You can change the XSLT/XPath version to 2.0 for Schematron by setting the queryBinding="xslt2" on the Schematron root..

If you want to use XSLT 1.0 I think you can change the value of the $AlteredPayableSum variable, something like this:

Code: Select all

<sch:let name="AlteredPayableSum">
    <xsl:choose>
        <xsl:when test="$PayableSum = -0">0</xsl:when>
        <xsl:otherwise><xsl:value-of select="$PayableSum"/></xsl:otherwise>
    </xsl:choose>
</sch:let>


Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

Re: Logical test in Schematron

Post by DanOvergaard »

Hi Octavian,

Thanks for your feedback - It gave my the hint to get it to work. I couldn't combined Schematron with XSL but a "clean" XSL variable definition did it
<xsl:variable name="AlteredPayableSum">
<xsl:choose>
<xsl:when test="$PayableSum = -.0">0</xsl:when>
<xsl:otherwise><xsl:value-of select="$PayableSum "/></xsl:otherwise>
</xsl:choose>
</xsl:variable>

Best regards,
Dan
Post Reply