{"id":5598,"date":"2022-01-12T09:25:57","date_gmt":"2022-01-12T00:25:57","guid":{"rendered":"https:\/\/www.sambuichi.jp\/?p=5598"},"modified":"2022-02-28T18:25:12","modified_gmt":"2022-02-28T09:25:12","slug":"schematron","status":"publish","type":"post","link":"https:\/\/www.sambuichi.jp\/?p=5598&lang=en","title":{"rendered":"Pool\/template rules with abstract Schematron"},"content":{"rendered":"<p>Views: 61<\/p><p>Comment from Mr. Oriol Baus\u00e0 on 2022-02-27.<\/p>\n<p>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).<\/p>\n<p>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.<\/p>\n<hr>\n<p>CEF&#8217;s GitHub <a href=\"https:\/\/github.com\/ConnectingEurope\/eInvoicing-EN16931\/releases\/tag\/validation-1.3.2\">EN16931 Validation artifacts v.1.3.2 <\/a> is maintained by Oriol and these files have interesting characteristics by defining abstract business rule definition and schematron implementation.<\/p>\n<h2>Directory structure<\/h2>\n<p>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.<\/p>\n<pre class=\"lang:default decode:true \" title=\"eInvoicing-EN16931-validation-1.3.2\/ubl\" >.\r\nschematron\r\n\u251c\u2500\u2500 EN16931-UBL-validation.sch\r\n\u251c\u2500\u2500 UBL\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 EN16931-UBL-model.sch\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 EN16931-UBL-syntax.sch\r\n\u251c\u2500\u2500 abstract\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 EN16931-model.sch\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 EN16931-syntax.sch\r\n\u251c\u2500\u2500 codelist\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 EN16931-UBL-codes.sch\r\n\u2514\u2500\u2500 preprocessed\r\n    \u2514\u2500\u2500 EN16931-UBL-validation-preprocessed.sch\r\n<\/pre>\n<h2>An abstract definition<\/h2>\n<p>The following is the excerpt from abstract\/EN16931-model.sch file.<br \/>\nThe first line declares attributes abstract=&#8221;true&#8221;and id=&#8221;model&#8221; meaning this definition is abstract and expanded later by replacing variables.<\/p>\n<p>&lt;pattern xmlns=&#8221;http:\/\/purl.oclc.org\/dsdl\/schematron&#8221; abstract=&#8221;true&#8221; id=&#8221;model&#8221;> <\/p>\n<p>&lt;pattern> element contains several &lt;rule> elements.<br \/>\nThe &lt;rule> element declares &lt;assert> element specifying validation rule.<br \/>\n&lt;context> element uses variable $Amount_due and &lt;assert> element uses variable $BR-CO-25.<br \/>\nBy 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.<\/p>\n<p>The variables with prefixed \u201c$\u201d character is later expanded with &lt;param> element definition in files located under UBL directory.<\/p>\n<pre class=\"width-set:true lang:xhtml decode:true \" title=\"abstract\/EN16931-model.sch\" >&lt;pattern xmlns=\"http:\/\/purl.oclc.org\/dsdl\/schematron\" abstract=\"true\" id=\"model\"&gt;\r\n...\r\n  &lt;rule context=\"$Amount_due\"&gt;\r\n    &lt;assert test=\"$BR-CO-25\" flag=\"fatal\" id=\"BR-CO-25\"&gt;[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.&lt;\/assert&gt;\r\n  &lt;\/rule&gt;\r\n  &lt;rule context=\"$Buyer_electronic_address\"&gt;\r\n    &lt;assert test=\"$BR-63\" flag=\"fatal\" id=\"BR-63\"&gt;[BR-63]-The Buyer electronic address (BT-49) shall have a Scheme identifier.    &lt;\/assert&gt;\r\n  &lt;\/rule&gt;\r\n...<\/pre>\n<h2>XPath definition in Schematron file<\/h2>\n<p>The following is the excerpt from UBL\/EN16931-UBL-model.sch file.<\/p>\n<p>Substitution targets are declared using XPath definition and XSLT function by specifying the @is-a attributes in the &lt;pattern> element. This value corresponds to the @id attribute value of &lt;pattern> element in abstract files.  <\/p>\n<p>The contents of test=&#8221;$BR-CO-25&#8243; specified in the &#038; lt;assert> element of the abstract file are mapped to the @name attribute of the &#038; lt;param> element on replacement. &#8220;BR-CO-25&#8221; is also mapped.<\/p>\n<p>We specify variable with attribute prefixed &#8220;$&#8221; 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.<\/p>\n<pre class=\"width-set:true lang:xhtml decode:true \" title=\"UBL\/EN16931-UBL-model.sch\" >&lt;pattern xmlns=\"http:\/\/purl.oclc.org\/dsdl\/schematron\" is-a=\"model\" id=\"UBL-model\"&gt;\r\n  &lt;param name=\"Amount_due\" value=\"\/ubl:Invoice\/cac:LegalMonetaryTotal\/cbc:PayableAmount \"\/&gt;\r\n  &lt;param name=\"BR-CO-25\" value=\"((. &amp;gt; 0) and (exists(\/\/cbc:DueDate) or exists(\/\/cac:PaymentTerms\/cbc:Note))) or (. &amp;lt;= 0)\"\/&gt;\r\n  &lt;param name=\"Buyer_electronic_address\" value=\"cac:AccountingCustomerParty\/cac:Party\/cbc:EndpointID\"\/&gt;\r\n  &lt;param name=\"BR-63\" value=\"exists(@schemeID)\"\/&gt;\r\n...<\/pre>\n<h2>Expanded result in preprocessed file<\/h2>\n<p>The following is the excerpt from preprocessed\/EN16931-UBL-validation-preprocessed.sch file.<br \/>\nThis is the result of substituting the param definition of the UBL definition file into the abstract file.<br \/>\nPreprocessed schematron script file is the result of substituting abstract definition with parameters values.<\/p>\n<p>By separating the abstract definition from the XPath definition in a particular file part, these files have a clearer definition.<br \/>\nWe 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.<\/p>\n<p>Files under UBL directory is the Pool\/template rules and the business experts can select and define theire business requirements using these predefined parameters.<\/p>\n<pre class=\"width-set:true lang:xhtml decode:true \" title=\"preprocessed\/EN16931-UBL-validation-preprocessed.sch\" >...\r\n  &lt;pattern id=\"UBL-model\"&gt;\r\n...\r\n    &lt;rule context=\"\/ubl:Invoice\/cac:LegalMonetaryTotal\/cbc:PayableAmount\"&gt;\r\n      &lt;assert id=\"BR-CO-25\" flag=\"fatal\" test=\"((. &gt; 0) and (exists(\/\/cbc:DueDate) or exists(\/\/cac:PaymentTerms\/cbc:Note))) or (. &amp;lt;= 0)\"&gt;[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.&lt;\/assert&gt;\r\n    &lt;\/rule&gt;\r\n ...\r\n    &lt;rule context=\"cac:AccountingCustomerParty\/cac:Party\/cbc:EndpointID\"&gt;\r\n      &lt;assert id=\"BR-63\" flag=\"fatal\" test=\"exists(@schemeID)\"&gt;[BR-63]-The Buyer electronic address (BT-49) shall have a Scheme identifier.    &lt;\/assert&gt;\r\n    &lt;\/rule&gt;\r\n...<\/pre>\n<p>(The photo was taken in Moscow in 2017 when I attended ISO\/PC295 plenary meeting as a head of delegate from JISC.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Views: 61Comment from Mr. Oriol Baus\u00e0 on 2022-02-27. There was an additional idea behind this architecture: th [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4869,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[57],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/5598"}],"collection":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5598"}],"version-history":[{"count":20,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/5598\/revisions"}],"predecessor-version":[{"id":6041,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/5598\/revisions\/6041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/media\/4869"}],"wp:attachment":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}