Skip to content

Regression in Schematron Validation After Upgrading to ph-schematron-pure 8.0.3 #185

@magdakw

Description

@magdakw

Description
After upgrading ph-schematron-pure from 7.1.3 to 8.0.3, we encountered issues with specific Schematron definitions. The behavior of certain validation rules has changed unexpectedly.

Minimal Reproducible Example
Consider the following Schematron definition:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
        xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
        queryBinding="xslt2">
    <title>EN16931 model bound to UBL</title>
    <ns prefix="ext" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"/>
    <ns prefix="cbc" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"/>
    <ns prefix="ubl" uri="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"/>
    <ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>

    <pattern xmlns="http://purl.oclc.org/dsdl/schematron" id="Check-Country">
        <let name="ISO-3166-RO-CODES" value="('AA','BB','BT','RO-CT','RO-BC')"/>
        <rule context="/ubl:Invoice">
            <report test="not(normalize-space(cbc:Country) = ('AA','BB','BT','RO-CT','RO-BC'))"
                    flag="fatal"
                    id="REG1">
                Error Entity1
            </report>
            <report test="not(normalize-space(cbc:Country) = $ISO-3166-RO-CODES)"
                    flag="fatal"
                    id="REG2">
                Error entity2
            </report>
        </rule>
    </pattern>
</schema>

And the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
         xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
                <cbc:Country>BB</cbc:Country>
</Invoice>

Observed Behavior

  • In ph-schematron-pure 7.1.3:
    • Both REG1 and REG2 passed successfully.
  • In ph-schematron-pure 8.0.3:
    • REG1 still passes.
    • REG2 fails when <cbc:Country>BB</cbc:Country>.
    • However, if we change <cbc:Country>BB</cbc:Country> to <cbc:Country>AA</cbc:Country>, both REG1 and REG2 pass again.

Possible Cause
It seems that the handling of variables in Schematron expressions has changed in version 8.0.3. Specifically:

The variable $ISO-3166-RO-CODES is defined as a list:

  <let name="ISO-3166-RO-CODES" value="('AA','BB','BT','RO-CT','RO-BC')"/>

but may not be interpreted as an XPath sequence in the new version.

The expression

normalize-space(cbc:Country) = $ISO-3166-RO-CODES

might be evaluated incorrectly due to changes in how lists are processed in XPath/XSLT2 within ph-schematron-pure.

Constraints
We cannot modify the Schematron file because it is officially published by a government authority.

Expected Behavior
The validation logic should remain consistent between versions, or at least clear documentation should be provided regarding changes in variable handling.

Request for Help
Is there a known change in how variables containing lists are evaluated in version 8.0.3?
Is there a recommended workaround for handling such cases without modifying the original Schematron definition?
Any guidance or clarification would be greatly appreciated!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions