<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="is.css" ?>
<!DOCTYPE document [
<!ENTITY emdash "&#x2014;">
<!-- In order to validate, replace all 
"this draft standard" with <this/> and replace all 
"This draft standard" with <This/>. 
Also allow p at start of terms-and-definitions
-->

<!-- To edit this file, you will need to use a font
  with mathematical operators such as Lucida Sans Unicode
 	∀  For All
 	∈  Element Of
 	⇒ Rightwards Double Arrow
 	¬ Not Sign
 	∧ Logical And
 	The emdash is marked up by NCR.
-->

<!--
	TODO:
		Element syntax definitions
	    Clarify terminology of firing versus matching
	    Fill in References
	    Complete terminology
	    
	 Done: 
	   Murata's external vocabulary requirement
	   SVRL
	   flags
-->
]>
<document>

<head> 
<organization>ISO/IEC</organization>
<document-type>International Standard</document-type>
<stage>enquiry</stage>
<secretariat>Standards Council of Canada</secretariat>
<tc-number>1</tc-number>
<tc-name>Information Technology</tc-name>
<sc-number>34</sc-number>
<sc-name>Document Description and Processing Languages</sc-name>
<serial-number>320</serial-number>
<wg-number>1</wg-number>
<document-number>19757</document-number>
<part-number>3</part-number>
<document-language>E</document-language>
<title>
  <main>Document Schema Definition Languages (DSDL)</main>
  <complementary>Rule-based validation &#x2014; Schematron</complementary>
</title>
<date>2004-04-14</date>
</head>

<foreword>

<part-list>
<part><number>1</number><title>Overview</title></part>
<part><number>2</number><title>Regular-grammar-based validation &emdash; RELAX NG</title></part>
<part><number>3</number><title>Rule-based validation &emdash; <?nospell-start?>Schematron<?nospell-end?></title></part>
<part><number>4</number><title>Namespace-based validaiton dispatching language</title></part>
<part><number>5</number><title><?nospell-start?>Datatypes<?nospell-end?></title></part>
<part><number>6</number><title>Path-based integrity constraints</title></part>
<part><number>7</number><title>Character repertoire validation</title></part>
<part><number>8</number><title>Declarative document architectures</title></part>
<part><number>9</number><title><?nospell-start?>Datatype<?nospell-end?>- and namespace-aware <?nospell-start?>DTDs<?nospell-end?></title></part>  
<part><number>10</number><title>Validation management</title></part>

</part-list>

</foreword>

<!-- ==========================================================-->
<introduction>

<p>The structure of this standard is as follows. </p>
<ul>
<li><p><xref to="syntax"/>
describes the syntax of an ISO Schematron schema. 
</p></li>
<li ><p ><xref to="semantics"/> describes the semantics of a 
correct ISO Schematron schema; 
the semantics specify when a document is
valid with respect to an ISO  Schematron schema.  
</p></li> 
<li ><p ><xref to="vocab"/> describes the use of ISO Schematron elements
in external vocabularies.
</p></li>
<li ><p >Finally, <xref to="conformance"/>
describes conformance requirements for implementations of ISO Schematron validators.
</p>
</li><li ><p><xref to="relax"/> is a normative annexes providing the Part 2 (RELAX NG)  schema
for ISO Schematron. 
</p></li>
<li ><p><xref to="sch"/> is a normative annexes providing the ISO Schematron  schema
for constraints in ISO Schematron that cannot be expressed by the schema of <xref to="relax"/>.  
</p></li>
<li ><p><xref to="binding"/> is a normative annexes providing the default query language binding to
<xref to="xslt-rec"/>. 
</p></li>
<li ><p ><xref to="svrl"/> is a non-normative annex providing a DTD and corresponding ISO Schematron schema 
for a simple XML language Schematron Validation
Report Language.</p></li>
<li ><p ><xref to="req"/> is a non-normative annex providing motivating design requirements
for ISO Schematron.</p></li>
</ul>
<p>This standard is based on the <xref to="schematron"/>. 
The <code>let</code> element is based on <xref to="XCSL"/>.</p>

</introduction>

<!-- ==========================================================-->
<scope>

<p>This standard specifies Schematron, a schema language for XML.</p>

<p>Considered as a document type, a Schematron schema contains
natural-language assertions concerning a set of documents, marked up
with various elements and attributes for testing these 
natural-language assertions, and for simplifying and grouping the 
assertions. </p>

<p>Considered theoretically,
a Schematron schema reduces to a non-chaining rule system
whose terms are boolean functions invoking an external query language
on the instance and other visible XML documents, 
with syntactic features to reduce specification size and to allow
efficient implementation.</p>

<p>Considered analytically, 
Schematron has two characteristic high-level
abstractions: the pattern and the phase. These allow 
the representation of non-regular, non-sequential constraints 
that Part 2 cannot specify, and various dynamic or contingent
constraints.</p>

<p>This standard establishes requirements for Schematron schemas and specifies
when an XML document matches the patterns specified by a Schematron
schema.</p>

</scope>

<!-- ==========================================================-->
<normative-references>

 
<p>Each of the following documents has a unique identifier that
is used to cite the document in the text.  The unique identifier
consists of the part of the reference up to the first
comma.</p>

<referenced-document id="xpath-rec">
<abbrev>XPath</abbrev>
<title>XML Path Language (XPath) Version 1.0</title>
<field>W3C Recommendation</field>
<url>http://www.w3.org/TR/1999/REC-xpath-19991116</url>
</referenced-document>

<referenced-document id="xslt-rec">
<abbrev>XSLT</abbrev>
<title>XSL Transformations (XSLT) Version 1.0</title>
<field>W3C Recommendation</field>
<url>http://www.w3.org/TR/1999/REC-xslt-19991116</url>
</referenced-document>


</normative-references>

<!-- ==========================================================-->
<terms-and-definitions>
<p>The definitions of Part 1 and Part 2
also apply to this standard.</p>


<term-and-definition>
<term>schema</term>

<definition>specification of a set of XML documents</definition>

