Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Schematron is an XML-based language for validating XML instance documents. It is used to make assertions about data in an XML document and it is also used to express operational and business rules. Schematron is an ISO Standard. The schematron component uses the leading implementation of ISO schematron. It is an XSLT based implementation. The schematron rules is run through four XSLT pipelines, which generates a final XSLT which will be used as the basis for running the assertion against the XML document. The component is written in a way that Schematron rules are loaded at the start of the endpoint (only once) this is to minimise the overhead of instantiating a Java Templates object representing the rules.

URI format

Code Block
languagebash
schematron://path?[options]

...

Code Block
languagexml
<route>
   <from uri="direct:start" />
   <to uri="schematron:///usr/local/sch/schematron.sch" />
   <log message="Schematron validation status: ${in.header.CamelSchematronValidationStatus}" />
   <choice>
      <when>
         <simple>${in.header.CamelSchematronValidationStatus} == 'SUCCESS'</simple>
         <to uri="mock:success" />
      </when>
      <otherwise>
         <log message="Failed schematron validation" />
         <setBody>
            <header>CamelSchematronValidationReport</header>
         </setBody>
         <to uri="mock:failure" />
      </otherwise>
   </choice>
</route>

...

Schematron rules can change with business requirement, as such it is recommended to store these rules somewhere in file system. When the schematron component endpoint is started, the rules are compiled into XSLT as a  Java Template Object. This is done only once to minimise the overhead of instantiating Java Template object which can be an expensive operation for large set of rules and given that the process goes through four pipelines of XSLT transformations

Brief tutorial of schematron

...

Code Block
languagexml
titleschematron rules
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
   <title>Check Sections 12/07</title>
   <pattern id="section-check">
      <rule context="section">
         <assert test="title">This section has no title</assert>
         <assert test="para">This section has no paragraphs</assert>
      </rule>
   </pattern>
</schema>

 

Here is an example of schematron report:

Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:saxon="http://saxon.sf.net/" xmlns:schold="http://www.ascc.net/xml/schematron" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" schemaVersion="" title="">
   <!--

      -->
   <svrl:active-pattern document="" />
   <svrl:fired-rule context="chapter" />
   <svrl:failed-assert test="title" location="/doc[1]/chapter[1]">
      <svrl:text>A chapter should have a title</svrl:text>
   </svrl:failed-assert>
   <svrl:fired-rule context="chapter" />
   <svrl:failed-assert test="title" location="/doc[1]/chapter[2]">
      <svrl:text>A chapter should have a title</svrl:text>
   </svrl:failed-assert>
   <svrl:fired-rule context="chapter" />
</svrl:schematron-output>

Links to Schematron resources