Schematron Rule Runner
Run an ISO/IEC 19757-3 Schematron schema against an XML document fully in the browser. Documented XPath 1.0 subset.
Paste an XML document and a Schematron schema, then evaluate.
How it works
Schematron is the ISO/IEC 19757-3 standard for rule-based validation of XML structures. The runner follows the classic two-pass flow:
- Parse the schema — the
<schema xmlns="http://purl.oclc.org/dsdl/schematron">file is read: every<pattern>holds<rule context="…">entries which in turn hold<assert test="…">or<report test="…">nodes. - Evaluation — for each rule, the XPath in
contextis evaluated against the input document; on every matched node, thetestXPath is evaluated. An assert that evaluates tofalse(), or a report that evaluates totrue(), yields a diagnostic carrying the offending node's path and the rule's message.
Supported XPath subset
To stay 100 % client-side and fit in a tiny JavaScript bundle, we hand-roll
a documented subset of XPath 1.0. Expressions outside this scope emit a
E_XPATH_UNSUPPORTED diagnostic — never a silent
mis-evaluation.
Supported
- Absolute paths (
/Invoice/cbc:ID), relative paths from the context,.,..,*. - Explicit axes
child::,attribute::,self::,parent::. - Attributes through
@code. - Numeric predicates (
[1]),position(),last(),count(path) op N, comparisons=,!=,<,<=,>,>=. - Boolean operators
and,or, functionnot(). - Functions:
count,string-length,normalize-space,string,number,boolean,true(),false(),position(),last(). - Arithmetic
+,-,*,div,mod.
Not supported
- The descendant operator
//and thedescendant::axis. - The
following-sibling::,preceding::and similar axes. - Functions
local-name(),substring(),matches(),key(). - XPath 2.0+ (sequences,
if/then/else,for $x in).
Examples
Click “Load example” to pre-fill both panes with a
simplified version of EN 16931's BR-S-09 rule: every
TaxSubtotal's VAT amount must equal the taxable amount times the
rate divided by 100. The example is intentionally minimal — it
illustrates the mechanism without requiring a full UBL document.
Limitations
-
The runner does not resolve external
<include>or<extends>directives: your schema must be self-contained. -
<ns>declarations are read but element prefixes are matched literally (cbc:IDin a test looks for an element tagged exactlycbc:ID). -
<value-of select="…"/>calls inside messages are rendered as{select}placeholders, without runtime interpolation. -
<phase>declarations are ignored: every rule is evaluated.
Privacy
Related documentation
- ISO/IEC 19757-3 — Schematron, the official standard. The historical site schematron.com remains an excellent pedagogical reference.
- PEPPOL Validator — ships the official EN 16931 + PEPPOL BIS 3.0 Schematron rules compiled into TypeScript.
- EN 16931 Validator — the underlying core-norm layer.