</term-and-definition>
 
 <term-and-definition>

<term>correct schema</term>
<definition>schema that satisfies all the requirements of
this standard</definition>
</term-and-definition>

<term-and-definition>
<term>good schema</term>

<definition>a correct schema with queries which
terminate and do not
add constraints to those of the natural-language
assertions. Note: it is not possible to compute
that a schema is good.
</definition>
</term-and-definition>

<term-and-definition>
<term>valid with respect to a schema</term>
<definition>member of the set of XML documents described by the
schema. An instance document is valid if no assertion tests
in fired rules of active patterns fail.
</definition>
</term-and-definition>

<term-and-definition>
<term>phase</term>
<definition>a named, unordered collection of patterns; patterns may belong
to more than one phase; two names #ALL and #DEFAULT are reserved
with particular meanings</definition>
</term-and-definition>

<term-and-definition>
<term>active phase</term>
<definition>one particular phase, whose patterns are 
used for validation</definition>
</term-and-definition>


<term-and-definition>
<term>pattern</term>
<definition>a named structure in instances 
specified in a schema by a lexically-ordered collection of rules
</definition>
</term-and-definition>


<term-and-definition>
<term>active pattern</term>
<definition>a pattern belonging to the active phase</definition>
</term-and-definition>


<term-and-definition>
<term>abstract pattern</term>
<definition>a pattern in a rule
to some extent parameterized</definition>
</term-and-definition>

<term-and-definition>
<term>subject</term>
<definition>a particular information item which matches the
context expression of a rule
and which corresponds to the object of interest of the
natural-language assertions</definition>
</term-and-definition>

<term-and-definition>
<term>assertion</term>
<definition>a natural-language assertion with corresponding assertion
test and ancilliary attributes</definition>
</term-and-definition>

<term-and-definition>
<term>natural-language assertion</term>
<definition>a natural-language statement expressing some part of a pattern;
a natural-language assertion is "met" or "unmet"</definition>
</term-and-definition>

<term-and-definition>
<term>assertion test</term>
<definition>an assertion modelled/implemented by a boolean query;
an assertion test "succeeds" or "fails"</definition>
</term-and-definition>

<term-and-definition>
<term>rule</term>
<definition>unordered collection of assertions
with a rule-context expresssion and ancilliary attributes
</definition>
</term-and-definition>

<term-and-definition>
<term>rule context</term>
<definition>a selection of elements; 
a rule is said to fire when an information item
matches its query</definition>
</term-and-definition>

<term-and-definition>
<term>rule-context expression</term>
<definition>a query to specify subjects; 
a rule-context is said to match when an information item
that has not been mateched by lexically previous rule
context expressions
matches its query ??? should use is member of?</definition>
</term-and-definition>


<term-and-definition>
<term>abstract rule</term>
<definition>a collection of assertions 
which can be included in other rules but which
does not fire itself</definition>
</term-and-definition>

<term-and-definition>
<term>variable</term>
<definition>let and param</definition>
</term-and-definition>


<term-and-definition>
<term>diagnostic</term>
<definition>named ...</definition>
</term-and-definition>
 

<term-and-definition>
<term>variable</term>
<definition></definition>
</term-and-definition>


<term-and-definition>
<term>parameter</term>
<definition></definition>
</term-and-definition>

 
<term-and-definition>
<term>macro substitution</term>
<definition>(parameterized text substitution)</definition>
</term-and-definition>


<term-and-definition>
<term>element inclusion</term>
<definition></definition>
</term-and-definition>


<term-and-definition>
<term>text substitution</term>
<definition></definition>
</term-and-definition>


<term-and-definition>
<term>implementation</term>
<definition>an implementation of a Schematron validator</definition>
</term-and-definition>


</terms-and-definitions>

<!-- ==========================================================-->
<clause><title>Notation</title>
<clause>
<title>XPath</title>
<p>This standard uses <xref to="xpath-rec"/> to express the names of 
information items in the schema. In this standard the prefix <code>sch</code> 
is bound to the Schematron namespace URI.</p>

</clause>
<clause>
<title>Predicate Logic</title>
<p>This standard uses predicate logic to express the semantics of
Schematron schema. 
The following functions are defined:</p>
<notation-list>

<notation-item><notation><symbol>∈</symbol></notation>
<notation-definition><p>is member of, an infix relation, 
used in the set-operation sense.
</p></notation-definition>
</notation-item>

<notation-item><notation>x <symbol><symbol>∈</symbol></symbol> y </notation>
<notation-definition><p>If <code>y</code> is an element in a simplified schema, 
<code>x <symbol>∈</symbol> y </code> 
is defined here as the 
<code>child::x</code> path from context of subject y
as defined by <xref to="xpath-rec"/>.</p></notation-definition>
</notation-item>

<notation-item><notation>x <symbol>∈</symbol> y </notation>
<notation-definition><p>If <code>y</code> is an element in a simplified schema, 
<code>x <symbol>∈</symbol> y </code> 
is defined here as the 
<code>child::x</code> path from context of subject y
as defined by <xref to="xpath-rec"/>.</p></notation-definition>
</notation-item>

<notation-item><notation>x <symbol>∈</symbol> y </notation>
<notation-definition><p>If <code>y</code> is the instance being validated,
<code>x <symbol>∈</symbol> y </code>
is defined here as all the subjects (information items) in the instance
that can be accessed by the query language,
as specified in the query language binding.</p></notation-definition>
</notation-item>


<notation-item><notation>x <symbol>∈</symbol> y </notation>
<notation-definition><p>If <code> y</code> is the name of the active active-phase
with the reserved value <code>#ALL</code>,
<code>x <symbol>∈</symbol> y</code> is defined here as the path
<code>//sch:pattern </code></p>
</notation-definition>
</notation-item>
<notation-item><notation>x <symbol>∈</symbol> y </notation>
<notation-definition><p>If <code> y</code> is the name of the active active-phase
with the reserved value <code>#DEFAULT</code>, <code>x <symbol>∈</symbol> y</code> is defined here as the path
<code>//sch:pattern[@id=/sch:schema/@default-phase] </code></p>
</notation-definition>

