XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z


<p:declare-step type="p:validate-with-schematron">
   <p:input port="parameters" kind="parameter"/>
   <p:input port="source" primary="true"/>
   <p:input port="schema"/>
   <p:output port="result" primary="true"/>
   <p:output port="report" sequence="true"/>
   <p:option name="phase" select="'#ALL'"/> <!-- string -->
   <p:option name="assert-valid" select="'true'"/> <!-- boolean -->

With the help of the <p:validate-with-schematron> step, the input document can be validated against a Schematron document. The step has three input ports. The XML document to be validated is indicated in “source“. The Schematron document is indicated in the “schema“ input port. The port with the indication “parameters“ refers to external Schematron variables.

The “result“ output port supplies a copy of the input port and the “report“ port supplies Schematron-related information outputs.

With the “phase“ option the user can determine which Schematron phase shall be the first one. If “assert-valid“ is set to “true“, an error output is generated in the case a validation error occurs, and the process is finished. If the value is set to “false“, the original document is completely outputted and Schematron messages are sent to the “report“ port (provided that it has been generated) also in the case a validation error occurs.


In the following example the known input document is validated with a Schematron schema. At first, the (very trivial) Schematron document:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
   <rule context="Film">
      <assert test="Title">No title available</assert>
      <assert test="Genre">No genre available</assert>
      <assert test="Director">No director available</assert>
      <assert test="Producer">No producer available</assert>
      <assert test="Cast">No cast available</assert>
      <assert test="Duration">No duration available</assert>
      <assert test="Author">No author available</assert>

This Schematron schema tests each “Film“ element in the document for the presence of various child elements. If one of the elements is not present, an appropriate message is outputted (e.g. "No title available"). These messages shall be written on the “report“ channel after the XProc procedure.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" name="Schematron">
   <p:input port="source">
      <p:document href="FilmCollection.xml"/>
   <p:output port="result" primary="true"/>
      <p:validate-with-schematron assert-valid="false" name="SchematronExample">
         <p:log port="report" href="log.log"/>
         <p:input port="schema">
            <p:document href="example_8_schematron.sch"/>
         <p:input port="parameters">

The “assert-valid“ option should be set to “false“, since if it is set to “true“, the XProc processor would terminate with a dynamic error in the case of a Schematron validation error. This would have the effect that no report output from the Schematron schema would be written on the “report“ port. The Schematron document is indicated in the <p:input port>. The second input port “parameters“ requires an indication. In the example, parameter indications are not required, therefore <p:empty> is entered into the example. In the case of an error during the execution of this stylesheet, the actual input document would be outputted on the “result“ port and the respective messages from the Schematron document on the “report“ port. These messages are caught by <p:log> and written into a file called “log.log“.