Tags

XProc and Calabash: part 2

XProc and Calabash: part 1

Validating with ISO Schematron

In XProc we have the optional step 'p:validate-with-schematron'.
It is defined as follows:

validate-with-schematrontaking al least two inputs: the xml file to be validated and the schematron schema and having two outputs: the result being a copy of the input and a report where all Schematron assertions and reports go.

So our XProc becomes, when the input XML file is supplied from the command-line:

<pipeline xmlns="http://www.w3.org/ns/xproc">    
<output port="report" primary="false">
<pipe port="report" step="schematron"/>
</output>
<validate-with-xml-schema>
<input port="schema">
<document href="test1.xsd"/>
</input>
</validate-with-xml-schema>
<validate-with-schematron name="schematron" assert-valid="true">
<input port="schema">
<document href="test1.sch"/>
</input>
</validate-with-schematron>
</pipeline>

A few words of explanation.

  • using the attribute assert-valid.
    When set to false, the input from this step is copied to the output.
    <test 
    xmlns:overheid="http://standaarden.overheid.nl/owms/3.5/xml/waardelijsten/"
    xsi:noNamespaceSchemaLocation="test1.xsd">
    <identifier scheme="overheid:Informatietype">vragens</identifier>
    </test>

    When set to true, an error is thrown to the output.

    Error  : Pipeline failed: err:XC0054: null  It is a dynamic error if the assert-valid option is true and any Schematron assertions fail.
  • the validate-with-schematron generates two outputs: a result and a report.
    Hence we declare at the pipeline level an additional output 'report', since this is not a defaulted primary output of the pipeline and we pipe the generated report of the schematron validation to the pipeline report output. The only thing left then is to bind the report output to a file on the Calabash command-line.
    java -cp /Applications/calabash-0.9.3/lib/calabash.jar:
    /Applications/saxonsa9-1-0-5j/saxon9sa.jar:
    /Applications/saxonsa9-1-0-5j/saxon9-s9api.jar:
    /Applications/msv-20080213/msv.jar:
    /Applications/msv-20080213/isorelax.jar:
    /Applications/saxonsa9-1-0-1j/
    com.xmlcalabash.drivers.Main -a
    -isource=/Users/paul/Desktop/R&D/calabash/test.xml
    -oreport=/Users/paul/Desktop/R&D/calabash/report.xml
    /Users/paul/Desktop/R&D/calabash/test.xpl

    The report generated by schematron and piped to "report.xml".

    svrl report

  • sometimes it is needed to pass parameters to the schematron validator. In my case I need to pass allow-foreign 'true'.
    This is done by adding element 'with-param'

    <validate-with-schematron name="schematron" assert-valid="true">
    <input port="schema">
    <document href="test1.sch"/>
    </input>

    <with-param name="allow-foreign" select="'true'"/>

    </validate-with-schematron>

Comments