</notation-item>
<notation-item><notation>x <symbol>∈</symbol> y </notation>
<notation-definition><p>If <code> y</code> is the name of the active active-phase,
not being <code>#ALL</code> or <code>#DEFAULT</code>, <code>x <symbol>∈</symbol> y</code> is defined here as the path
<code>../sch:pattern[@id=//sch:phase[id="y"]/active/@pattern]</code> </p>
</notation-definition>

</notation-item>






<notation-item><notation>position( r )</notation>
<notation-definition><p>the <xref to="xslt-rec"/> function  <code>position()</code>
of a rule <code>r</code> in its parent pattern</p>
</notation-definition></notation-item>

<notation-item><notation>match ( r, s, d )</notation>
<notation-definition><p>a function returning boolean
provided by the query language binding: it returns true
iff the subject <code>s</code> from the document <code>d</code> 
matches the context expression of rule<code> r</code></p>
</notation-definition></notation-item>

<notation-item><notation>assert ( t,  s, d)</notation>
<notation-definition><p>a function returning boolean
provided by the query language binding: it returns true
iff the assertion test <code>t</code> is true when applied to
the subject <code>s</code> from the document <code>d</code> 
</p>
</notation-definition></notation-item>

</notation-list>
</clause>
</clause>

<!-- ==========================================================-->
<clause id="syntax">
<title>Syntax</title>
<clause id="namespace">
<title>Namespace and Whitespace</title>

<p>All elements shown in the grammar are qualified with the namespace
URI:</p>

<pre>http://www.ascc.net/xml/schematron</pre>


<p>Any element can also have foreign attributes in addition to the
attributes shown in the grammar. A foreign attribute is an attribute
with a name whose namespace URI is neither the empty string nor the
Schematron namespace URI.  Any non-empty element 
may have foreign child elements in addition
to the child elements shown in the grammar. A foreign element is an
element with a name whose namespace URI is not the Schematron namespace
URI.  There are no constraints on the relative position of foreign
child elements with respect to other child elements.</p>

<p>Any element can also have as children strings that consist
entirely of whitespace characters, where a whitespace character is one
of U+0020, U+009, U+00D or U+00A. There are no constraints on the relative
position of whitespace string children with respect to child
elements. 
</p>

<p>Leading and trailing whitespace is allowed for the value of any
Schematron-namespace attribute, and shall be stripped.
Whitespace in Schematron-namespace elements should be collapsed.</p>

   
 </clause>

<!-- ==========================================================-->
<clause>
<title>Core Elements</title>

<clause>
<title><code>active</code> element</title>

<p>The required <code>pattern</code> attribute is
a reference a pattern that is active in the current phase.</p>

</clause>

<clause>
<title><code>assert</code> element</title>

<p>An assertion made about the context nodes.
The data context is a natural-language assertion.
The required <code>test</code> attribute is an assertion test
evaluated in the current context. If the test evaluates positive,
the report succeeds.
The optional <code>diagnostics</code> attribute
is a reference to further diagnostic information. </p>
<p>The natural-language assertion shall be a positive
statement of a constraint.</p>
<note><p>The natural-language assertion may contain information
about actual values in addition to expected values
and may contain diagnostic information, however
the <code>diagnostic</code> element is provided
for such information to encourage clear statement
of the natural-language assertion.</p></note> 

</clause>


<clause>
<title><code>extends</code> element</title>

<p>Abstract rules are name lists of assertions without
a context expression. 
The required <code>rule</code> attribute 
references an abstract rule. The current rule 
uses all the assertions from the abstract rule it extends.</p>

</clause>

 

<clause>
<title><code>include</code> element</title>

<p>The required <code>src</code> attribute references
an external XML document with a schema fragment.
The schema fragment contains elements which
are valid when substituted for the <code>include</code>
element.</p>

</clause>

<clause>
<title><code>let</code> element</title>

<p>A named constant, calculated and scoped to the current rule
and context.
The required <code>name</code> attribute is the name of the
constant.  The required <code>value</code> attribute is an
expression evaluated in the current context that returns a string. </p>
<p>The constant is substituted by text substitution into 
assertion tests and other expressions in the same rule
before they are used. The query language binding 
specifies which lexical conventions are used to detect
references to constants.</p>
</clause>



<clause>
<title><code>name</code> element</title>

<p> Finds the names of nodes from the instance document to
allow clearer assertions and diagnostics. 
The optional <code>select</code> attribute is an expression 
evaluated in the current context that returns either a string that is
the name of a node or a node that has a name. In the latter case,
the name of the node is used.   
</p>
<p>The name is substituted by text substitution.</p>

<p>An implementation which does not report natural-language assertions  
is not required to make use of this element.</p>

</clause>

<clause>
<title><code>ns</code> element</title>

<p>Specification of a namespace prefix and URI. 
The required <code>prefix</code> attribute is an XML name with no
colon character. The required <code>uri</code> attribute is
a namespace URI.</p>
<p>In an ISO Schematron schema, 
namespace prefixes in context expressions, assertion
tests and other query expressions should use the namespace 
bindings provided by this element. Namespace prefixes 
should not use the namespace bindings in scope for element
and attribute names.</p>
<note><p>When elements other than <code>schema</code>
are used for external vocabularies, the namespace bindings shall
be provided by that external vocabulary.</p></note>
</clause>



<clause>
<title><code>param</code> element</title>

<p>A name/value pair providing parameters for an abstract pattern.
The required <code>name</code> attribute is an XML name with
no colon. The required <code>value</code> attribute is a
fragment of a query.</p>

</clause>
<clause>
<title><code>pattern</code> element</title>

<p><code>empty</code></p>

</clause>


<clause>
<title><code>phase</code> element</title>

<p><code>empty</code></p>

</clause>

<clause>
<title><code>report</code> element</title>

<p>An assertion made about the context nodes.
The data context is a natural-language assertion.
The required <code>test</code> attribute is an assertion test
evaluated in the current context. If the test evaluates positive,
the report succeeds.
The optional <code>diagnostics</code> attribute
is a reference to further diagnostic information. </p>
<p>The natural-language assertion shall be a positive
statement of a found pattern or a negative statement of a constraint.</p>
<note><p>The natural-language assertion may contain information
about actual values in addition to expected values
and may contain diagnostic information, however
the <code>diagnostic</code> element is provided
for such information to encourage clear statement
of the natural-language assertion.</p></note> 

</clause>


<clause>
<title><code>rule</code> element</title>

<p><code>empty</code></p>

</clause>

<clause>
<title><code>schema</code> element</title>

<p><code>empty</code></p>

</clause>

<clause>
<title><code>value-of</code> element</title>

<p>Finds or calculates values from the instance document to
allow clearer assertions and diagnostics. 
The required <code>select</code> attribute is an expression 
evaluated in the current context that returns either a string.
</p>
<p>The string is substituted by text substitution.</p>


<p>An implementation which does not report natural-language assertions  
is not required to make use of this element.</p>
</clause>

</clause>

<!-- ==========================================================-->
<clause>
<title>Ancilliary Elements and Attributes</title>
<clause>
<title><code>diagnostics</code> element</title>

<p>Section containing invidual diagnostic elements.</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>
 
 <clause>
<title><code>diagnostic</code> element</title>

<p>A natural-language message giving more specific
details concerning a failed assertion, such as found 
<i>versus</i> expected values and repair hints. </p>

<p>An implementation is not required to make use of this
element.</p>
</clause>
<clause>
<title><code>dir</code> element</title>

<p>A section of natural-language text with a 
direction specified by the <code>dir</code> attribute.  
The value <code>ltr</code> indicates left-to-right text;
the value  <code>rtl</code> indicates right-to-left text.</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>

  <clause>
<title><code>emph</code> element</title>

<p>A portion of text that should be rendered with some emphasis.</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>


   
 <clause>
<title><code>flag</code> attribute</title>

<p>A boolean variable with value false.
A flag is implicitly declared by an assertion or rule
having a <code>flag</code> attribute with that name.
The value of a flag becomes true when
an assertion with that flag fails or a rule
with that flag fires. </p>
<p>The purpose of flags is to convey state or severity
information to a subsequent process. </p>
<p>An implementation is not required to make use of this
attribute.</p>

</clause>


<clause>
<title><code>fpi</code> attribute</title>
<p>A formal public identifier for the schema or phase.
</p>
<p>An implementation is not required to make use of this
attribute.</p>
</clause>

<clause>
<title><code>icon</code> attribute</title>

<p>The location of a graphics file containing
some visible representation of the severity,
significance or other grouping of the associated element.</p>

<p>An implementation is not required to make use of this
attribute.</p>
</clause>

 <clause>
<title><code>p</code> element</title>

<p>A paragraph of natural language text containing 
maintainer and user information about the parent element.
The schema can nominate paragraphs
 that should be rendered
in a distinct way, keyed with the <code>class</code> attribute.
</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>

<clause>
<title><code>role</code> attribute</title>

<p>A name describing the function of the assertion
or context node in the pattern. If the assertion 
has a <code>subject</code> attribute, then the
role labels the arc between the context node and
any nodes which match the path expression.
</p>

<p>An implementation is not required to make use of this
attribute.</p>
</clause>


<clause>
<title><code>see</code> attribute</title>
<p>The URI of some external information of interest to
maintainers and users of the schema.
</p>
<p>An implementation is not required to make use of this
attribute.</p>
</clause>

<clause>
<title><code>span</code> element</title>

<p>A portion of some paragraph that should be rendered
in a distinct way, keyed with the <code>class</code> attribute.</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>


<clause>
<title><code>subject</code> attribute</title>

<p>A path allowing more precise specification of nodes.
The path expression is evaluated in the context of the 
current subject node of the current rule. If no 
subject is specified, the subject is the
current subject node.</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>



<clause>
<title><code>title</code> element</title>

<p>The purpose or role of the schema  or pattern.</p>

<p>An implementation is not required to make use of this
element.</p>
</clause>

     
</clause>

</clause>
<!-- ==========================================================-->

<clause id="semantics">
<title>Semantics</title>

<clause id="func">
<title>Validation Function</title>

<p>A Schematron validator is a function 
returning "valid", "invalid" or "error".
The function performs notationally performs two steps: 
transforming the schema into a simple syntax, 
then testing the instance against the simple syntax.
</p>
<note><p>This standard does not constrain other information 
provided by an implementation nor
other uses of Schematron schemas.
However, it is the intent of this standard to support implementations
to provide rich, specific diagnostics customized with
values that assist in detecting and rectifying problems.</p></note>
<p>A Schematron validator is a function over
the following:
</p>
<ul>
<li><p>a query language binding</p></li>
<li><p>a schema document</p></li>
<li><p>an instance to be validated</p></li>
<li><p>external XML documents addressed using information in the instance or schema</p></li>
<li><p>a phase name, or #ALL if all patterns shall be active patterns,
or #DEFAULT if the phase attribute on the schema element shall be
used</p></li>
<li><p>a list of name-value pairs, if the schema uses external variables.</p></li>
</ul>

</clause>
<clause id="preprocessing">
<title>Simplified Syntax</title>


<p>To simplifying the specification of semantics later,
the following transformation steps are first applied to a schema, 
resulting in a schema in the simplified syntax:</p>
<ol>
<li><p>Resolve all libraries by element inclusion</p></li>
<li><p>Resolve all abstract patterns by macro substitution</p></li>
<li><p>Resolve all abstract rules in the schema by element inclusion</p></li>
<li><p>Resolve all top-level parameters by text substitution</p></li>
<li><p>Negate all sch:report elements into sch:assert elements</p></li>
<li><p>Remove (ignore) all information items in foreign namespaces.</p></li>
</ol>
<p>The resulting simplified syntax is also a valid Schematron instance
in the full syntax. The simplified syntax differs from the complex syntax
by not containing the following XPaths: </p>
<ul>
<li><p><code>//sch:library</code></p></li>
<li><p><code>//sch:pattern/@abstract="true"</code></p></li>
<li><p><code>//sch:rule/@abstract="true"</code></p></li>
<li><p><code>/sch:schema/sch:param</code></p></li>
<li><p><code>//sch:rule/sch:report</code></p></li>
</ul>

</clause>
 

<clause id="simpleval">
<title>Schema Semantics</title>
<p>This clause gives the semantics of a good schema
that has been transformed into the simple syntax.</p>

<p>A good schema with no use of  variables
satisfies the following predicate:</p>
<pre>
    <symbol>∃</symbol> ( instance, schema, active-phase ),
	<symbol>∀</symbol>( subject, pattern, rule, assertion ) :
		subject <symbol>∈</symbol> instance,
		subject <symbol>∈</symbol> schema,
		pattern <symbol>∈</symbol> active-phase,
		rule <symbol>∈</symbol> pattern,
		assertion <symbol>∈</symbol> rule :
			match ( rule, subject, instance ) 
		 	<symbol>∧</symbol> ( <symbol>∀</symbol>(previous-rule ) : 
		 		previous-rule <symbol>∈</symbol> pattern,
		 		position (previous-rule ) &lt; position( rule ) :
		 			<symbol>¬</symbol> ( match ( previous-rule, subject, instance )))
		 	<symbol>⇒</symbol> assert ( assertion,  subject, instance ) = true
</pre>



<note><p>In natural language, that is
"<i>There exists an instance, schema and active-phase combination
where, for each subject, pattern, rule and assertion
(the subject being a member of that instance,
the pattern being a member of that 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 subject in an instance
matches the rule, and that subject has not
been matched by a previous rule in the same pattern,
then the particular assertion 
evaluates to true when applied to the particular subject
and instance.</i>"
</p></note>


</clause>
 
<!-- ==========================================================-->
<clause id="querylang">
<title>Query Language Binding</title>

<p>A query language binding shall provide the
following:
</p>
<ul>
<li><p>The general query language used.
A name token which identifies the query language.
The data model.</p></li>
<li><p>The rule context query language. 
The rule context scope.</p></li>
<li><p>The assertion test, 
a function which returns a data value
coerceable into boolean.</p></li>
</ul>

<note><p>The following other query language names are
reserved without further definition. Implementions which use 
different query language bindings are encouraged to use 
one of these names if appropriate :

<code>stx</code>,
 <code>xslt</code>
 <code>xslt1.1</code>,
<code>exslt</code>,
<code>xslt2</code>,
<code>xpath</code>,
<code>xpath2</code>,
<code>xquery</code>.</p>

</note>
<p>A Schematron implementation which does
not support the specification language
shall fail with an error.</p>

<p>A schema language binding may also provide the following:
</p>
<ul>
<li><p>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.</p></li>
<li><p>The name query language, a function which returns a 
data value coerceable into a string.</p></li>
<li><p>The value-of query language, a function which returns a 
data value coerceable into a string.</p></li> 
<li><p>The let value query language, a function which returns a 
data value. </p></li>
<li><p>The variable delimiter convention, a lexical 
convention such as a delimiter by which
the use of a variable in a query expression 
shall be recognized.</p></li>
<li><p>The abstract pattern parameter convention,
a lexical convention such as a delimiter
by which the parameters of
abstract patterns  inside query expressions
shall be recognized.</p></li>
</ul>
<p>The schema language binding may also specify the
element types in other namespaces which provide query-language-specific
ancilliary information or pragmatic hints.</p>

<p>The schema language binding shall specify any
whitespace processing required on queries.</p>

<p>A Schematron implementation which does
not support the specification language
shall fail with an error.</p>

</clause>
 
<!-- ==========================================================-->
<clause id="order">
<title>Order and side-effects</title>
<p>The order in which elements
are validated is implementation-dependent,
without altering the validity of the instance.</p>
<p>The order in which patterns are used is
implementation-dependent,
without altering the validity of the instance</p>
<p>The order in which elaborated rule-contexts
are matched is implementation-dependent,
without altering the validity of the instance
</p>
<p>The order in which assertions are tested
is implementation-dependent,
without altering the validity of the instance.</p>

<p>The only elements for which order is significant
are the sch:rule and sch:let elements.
</p>
<p>An sch:rule element acts as an if-then-else
statement within each pattern. An implementation may 
make order non-significant 
by converting rules contexts to elaborated rule contexts. 
An elaborated rule context consists the negated union
of all the lexically previous rule contexts in the same
pattern interected with the current rule context.
</p>
<note><p>The behaviour of the sch:rule element 
allows consraints that would require a complex context expression
to be factored into
simpler expressions in different rules. </p></note>
<p>An sch:let element may use lexically previous variables
within the same rule or global variables.</p>

<note><p>A wide variety of implementation
strategies are therefore possible.
</p></note>

<p>All queries shall act as pure functions. 
Queries shall not alter the instance in any
way visible to other queries. 
this standard does not specify any outcome augmentation 
of the instance being validated.</p>

<p>The only element which has a side-effect is key,
which may provide extra index information for other
queries.</p>


</clause> 
</clause>
<!-- ==========================================================-->
<clause id="vocab">
<title>Use of Schematron as a Vocabulary</title>
<p>The following Schematron element types may be used as vocabulary 
elements by other standards and schemas. The semantics of  element types used
externally shall follow this standard.
Where an element  requires other preceding or ancestor element 
to be complete, the information supplied by those elements shall
be provided by the other standard or schema.</p>
<ul>
<li><p><code>schema</code></p></li>
<li><p><code>pattern</code></p></li>
<li><p><code>rule</code></p></li>
<li><p><code>assert</code></p></li>
<li><p><code>report</code></p></li>
</ul>
</clause>

<!-- ==========================================================-->
<clause id="conformance">
<title>Conformance</title>

<clause id="simple-conformance">
<title>Simple Conformance</title>

<p>A simple-conformance  implementation shall be able 
to report for any XML document whether it may not be a valid 
Schematron schema.</p>
<ul>
<li><p>A valid schema conforms to the constraints
of <xref to="relax"/>, 
the normative Part 2 (RELAX NG) schema of this standard.</p></li> 
</ul>
<p>A simple-conformance  implementation shall 
be able to determine for any XML
document and for any good schema whether the document is
valid with respect to the schema. </p>

<note><p>It is not a requirement of <this/>
that a simple-conformance  implementation
shall be able to determine whether validation will 
terminate or whether the queries are feasible against
some other schema for the instance.
The ability to determine these
depends on the query language used.
Where the query language allows incorrectness to be established,
implementations are encouraged to report this information
as part of validation.</p></note>


<note><p>It is not a requirement of this standard 
that a simple-conformance implementation
shall be able to generate validation reports in
the Schematron Validation Report Language.
</p></note>
</clause>
<clause id="full-conformance">
<title>Full Conformance</title>

<p>A full-conformance  implementation shall be able to determine for
any XML document whether it is a correct schema.</p>
<ul>
<li><p>A valid schema conforms to the constraints
of <xref to="relax"/>, 
the normative Part 2 (RELAX NG) schema of this standard.</p></li>  
<li><p>A valid schema conforms to the constraints
of <xref to="sch"/>, 
the normative ISO Schematron schema of this standard.</p></li> 
<li><p>A correct schema's attributes conform to the grammars
specified by the query language binding in use.</p></li>
</ul>


<p>A full-conformance  implementation shall be able to determine 
for any XML document and for any good schema whether 
the document is valid with respect to the schema. 
</p>

<note><p>It is not a requirement of <this/>
that a full-conformance  implementation
shall be able to determine whether the validation will 
terminate or whether the queries are feasible against
some other schema for the instance.
The ability to determine these
depends on the query language used.
Where the query language allows incorrectness to be established,
implementations are encouraged to report this information
as part of validation.</p></note>

<note><p>It is not a requirement of this standard 
that a full-conformance  implementation
shall be able to generate validation reports in
the Schematron Validation Report Language.
</p></note>

</clause>
 </clause>
 
 
<!-- ==========================================================-->
 
<annex normative="true"  id="relax">
<title>RELAX NG schema for Schematron</title>

<p>A correct Schematron schema shall be valid with respect to the
following Part 2 (RELAX NG) schema.</p> 
<!--
<rngref src="iso-schematron.rng"/>
-->
<pre>
<![CDATA[

# Based on
# http://www.ascc.net/xml/schematron/schematron1-5.dtd, version of 2002/08/16

# James' RNC for Schematron 1.5 with:
# key removed
#schema/@ns removed
# include added
#abstract patterns and param added
#let added
# subject added with role in linkable production
# flag added
# pattern/name optional
# attribute see and fpi on more elements, with rich production
# patterns have titles rather than names
# do we need to put in declarations for xml:space and xml:lang ??


default namespace sch = "http://www.ascc.net/xml/schematron"
namespace local = ""

start = schema

# Element declarations
schema =
  element schema {
    attribute id { xsd:ID }?, 
    rich, 
    attribute schemaVersion { non-empty-string }?,
    attribute defaultPhase { xsd:IDREF }?, 
    attribute version { non-empty-string }?,
    attribute language { non-empty-string }?,
    (foreign
     & inclusion*
     &  (title?,
        ns*,
        p*,
        phase*,
        pattern+,
        p*,
        diagnostics?))
  }
active =
  element active {
    attribute pattern { xsd:IDREF },
    (foreign & (text | dir | emph | span)*)
  }
assert =
  element assert {
    attribute test { expr }, 
    attribute flag { flag }?,
    attribute id { xsd:ID }?,
    attribute diagnostics { xsd:IDREFS }?, 
    rich,
    linkable,
    (foreign & (text | name | emph | dir | span)*)
  }
dir =
  element dir {
    attribute value { "ltr" | "rtl" }?,
    (foreign & text)
  }
emph = element emph { text }
extends =
  element extends {
    attribute rule { xsd:IDREF },
    foreign-empty
  }
diagnostic =
  element diagnostic {
    attribute id { xsd:ID },
    rich, 
    (foreign & (text | value-of | emph | dir | span)*)
  }
diagnostics = element diagnostics { foreign & inclusion* & diagnostic* }

inclusions = 
	element include {
		attribute src { uri }
}
let =
	element let {
		attribute name { name },
		attribute value { string }
}
name =
  element name {
    attribute path { path }?,
    foreign-empty
  }
ns =
  element ns {
    attribute uri { uri },
    attribute prefix { xsd:NMTOKEN }?,
    foreign-empty
  }
p =
  element p {
    attribute id { xsd:ID }?,
    attribute class { class }?,
    attribute icon { uri }?,
    (foreign & (text | dir | emph | span)*)
  }
param =
	element param {
		attribute name { name },
		attribute value { non-empty-string }
}  
pattern =
  element pattern { 
    attribute id { xsd:ID }?, 
    rich,
    (foreign & inclusion* & 
     ( (attribute abstract { "true" }, title?, (p*, rule*))
     |  (attribute abstract { "false" }?, title?, (p*, rule*))
     | (attribute abstract { "false" }?, attribute is-a { xsd:IDREF }, title?, (p*, param*))
     )
  }
phase =
  element phase {
    attribute id { xsd:ID },
    rich, 
    (foreign & inclusion* & (p*, active*))
  }
report =
  element report {
    attribute test { expr }, 
    attribute flag { flag }?,
    attribute id { xsd:ID }?,
    attribute diagnostics { xsd:IDREFS }?, 
    rich,
    linkable,
    (foreign &  (text | name | emph | dir | span)*)
  } 
rule =
  element rule { 
    attribute id { xsd:ID }?, 
    rich,
    linkable,
    (foreign & inclusion* 
     & ((attribute abstract { "true" }, let*, (assert | report | extends)+)
        | (attribute context { path },
           attribute abstract { "false" }?,
           let*, (assert | report | extends)+)))
  }
span =
  element span {
    attribute class { class },
    (foreign & text)
  }
title = element title { (text | dir)* }
value-of =
  element value-of {
    attribute select { path },
    foreign-empty
  }

rich = 
    attribute icon { uri }?,
    attribute see { uri }?,
    attribute fpi { fpi }?

linkable =
    attribute role { role }?,
    attribute subject { path }?

foreign = foreign-attributes, foreign-element*

foreign-empty = foreign-attributes

foreign-attributes = attribute * - local:* { text }*
foreign-element =
  element * - sch:* {
    (attribute * { text }
     | foreign-element
     | schema
     | text)*
  }

# Data types

uri = xsd:anyURI
path = string
expr = string
fpi = string
lang = xsd:language

role = xsd:NCName
flag = xsd:NCName
name = xsd:NCName
class = xsd:NCName

non-empty-string = xsd:token { minLength = "1" }


]]>
</pre>
</annex>
<!-- ==========================================================-->

<annex normative="true" id="sch">
<title>Schematron Schema for Additional Constraints</title>

<p>A correct Schematron schema shall be valid with respect to the
following schema.</p>

<pre>
<![CDATA[
The pattern attribute of the active element shall be the same as the id attribute of a pattern.
The diagnostic attribute of the asssert and report elements shall be the same as the id attribute of a diagnostic.
The is-a attribute of an abstract pattern element shall be the same as the id attribute of a pattern.
The extends attribute of an rule element shall be the same as the id attribute of a rule.
]]>
</pre>

</annex>
<!-- ==========================================================-->
<annex normative="true" id="binding">
<title>Default Schematron Query Language Binding</title>
<p>A Schematron schema with no language binding or a <code>language</code>
attribute with the value <code>xslt</code>, in any mix of upper and lower case letters, 
shall use the following binding.</p>
<ul>
<li><p>The query language used is the extended version of
<xref to="xpath-rec"/> specified in <xref to="xslt-rec"/>.
Consequently, the data model used is the data model of those
specifications.</p></li>
<li><p>The rule context is interpreted according to the production
1 of <xref to="xslt-rec"/>. The rule context may be elements, attributes, 
comments and processing instructions.</p></li>
<li><p>The assertion test is interpreted according to 
production 14 of <xref to="xpath-rec"/>, as returning a boolean value.</p></li>
<li><p>The name query is interpreted according to
production 14  of <xref to="xpath-rec"/>, as returning a string value.</p></li>
<li><p>The value-of query is interpreted according to production
14 of <xref to="xpath-rec"/>, as returning a string value.</p></li>

<li><p>The let value is interpreted according to production
14 of <xref to="xpath-rec"/>, as returning a string value.</p></li>
<li><p>A Schematron let expression is treated 
as an <xref to="xslt-rec"/> variable. The <xref to="xslt-rec"/> $ delimiter signifies the use
of a variables in an assertion test, name query or value-of
query.</p></li>
<li><p>The notation for signifying abstract pattern is to prefix
the token with the <strong>$</strong> character. 
This is a character not found in URLs or XPaths.</p></li>
</ul>

<p>The <xref to="xslt-rec"/> <code>key</code> element may be used, in
the <xref to="xslt-rec"/> namespace, before the pattern elements.</p>

</annex>

<!-- ==========================================================-->

<annex normative="false"  id="svrl">
<title>Schematron Validation Report Language</title>
<clause>
<title>Description</title>
<p>The Schematron Validation Report Language (SVRL) is
a simple XML language which may be used for reporting the
results of Schematron validation and for conformance
suites. this standard does not specify such a conformance suite.
</p>
<p>The order of elements in an SVRL is implementation-dependent;
different implementations may generate the same elements in
a different order.</p>
</clause>
<clause>
<title>DTD</title>
<pre>
<![CDATA[
<!--
 	  Copyright note goes here
 -->

	 <!ELEMENT schematron-output  
        ( text*, ns*, (active-pattern, (fired-rule, ( failed-assert | successful-report)* )+ )+ )>
   
   <!-- only active patterns are reported -->
   <!ELEMENT active-pattern  EMPTY>
   <!-- only references are repor/08, not the diagnostic -->
   <!ELEMENT diagnostic-reference (#PCDATA)  >
   <!-- only failed assertions are reported -->
   <!ELEMENT failed-assert  ( diagnostic-reference*, text )>
   <!-- only rules that are fired are reported, abstract/extend handling
            should have been done before -->
   <!ELEMENT fired-rule EMPTY >
   <!-- only namespaces from sch:ns need to be reported -->
   <!ELEMENT ns EMPTY >
   <!-- only successful asserts are reported -->
   <!ELEMENT successful-report (  diagnostic-reference*, text ) >
   <!ELEMENT text (#PCDATA )>

    <!ATTLIST schematron-output
        title CDATA #IMPLIED
        phase NMTOKEN #IMPLIED
	schemaVersion CDATA #IMPLIED >

   <!ATTLIST active-pattern
          id ID #IMPLIED
          name CDATA #IMPLIED 
          role NMTOKEN #IMPLIED >

   <!ATTLIST diagnostic-reference
         diagnostic NMTOKEN #REQUIRED >

   <!ATTLIST failed-assert
          id ID #IMPLIED
          location CDATA #REQUIRED「
          test CDATA #REQUIRED 
          role NMTOKEN #IMPLIED 
          flag NMTOKEN #IMPLIED >         

   <!ATTLIST fired-rule
          id ID #IMPLIED
          context CDATA #REQUIRED 
          role NMTOKEN #IMPLIED 
          flag NMTOKEN #IMPLIED >         
   
   <!ATTLIST ns
          prefix NMTOKEN #REQUIRED
          uri  CDATA #REQUIRED >          

   <!ATTLIST successful-report
          id ID #IMPLIED
          location CDATA #REQUIRED
          test  CDATA #REQUIRED
          role NMTOKEN #IMPLIED 
          flag NMTOKEN #IMPLIED > 
 	
	]]>
</pre>
</clause>
<clause>
<title>Schematron Schema</title>
<p>The corresponding Schematron schema is:</p>
<pre>
<![CDATA[
<!--
 	  Copyright note goes here
 -->
 
 
<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
	<sch:title>Schema for Schematron Report Validation Language</sch:title>

	<sch:pattern>
		<sch:title>Elements</sch:title>
	
	<!--Abstract Rules -->
   <sch:rule abstract="true" name="second-level">
			<sch:assert test="../schematron-output">The <sch:name/> element is a child of schematron-output</sch:assert>
		</sch:rule>	
		
		<sch:rule abstract="true" name="childless">
			<sch:assert test="count(*)=0">The <sch:name/> element should not have any elements</sch:assert>
		</sch:rule>
		
		<sch:rule abstract="true" name="empty">
			<sch:extends rule="childless" />
			<sch:assert test="string-length(space-normalize(.)) = 0">The <sch:name/> element should be empty</sch:assert>
		</sch:rule>
		 
	<!-- Rules-->
		<sch:rule context="schematron-output">
			<sch:assert test="not(../*)">The <sch:name/> element is the root element.</sch:assert>
			<sch:assert test="count(text) + count(ns) + count(active-pattern) + count(fired-rule) +
					count(failed-assert) + count(successful-report) = count(*)">
					<sch:name/> may only contain the following elements:
					text, ns, active-pattern, fired-rule, failed-assert and successful-report.
			</sch:assert>
	   <sch:assert test="active-pattern"><sch:name/> should have at least one active pattern</sch:assert> 
		</sch:rule>	
		
		<sch:rule context="text">
			<sch:extends rule="childless" />
		</sch:rule>
		
		<sch:rule context="diagnostic-reference">
			<sch:extends rule="childless" />
			<sch:assert test="string-length(@diagnostic) &gt; 0">
				<sch:name/> should have a diagnostic attribute, giving the id of the diagnostic
				</sch:assert>
		</sch:rule>
		
		<sch:rule context="ns">
			<sch:extends rule="second-level" />
			<sch:extends rule="empty" />
			<sch:assert test="following-sibling::active-pattern or following-sibling::ns">
				A <sch:name/> comes before an active-pattern or another ns element
			</sch:assert>
		</sch:rule>
		
		<sch:rule context="active-pattern">
			<sch:extends rule="second-level" />
			<sch:extends rule="empty" />
		</sch:rule>
		
		<sch:rule context="fired-rule">
			<sch:extends rule="second-level" />
			<sch:extends rule="empty" />
			<sch:assert test="preceding-sibling::active-pattern | preceding-sibling::fired-rule | 
					preceding-sibling::failed-assert | preceding-sibling::successful-report">
				A <sch:name/> comes after an active-pattern, an empty fired-rule, a failed-assert or a 
				successful report.
			</sch:assert>
		</sch:rule>
		
		<sch:rule context="failed-assert | successful-report">
			<sch:extends rule="second-level" />
			<sch:assert test="count(diagnostic-reference) + count(text) = count(*)">
				The <sch:name/> element should only contain a text element and diagnostic reference elements.
				</sch:assert>
			<sch:assert test="count(text) = 1">
				The <sch:name/> element should only contain a text element.
				</sch:assert>
			<sch:assert test="preceding-sibling::fired-rule | preceding-sibling::failed-assert | preceding-sibling::successful-report">
				A <sch:name/> comes after a fired-rule, a failed-assert or a succesful-report.
			</sch:assert>
		</sch:rule>
		
<!-- Catch-all rule-->		
		<sch:rule context="*">
			<sch:report test="true">An unknown <sch:name/> element has been used</sch:report>
		</sch:rule>
		
	</sch:pattern>
	
	 <sch:pattern>
	 		<sch:title>Unique Ids</sch:title>
	 
	 		<sch:rule context="*[@id]">
	 			<sch:assert test="not(document-previous???:*[@id=current()/@id][1]">
	 				Id attributes should be unique in a document.
	 			</sch:assert>
	    </sch:rule>
	    
	   </sch:pattern> 
	   
</sch:schema>

]]>

</pre>
</clause>
</annex>


<annex normative = "false"  id="req" >
<title>Design Requirements</title>
<p>Motivating design requirements for the schema language include:</p>
<ol>
<li><p>Represent abstract patterns such as the <i>head+body</i> pattern.</p></li>
<li><p>Support progressive validation</p></li>
<li><p>Include assertions or abstract rules from an external file</p></li>
<li><p>Support a line-to-one mapping between the natural-language
statements and artificial-language statements</p></li>

<li><p>Support the generation and labelling of arcs between information items.</p></li>
</ol>

<p>Motivating  design requirements for the schema language do not include:</p>
<ul>
<li><p>Simple specification of contraints that are simply expressed by grammar-based validation,
such as Part 2 (RELAX NG) schemas or DTDs.</p></li>
<li><p>Replacement of any other standard schema language for XML.</p></li>
<li><p>Single-pass or streamable implementation</p></li>
</ul>


<p>As well, certain outcomes are out-of-scope for this standard:</p>
<ul>
<li><p>Specification of a type system.</p><!-- no PSVI --></li>
<li><p>Generation of links between a provided collection of documents linking 
specifications of constraints and the information items which 
meet or fail the constraints.</p><!-- XLinkIt patent? --></li>

</ul>

</annex>

<annex normative ="false">
<title>Differences from Schematron 1.6</title>
<p><code>key</code> has been removed.</p>
<p>Allow attribute, comment and PI nodes</p>

</annex>

<bibliography>

<referenced-document id="schematron">
<abbrev>Schematron</abbrev>
<title>Resource Description for Schematron (web page)</title>
<field>Rick Jelliffe</field>
<field>Computing Centre, Academia Sinica, Taipei</field>
<url>http://www.ascc.net/xml/schematron</url>
</referenced-document>

<referenced-document id="XCSL">
<abbrev>XCSL</abbrev>
<title>XML Constraint Specification Language</title>
<field>jose</field>
<field>portugal</field>
<url>http://???</url>
</referenced-document>

</bibliography>

</document>

