A general Schematron validator is a function returning "valid", "invalid" or "error". The function notionally performs two steps: transforming the schema into a minimal syntax, then testing the instance against the minimal syntax.
||This part of ISO/IEC 19757 does not constrain other information provided by an implementation nor other uses of Schematron schemas. However, it is the intent of this part of ISO/IEC 19757 to support implementations to provide rich, specific diagnostics customised with values that assist in detecting and rectifying problems.|
A Schematron validator is a function over the following:
||a query language binding|
||an instance to be validated|
||external XML documents addressed using information in the instance or schema|
||a phase name, or #ALL if all patterns shall be active patterns, or #DEFAULT if the defaultPhase attribute on the schema element shall be used|
||a list of name-value pairs, if the schema uses external variables.|
To simplify the specification of semantics later, the following transformation steps are first applied to a schema, resulting in a schema in the minimal syntax:
||Resolve all inclusions by replacing the include element by the resource linked to.|
||Resolve all abstract patterns by replacing parameter references with actual parameter values in all enclosed attributes that contain queries.|
||Resolve all abstract rules in the schema by replacing the extends elements with the contents of the abstract rule identified.|
||Negate all report elements into assert elements.|
||Remove elements used for diagnostics and documentation.|
The resulting minimal syntax is also a valid Schematron instance in the full syntax. The minimal syntax differs from the complex syntax by not containing the following XPaths:
This clause gives the semantics of a good schema that has been resolved into the minimal form.
This predicate treats an instance as a set of contexts, a schema as a set of phases, a phase as a set of patterns, a pattern as a set of rules, and a rule as a set of assertions.
A document is valid in respect to a schema in a phase when the following predicate is satisfied:
∀ ( context, pattern, rule, assertion):
( context ∈ instance,
active-phase ∈ schema,
pattern ∈ active-phase,
rule ∈ pattern,
assertion ∈ rule :
( match ( rule, context, instance ),
∀ (previous-rule) :
( previous-rule ∈ pattern,
position (previous-rule) < position( rule):
¬ match(previous-rule, context, instance)
⇔ assert ( assertion, context, instance) = true
||position( rule ) is the position of the member in the set, a cardinal number,|
||match( rule, context, instance) is a predicate supplied by the query language binding, and|
||assert( assertion, context, instance ) is a predicate supplied by the query language binding.|
||In natural language, a document is valid against a schema in a phase if: There exists an instance, schema and active-phase combination where, for each context, pattern, rule and assertion (the context being a member of that instance, the active phase being a member of the schema, the pattern being a member of that active phase, the rule being a member of that pattern, the assertion being a member of that rule), the following is true: if the context of an instance matches the rule, and that context has not been matched by a previous rule in the same pattern, then the particular assertion evaluates to true when evaluated with the particular context and instance.|6.4 Query Language Binding
A query language binding shall provide the following:
||The general query language used. A name token which identifies the query language. The data model.|
||The rule context query language. The rule context scope.|
||The assertion test, a function which returns a data value coercible into boolean.|
||The following query language names are reserved without further definition. Implementations which use different query language bindings are encouraged to use one of these names if appropriate : |
A schema language binding may also provide the following:
||The data models of the various query languages, the conversion between data models, and the treatment of information items: which information items are stripped or ignored, which information items are errors, and which information items are used.|
||The name query language, a function which returns a data value coercible into a string.|
||The value-of query language, a function which returns a data value coercible into a string.|
||The let value query language, a function which returns a data value. |
||The variable delimiter convention, a lexical convention such as a delimiter by which the use of a variable in a query expression shall be recognised.|
||The abstract pattern parameter convention, a lexical convention such as a delimiter by which the parameters of abstract patterns inside query expressions shall be recognised.|
The query language binding may also specify the element types in other namespaces which provide query-language-specific ancillary information or pragmatic hints.
The query language binding shall specify any whitespace processing required on queries.
The query language binding shall specify any restrictions to the value of name tokens.
A Schematron implementation which does not support the query language binding, specified in a schema with the queryBinding attribute, shall fail with an error.
6.5 Order and side-effects
The order in which elements are validated is implementation-dependent, without altering the validity of the instance.
The order in which patterns are used is implementation-dependent, without altering the validity of the instance.
The order in which assertions are tested is implementation-dependent, without altering the validity of the instance.
The only elements for which order is significant are the rule and let elements.
A rule element acts as an if-then-else statement within each pattern. An implementation may make order non-significant by converting rules context expressions to elaborated rule context expressions.
||The behaviour of the |
rule element allows constraints that would require a complex context expression to be factored into simpler expressions in different rules.
An let element may use lexically previous variables within the same rule or global variables.
||A wide variety of implementation strategies are therefore possible. |
All queries shall act as pure functions. Queries shall not alter the instance in any way visible to other queries. This part of ISO/IEC 19757 does not specify any outcome augmentation of the instance being validated.