Schemas and validity
Schematron
A rule-based schema language that asserts XPath conditions about a document, rather than describing its grammar.
Schematron answers the questions a grammar cannot: this total must equal the sum of the lines, this end date must not precede the start date, this element is required only when that attribute is present. Rules are XPath expressions with human-readable messages, which makes its output the most actionable of any schema language.
It is usually layered on top of XSD rather than replacing it — the grammar checks the shape, Schematron checks the relationships. It is also the one schema language this site cannot run: the WebAssembly build of libxml2 reports an internal error for valid and invalid documents alike, so publishing a Schematron validator would mean publishing a coin flip.
- Defined in
- ISO/IEC 19757-3
- Category
- Schemas and validity
- Also written
- ISO Schematron, .sch
Why there is no demo
Nothing here to execute
Our engine cannot run Schematron. The WebAssembly build of libxml2 returns the same internal error for a document that satisfies the rules and one that violates them, so any demonstration here would be asserting a result nothing produced. The /about page says the same thing about why the validator is missing.What catches people out
- Schematron rules are XPath, so everything true of XPath is true of them — including that an unprefixed name in a namespaced document matches nothing.
- It constrains relationships, not structure. Use it alongside a grammar rather than instead of one.
- Most implementations compile Schematron to XSLT and run that, which means your XPath version is whatever the XSLT processor supports.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- XPathsum()The function behind the classic Schematron rule: a total that must match its lines.
- ToolsXPath testerTest the expression a rule would use, against your own document.
Related terms
- ValidA well-formed document that also conforms to a declared grammar — a DTD, an XSD schema or a RELAX NG grammar.
- XML Schema (XSD)The W3C schema language: a grammar written in XML itself, with datatypes, namespaces and a type system.
- RELAX NGA schema language built around patterns rather than types, expressing repetition, alternation and interleaving far more directly than XSD.
- XPathThe expression language for addressing parts of an XML document — the query language inside XSLT, XSD's identity constraints, Schematron and every DOM API.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.