How to debug Schematron validation

      No Comments on How to debug Schematron validation

A Schematron validator is a powerful tool to run business rules for your XML data and to check conditions that are not supported using W3C schema. Schematron uses a lot of XPath and the validator is based on XSLT to apply all rules to the XML instance.

But often it is not easy to debug a Schematron check if it does not work as expected. Because the Schematron rules are transformed to a stylesheet to run the validator, it is not always clear where the error happens. To make life easier in this regard, the XML ValidatorBuddy editor supports several functions which are targeted at the transformation from the Schematron input to the final XSLT for the validator.

First step: Check the output from the Schematron pre-processing for includes and abstract rules

If the Schematron uses includes and abstract rules the pre-processor generates an intermediate schema with all of the included and abstract rules. Select the original Schematron in the built-in File Explorer and use the “Get Schematron schema after pre-processing” command from the XML menu in the editor to get a copy of this intermediate schema saved next to your original Schematron file.

Get Schematron pre-processed intermediate schema Afterwards a new Schematron document (usually having .sch as extension) is available in the same folder with “after_preprocess” appended to the name of the original Schematron. You can inspect this file in the editor if all of the includes and abstract rules are present. If not, please check if your include files are accessible and well-formed. For abstract rules, take a look if the “id” and “is-a” attributes are correctly used.

Second step: Generate the final stylesheet for the Schematron validator

You can generate the final XSLT for the validator similar to generating the intermediate schema for the pre-process step. Again select the original Schematron in the built-in File Explorer and use the “Get Schematron validation stylesheet” from the XML menu. Afterwards the final stylesheet for the validator is available in the same folder with “_final.xsl” appended to the name of the original Schematron.

This XSLT can be applied to the XML instance using the “Transform XSL…” command in the editor like any other stylesheet. Any errors occurred during the transformation are visible in the standard Results window in XML ValidatorBuddy. If the XSL transformation produced some output you can check the resulting document if the Schematron validator applied your rules as expected.

Use the XPath evaluator window

Schematron rules are using XPath expressions to check if a rule should trigger in the current context. The XPath evaluator in the editor helps a lot to simplify the creation of such XPath expressions. Use it to get a feeling what results a certain expression gives in the current XML context.

XPath expression for current context

It is also easy to get a full qualified XPath for any selection in the editor. Just move the cursor to the XML element or attribute where you want to get the XPath and use the “Copy XPath” command either from the “Edit” or the context menu.

»crosslinked«

Leave a Reply