Implementation: Generates standard messages in the format used by emacs and XED: plug it in and use it in interactive editors.
Author: Rick Jelliffe
Current version: 2000-03-26
Requires: any XSLT implementation which sends xml:message to output (standard error?) with the correct file and line number information. XT does this.Intro: Schematron is a way of using XPath Paths and Expressions to validate that an XML file (file A) obeys certain rules, specified by the user in another XML file (file B). File B is called a schematron schema instance.
Examples of user need for this might include:
- Checking that no element X is empty.
- Checking that element Y has no more than n element Z children.
- Checking that element P has element S as its parent.
- Checking that element T has an attribute att present.
- Checking the nesting depth of an element.
- Checking that an IDREF attribute references an element of the correct type.
It does that by using an XML file B, valid to the schema DTD, together with the schematron XSL file, to create an XSLT file (XSL file C).
This is then used with XML file A , to validate your XML file against the rules you have created!
Rules file (XML file B) + schematron.xsl => XSL file C Your XML file A + XSL file C => Report file.The report file finally output informs you of either exceptions (assert elements) or compliances (report elements) that you have specified.
Downloading
Download the file schematron-message.xsl. You may need an XSLT implementation with the correct behaviour too, e.g. XT (and XP etc) from jclark.com
Running
So the order is
xt schemafile.xml schematron-message.xsl xxx.xsl xt datafile.xml xxx.xsl
Demonstration Schematron Schema
Here are is a demonstration schema.
WAI: Web Accessability Inititative Guidelines
Many of the WAI guidelines can be turned into a schema easily. Here is the schema, and here is an evil test file. And here is part of the result:
file:/project3/xml/public_html/resource/schematron/schematron-message/waitest.xml:12: (1.1) An image element should have some descriptive text: an alt or longdesc attribute. (Web Content Accessibility Guidelines 1.0, Guideline 1) file:/project3/xml/public_html/resource/schematron/schematron-message/waitest.xml:15: (1.1) An input element should have some descriptive text: an alt or longdesc attribute. (Web Content Accessibility Guidelines 1.0, Guideline 1) file:/project3/xml/public_html/resource/schematron/schematron-message/waitest.xml:18: (1.1) An applet element should have some descriptive text: an alt or longdesc attribute. (Web Content Accessibility Guidelines 1.0, Guideline 1) file:/project3/xml/public_html/resource/schematron/schematron-message/waitest.xml:20: (1.1) A map element should have some descriptive text: an alt attribute or a link. (Web Content Accessibility Guidelines 1.0, Guideline 1)generated by schematron-message. (Actually, the current version has a little bug: if your schema has newlines, these come out to to the error messages: those kind of lines will probably break interactive debuggers. Sorry I don't have time to fix it today)Of course, any HTML in XML file or XHTML file can be used. The test file is certainly not good or even valid HTML (against the HTML DTDs). But you can see that this WAI schema does not require documents that are valid; it only is interested in validating the patterns that WAI is interested in. (Actually, I have just made each section in the WAI guidelines into a pattern: this perhaps is slack, since really a pattern should be a bunch or rules that are somehow interconnecting.)
Copyright (C) Rick Jelliffe, Academia Sinica Computing Centre. Thanks to David Pawson for the introductory material. The Schematron software and this page are available for any public use, under the conditions of the GPL or MPL, but please mention our names in any documentation or About screens for any products that uses it. Comments, fixes and upgrades welcome: email ricko@gate.sinica.edu.tw