XML technologies / Schematron / SVRL / Structure

(Excerpt from "Schematron - Effiziente Business Rules für XML-Dokumente", chapter 9)

Errors can be described precisely because SVRL structures represent useful additional information as well as the messages themselves.

Annex D of the ISO standard for Schematron describes SVRL’s structure as a RELAX NG schema. Earlier examples showed the final transformation’s output as XTHML or plain text. Here is an illustrative example:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
  <title>Schematron für Noah</title>
  <p>Dieses Schematron soll Noah helfen, die richtigen Tiere in der adäquaten Umgebung unterzubringen.</p>
  <ns uri="http://www.schematron.info/arche" prefix="arc"/>
  <phase id="alles">
    <active pattern="arche"/>
    <active pattern="noah"/>
  </phase>
  <pattern id="arche">
    <rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]">
      <report test="arc:tier[@fleischfresser='ja']">Es gibt Fleischfresser und Pflanzenfresser in einer Unterkunft. Die Tiere sind keine Nahrungsquelle!</report>
    </rule>
  </pattern>
  <pattern id="noah">
    <rule context="arc:tier">
      <let name="tierart" value="arc:art"/>
      <report test="count(parent::*/arc:tier[arc:art=$tierart]) &gt; 2" diagnostics="Anzahl">In dieser Unterkunft gibt es mehr als zwei Tiere dieser Art (<value-of select="arc:art"/>).</report>
      <assert test="not(count(parent::*/arc:tier[arc:art=$tierart]) &lt; 2)">In dieser Unterkunft gibt es kein Paar dieser Art (<value-of select="arc:art"/>).</assert>
    </rule>
  </pattern>
  <diagnostics>
    <diagnostic id="Anzahl">Noah, du hast <value-of select="count(parent::*/arc:tier[arc:art=$tierart])"/> Tiere von der Gattung <value-of select="arc:art"/>.</diagnostic>
  </diagnostics>
</schema>

Here is the resulting SVRL file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svrl:schematron-output xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:arc="http://www.schematron.info/arche" xmlns:svrl="http://purl.oclc.org/dsdl/svrl" title="Schematron für Noah" schemaVersion="">
  <svrl:text>Dieses Schematron soll Noah helfen, die richtigen Tiere in der adäquaten Umgebung unterzubringen.</svrl:text>
  <svrl:ns-prefix-in-attribute-values uri="http://www.schematron.info/arche" prefix="arc"/>
  <svrl:active-pattern id="arche" name="arche"/>
  <svrl:fired-rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]"/>
  <svrl:successful-report test="arc:tier[@fleischfresser='ja']" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]">
    <svrl:text>Es gibt Fleischfresser und Pflanzenfresser in einer Unterkunft. Die Tiere sind keine Nahrungsquelle!</svrl:text>
  </svrl:successful-report>
  <svrl:fired-rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]"/>
  <svrl:active-pattern id="noah" name="noah"/>
  <svrl:fired-rule context="arc:tier"/>
  <svrl:successful-report test="count(parent::*/arc:tier[arc:art=$tierart]) &gt; 2" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]/*:tier[namespace-uri()='http://www.schematron.info/arche'][1]">
    <svrl:text>In dieser Unterkunft gibt es mehr als zwei Tiere dieser Art (Zebra). <svrl:diagnostic-reference diagnostic="Anzahl" id="Anzahl">Noah, du hast 3 Tiere von der Gattung Zebra.</svrl:diagnostic-reference></svrl:text>
  </svrl:successful-report>
  …
  <svrl:fired-rule context="arc:tier"/>
  <svrl:fired-rule context="arc:tier"/>
</svrl:schematron-output>

An SVRL document’s root element is <svrl:schematron-output>. Three attributes are available here. Attribute title may contain the text of Schematron element <title>. Attribute phase has not yet been precisely specified, but would probably contain the name of the selected <phase>. Attribute schemaVersion takes the value of the same-named attribute on Schematron root element <schema>.

There are also optional elements <svrl:text> and <svrl:ns-prefix-in-attribute-values>. <svrl:text> contains the content of <p>; <svrl:ns-prefix-in-attribute-values> corresponds to Schematron element <ns>.

Thus,

<ns uri="http://www.schematron.info/arche" prefix="arc"/>

becomes the following in SVRL:

<svrl:ns-prefix-in-attribute-values uri="http://www.schematron.info/arche" prefix="arc"/>

Element <svrl:active-pattern> identifies the patterns active in this phase.

This evaluates element <active>. Both attributes id and name receive the value of attribute pattern on <active>. All subsequent <svrl:fired-rule> elements up to the next <svrl:active-pattern> belong to this group. If no <active> was used, <svrl:active-pattern> is output without attributes, since it is mandatory.

Central element <svrl:fired-rule> is output whenever a rule matches. In our ark example, this happens whenever the context attribute of element <rule> matches.

<rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]">

The <svrl:fired-rule> also has a context attribute, into which the <rule>-context attribute’s content is copied, as shown here:

<svrl:fired-rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]"/>

Elements <svrl:failed-assert> and <svrl:successful-report> are generated whenever element <assert> or <report> becomes active, respectively. Both have attribute test showing the XPath expression, depending on whether <assert> or <report> is used, copying the content of the test attributes. Attribute location holds the exact position of the assertion or error message, preferably as an absolute XPath expression.

Here is an example:

<svrl:successful-report test="arc:tier[@fleischfresser='ja']" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]">

Within <svrl:failed-assert> and <svrl:successful-report>, descriptive text originating from <assert> or <report> is output in a <svrl:text>.

<svrl:failed-assert test="not(count(parent::*/arc:tier[arc:art=$tierart]) &lt; 2)" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]/*:tier[namespace-uri()='http://www.schematron.info/arche'][4]">
  <svrl:text>In dieser Unterkunft gibt es kein Paar dieser Art (Zebra).</svrl:text>
</svrl:failed-assert>

Element <svrl:diagnostic-reference> contains the content of <diagnostic>, referenced through an ID in Schematron.

Here is an example:

<svrl:diagnostic-reference diagnostic="Anzahl" id="Anzahl">Noah, du hast 3 Tiere von der Gattung Zebra.</svrl:diagnostic-reference>

Since this content depends on <assert> or <report> , its text appears here and any <value-of> elements are resolved.

   

 

 

 

back to top