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-xml-schema">
   <p:input port="source" primary="true"/>
   <p:input port="schema" sequence="true"/>
   <p:output port="result"/>
   <p:option name="use-location-hints" select="'false'"/> <!-- boolean -->
   <p:option name="try-namespaces" select="'false'"/> <!-- boolean -->
   <p:option name="assert-valid" select="'true'"/> <!-- boolean -->
   <p:option name="mode" select="'strict'"/> <!-- "strict" | "lax" -->

As the name of this step implies, a XML document is validated against a XML Schema document. It requires a “source“ input port which supplies the XML document to be validated, as well as a further input port with the name “schema“ by indication of the XML Schema data. Per convention the “result“ output port is used.

The Boolean options “try-namespace-hints“ and “use-location-hints“ tell the Schema processor how it has to react regarding the locating of further Schema data which have not been indicated in the “schema“ port. If “use-location-hints“ is set to “true“, the processor will try to persue any information concerning further Schema documents which have been indicated in the Schemas on the “source“ port. If “try-namespace-hints“ is set to “true“, the processor will also try to resolve the indicated namespaces in order to be able to locate further Schema documents. If the options are set to “false“, the processor will do nothing in order to find further Schema documents.

The “assert-valid“ option determines how XProc shall react in relation to the error handling. If the value is set to “true“, the appropriate report is generated and outputted by the output port in the case of a validation error. If “assert-valid“ is set to “false“, no error output is generated in case of an error. In this situation the reaction of XProc depends on the underlying implementation of the used processor. If the processor supports PSVI (Post-Schema-Validation-Infoset), an output with additional information is generated which allow conclusions about the validation errors. If PSVI is not supported, the document read in is outputted without supplements.

The “mode“ option indicates how the processor shall react when validating against the Schema document. When using “strict“, all elements in the XML document have to be defined and namespaces have to be indicated correctly. A validation which is set to relaxed (“lax“) is less strict since the missing of a document output is not checked. In both cases the document has to be “valid“.


In the following example the known “FilmCollection.xml“ file shall be validated with an appropriate XML Schema document.

<?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">
   <p:input port="source">
      <p:document href="FilmCollection.xml"></p:document>
   <p:output port="result"/>
   <p:validate-with-xml-schema assert-valid="true" mode="strict">
      <p:input port="schema">
         <p:document href="xmlschema.xsd"></p:document>

In the example a strict validation is executed which generates an appropriate error output if an error occurs. The XML Schema document (“xmlschema.xsd“) is indicated within the <p:validate-with-schema> element in the <p:input> port. The result is written into the “result“ port.