The Run Schematron workflow action uses ISO Schematron 2016 to test for the presence or absence of patterns in XML documents.
A “Schematron” refers to a collection of one or more rules which contain tests. Schematrons are written in a form of XML, which makes it easy for people to understand and write.
One of the brilliant things about running a Schematron is that error messages can be customised to be human-readable. For example, you could use a Schematron to verify headings are nested correctly and write the error message to read as "
Incorrect heading order: Heading 3, Heading 4, Heading 5 or Heading 6 cannot
follow Heading 1."
TIP Since Content XML, the data format used by Typefi to encode content, is a type of XML, you can use the Run Schematron workflow action with Content XML documents too.
You can use a Schematron to validate:
- the content and structure of XML documents
- the presence or absence of attributes
- the content of attributes
- any co-occurring constraints
Validate the content and structure XML documents
Use a Schematron to validate the content and structure of your XML document. For example, you can check that headings are nested properly ("Does Heading 2 always follow Heading 1?"), or check for the presence or absence of elements ("Does every
<row> contain at least one
Validate the presence or absence of attributes
Use a Schematron to validate the presence or absence of attributes. For example, you can check that every Typefi Element has an ID ("Does every
<context> have an
Validate the content of attributes
Use a Schematron to validate the content of attributes. For example, you can check that every video in a document displays the video control buttons ("Does every
<video> have the
@autoplay attribute and is
@autoplay set to true?").
Validate any co-occurring constraints
Use a Schematron to validate any co-occurring constraints. For example, you can check if a Typefi Section contains a table; if so, the Typefi Section should contain a paragraph too ("Does this
<section> contain a
<table>? If so, does this
<section> also include a
Run a Schematron validation
|Input||Choose the Content XML or XML file to be validated.|
|Schematron||Choose the Schematron file (.sch) to test for the presence or absence of patterns. If left blank, a default Schematron that scans for invalid styles is applied.|
|Output||Enter the filename for the Schematron Validation Report Language (.svrl) report.|
|Parameters||Enter any optional parameters. For example, selecting a subset of patterns and only validating against those, or defining the active phase to be applied according to the state of a document within its lifecycle.
Example 1: Selecting a subset of patterns
You are validating an XML file that contains contact information for people in your organisation. At a minimum, each person should have a mobile phone number and first name listed in the XML file.
The XML file might look like this:
And the Schematron file has these defined parameters:
<!-- Externally passed parameters are declared globally --> <sch:let name="phone" /> <sch:let name="expected" />
These parameters are used in the Schematron assertions, which are used to specify the constraints that should be checked.
Then, you can pass the values for those parameters as
If there is no value set, then the default value is
Example 2: Defining the active phase
Typefi uses ph-schematron to convert the source Schematron file (.sch) to an XSLT script and apply this XSLT on the Input document (.xml or .cxml) to be validated.
You can define the active phase by passing in a parameter:
If a value is not set for the phase (
If a phase is not defined via a parameter, then the
If the Run Schematron workflow action fails, then the job in Typefi Server will also fail.