Search Posts

Visits: 275

Comment from Mr. Oriol Bausà on 2022-02-27.

There was an additional idea behind this architecture: the possibility to use different syntaxes to implement the same rules. In the EN, this was a must, as the EN shall be implemented in UBL and CII (at a certain point, there was an EDI implementation as well).

So the rules are defined by business experts in natural prose. And the Schematron experts shall implement the XPath expressions to support the requirements expressed in the text rules.


CEF’s GitHub EN16931 Validation artifacts v.1.3.2 is maintained by Oriol and these files have interesting characteristics by defining abstract business rule definition and schematron implementation.

Directory structure

The schematron directory is configured to read the abstract definition under the abstract directory using variables and then the variable definitions are expanded in schematron script definition under the UBL directory.

.
schematron
├── EN16931-UBL-validation.sch
├── UBL
│   ├── EN16931-UBL-model.sch
│   └── EN16931-UBL-syntax.sch
├── abstract
│   ├── EN16931-model.sch
│   └── EN16931-syntax.sch
├── codelist
│   └── EN16931-UBL-codes.sch
└── preprocessed
    └── EN16931-UBL-validation-preprocessed.sch

An abstract definition

The following is the excerpt from abstract/EN16931-model.sch file.
The first line declares attributes abstract=”true”and id=”model” meaning this definition is abstract and expanded later by replacing variables.

<pattern xmlns=”http://purl.oclc.org/dsdl/schematron” abstract=”true” id=”model”>

<pattern> element contains several <rule> elements.
The <rule> element declares <assert> element specifying validation rule.
<context> element uses variable $Amount_due and <assert> element uses variable $BR-CO-25.
By not specifying a distinct XPath definition in the abstract file, it is easier for business experts to define business rules without knowing technical detail. And resulting abstract rule definition is much more easier to read and check for the business experts.

The variables with prefixed “$” character is later expanded with <param> element definition in files located under UBL directory.

<pattern xmlns="http://purl.oclc.org/dsdl/schematron" abstract="true" id="model">
...
  <rule context="$Amount_due">
    <assert test="$BR-CO-25" flag="fatal" id="BR-CO-25">[BR-CO-25]-In case the Amount due for payment (BT-115) is positive, either the Payment due date (BT-9) or the Payment terms (BT-20) shall be present.</assert>
  </rule>
  <rule context="$Buyer_electronic_address">
    <assert test="$BR-63" flag="fatal" id="BR-63">[BR-63]-The Buyer electronic address (BT-49) shall have a Scheme identifier.    </assert>
  </rule>
...

XPath definition in Schematron file

The following is the excerpt from UBL/EN16931-UBL-model.sch file.

Substitution targets are declared using XPath definition and XSLT function by specifying the @is-a attributes in the <pattern> element. This value corresponds to the @id attribute value of <pattern> element in abstract files.

The contents of test=”$BR-CO-25″ specified in the & lt;assert> element of the abstract file are mapped to the @name attribute of the & lt;param> element on replacement. “BR-CO-25” is also mapped.

We specify variable with attribute prefixed “$” in an abstract file and describe the definition to be replaced by specifying XPath in the @value attribute and defining the condition to be satisfied as a test parameter.

<pattern xmlns="http://purl.oclc.org/dsdl/schematron" is-a="model" id="UBL-model">
  <param name="Amount_due" value="/ubl:Invoice/cac:LegalMonetaryTotal/cbc:PayableAmount "/>
  <param name="BR-CO-25" value="((. &gt; 0) and (exists(//cbc:DueDate) or exists(//cac:PaymentTerms/cbc:Note))) or (. &lt;= 0)"/>
  <param name="Buyer_electronic_address" value="cac:AccountingCustomerParty/cac:Party/cbc:EndpointID"/>
  <param name="BR-63" value="exists(@schemeID)"/>
...

Expanded result in preprocessed file

The following is the excerpt from preprocessed/EN16931-UBL-validation-preprocessed.sch file.
This is the result of substituting the param definition of the UBL definition file into the abstract file.
Preprocessed schematron script file is the result of substituting abstract definition with parameters values.

By separating the abstract definition from the XPath definition in a particular file part, these files have a clearer definition.
We can use the files under the UBL directory as a pool of rules, and we can use these parameter elements with @name in the abstract rules file to achieve our requirements.

Files under UBL directory is the Pool/template rules and the business experts can select and define theire business requirements using these predefined parameters.

...
  <pattern id="UBL-model">
...
    <rule context="/ubl:Invoice/cac:LegalMonetaryTotal/cbc:PayableAmount">
      <assert id="BR-CO-25" flag="fatal" test="((. > 0) and (exists(//cbc:DueDate) or exists(//cac:PaymentTerms/cbc:Note))) or (. &lt;= 0)">[BR-CO-25]-In case the Amount due for payment (BT-115) is positive, either the Payment due date (BT-9) or the Payment terms (BT-20) shall be present.</assert>
    </rule>
 ...
    <rule context="cac:AccountingCustomerParty/cac:Party/cbc:EndpointID">
      <assert id="BR-63" flag="fatal" test="exists(@schemeID)">[BR-63]-The Buyer electronic address (BT-49) shall have a Scheme identifier.    </assert>
    </rule>
...

(The photo was taken in Moscow in 2017 when I attended ISO/PC295 plenary meeting as a head of delegate from JISC.)