<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="is.css" ?>

<!-- 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
Also allow <this> in <definition>
-->

<!-- To edit this file, you will need to use a font
  with mathematical operators such as Lucida Sans Unicode
  See s4.2 for a full listing, but they include
 	∀  For All
 	∈  Element Of
 	¬ Not Sign
 
 	The emdash is marked up by NCR.
-->

<!--
TODO

inclusions
is $

-->


<document >

<head> 
<organization>ISO/IEC</organization>
<document-type>International Standard</document-type>
<stage>approval</stage>
<secretariat>ANSI</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-05-31</date>
</head>

<foreword>

<part-list>

<part><number>1</number><title>Overview</title></part>
<part><number>2</number><title>Grammar-based validation &#x2014; RELAX NG</title></part>
<part><number>3</number><title>Rule-based validation &#x2014; Schematron</title></part>
<part><number>4</number><title>Namespace-based validation dispatching language — NVDL</title></part>
<part><number>5</number><title>Datatypes</title></part>
<part><number>6</number><title>Path-based integrity constraints</title></part>
<part><number>7</number><title>Character reportoire validation</title></part>
<part><number>8</number><title>Declarative document manipulation</title></part>
<part><number>9</number><title>Datatype- and namespace-aware DTDs</title></part>
<part><number>10</number><title>Validation management</title></part>
</part-list>

</foreword>

<!-- ==========================================================-->
<introduction>
<p>This International Standard defines a set of Document Schema Definition Languages (DSDL) that can be used to
specify one or more validation processes performed against Extensible Markup Language (XML) documents. A
number of validation technologies are standardized in DSDL to complement those already available as standards
or from industry.</p>
<p>The main objective of this International Standard is to bring together different validation-related technologies to
form a single extensible framework that allows technologies to work in series or in parallel to produce a single or a
set of validation results. The extensibility of DSDL accommodates validation technologies not yet designed or
specified.
</p>

<p>The structure of <this>this part of ISO/IEC 19757</this> 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 annex providing the Part 2 (RELAX NG)  schema
for ISO Schematron. 
</p></li>
<li ><p><xref to="sch"/> is a normative annex 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 annex 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>
<li ><p ><xref to="vocab"/> is a normative annex allowing certain Schematron
elements
to be used in external vocabularies.</p></li>

<li ><p ><xref to="multi"/> is a non-normative annex with a simple example
of a multi-lingual schema.</p></li>
</ul>
<p><This>This part of ISO/IEC 19757</This> is based on the <xref to="schematron"/>
assertion language.
The <code>let</code> element is based on <xref to="XCSL"/>.
Other features arise from the half-dozen early Open Source implementations of Schematron
in diverse programming languages 
and from discussions in electronic forums by Schematron users and implementers.</p>

</introduction>

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

<p><This>This part of ISO/IEC 19757</This> 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  
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>This part of ISO/IEC 19757</This> 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="xml-rec">
<abbrev>W3C XML 1.0</abbrev>
<title>Extensible Markup Language (XML) 1.0 (Third Edition)</title>
<field>W3C Recommendation</field>
<url>04 February 2004</url>
</referenced-document>

<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>

<term-and-definition>
<term>abstract pattern</term>
<definition>a pattern in a rule
to some extent parameterised</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>active phase</term>
<definition>one particular phase, whose patterns are 
used for validation</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>assertion</term>
<definition>a natural-language assertion with corresponding assertion
test and ancillary attributes. Assertions are marked up with
<code>assert</code> and <code>report</code> elements.</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>correct schema</term>
<definition>schema that satisfies all the requirements of
<this>this part of ISO/IEC 19757</this></definition>
</term-and-definition>


<term-and-definition>
<term>diagnostic</term>
<definition>named natural language statements
providing information to end-users of validators
concerning the expected and actual values 
together with
repair hints</definition>
</term-and-definition>
 
 <term-and-definition>
<term>elaborated rule context expression</term>

<definition>a single rule context expression which explicitly disallows
items selected by lexically previous rule contexts in the same pattern.
</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 may not be possible to compute
that a schema is good.
</definition>
</term-and-definition>

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


<term-and-definition>
<term>name</term>
<definition>a token with no whitespace characters</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>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>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>progressive validation</term>
<definition>the validation of constraints in 
stages determined or grouped to some extent 
by the schema author
rather than, for example, entirely determined by
document order </definition>
</term-and-definition>

<term-and-definition>
<term>query language binding</term>

<definition>a named set, specified in a document
called a Query Language Binding, of the 
languages and conventions used for assertion tests,
rule-context expressions and so on, by a particular
Schematron implementation. Schematron is defined
as a framework, with a default query language
binding, but other query language bindings are possible.
<xref to="querylang"/> 
specifies the information to be required by a query language
binding and <xref to="binding"/> defines the default
query language binding for Schematron.
</definition></term-and-definition>

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

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

</term-and-definition>

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

<term-and-definition>
<term>rule</term>
<definition>unordered collection of assertions
with a rule-context expression and ancillary 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 an information item
when that information item
that has not been matched by any lexically-previous rule
context expressions in the same pattern
and the information item is one of the information items
that the query would specify</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>variable</term>
<definition>a constant value, evaluated 
within within the parent 
schema, phase, pattern or rule
and visible scoped within the parent
schema, phase, pattern or rule</definition>
</term-and-definition>


</terms-and-definitions>




<!-- ==========================================================-->
<clause><title>Notation</title>
<clause>
<title>XPath</title>
<p><This>This part of ISO/IEC 19757</This> uses <xref to="xpath-rec"/> to identify 
information items in Schematron schemas. 
</p>

</clause><clause>
<title>Predicate Logic</title>
<p><This>This part of ISO/IEC 19757</This> uses predicate logic to express the semantics of
Schematron schema. 
The following symbols are defined for use in s6.3:</p>
<notation-list>





<notation-item><notation><symbol>()</symbol></notation>
<notation-definition>
<p>
   Grouping delimiters</p></notation-definition></notation-item>

<notation-item><notation><symbol>∃</symbol></notation>
<notation-definition>
<p>
 "there exists". Prefix operator. </p></notation-definition></notation-item>

<notation-item><notation><symbol>∀</symbol></notation>
<notation-definition>
<p>
 "for all". Prefix operator.</p></notation-definition></notation-item>
 
<notation-item><notation><symbol>¬</symbol></notation>
<notation-definition>
<p> 
 "not". Prefix operator.</p></notation-definition></notation-item>
 
<notation-item><notation><symbol>∈</symbol></notation>
<notation-definition>
<p>
 "is member of", in set operative sense. Prefix operator. </p></notation-definition></notation-item>
  
<notation-item><notation><symbol>,</symbol></notation>
<notation-definition>
<p> 
  "and" (sequence). Infix operator.</p></notation-definition></notation-item>
  
<notation-item><notation><symbol>: </symbol></notation>
<notation-definition>
<p>
  "where". Such that. Infix operator.</p></notation-definition></notation-item>
  
<notation-item><notation><symbol>⇔</symbol></notation>
<notation-definition>
<p>
  "such that". Infix operator.</p></notation-definition></notation-item>

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

<!-- ==========================================================-->
<clause id="syntax">
<title>Syntax</title>


<clause id="basic">
<title>Well-formedness</title>
<p>A Schematron schema shall be a well-formed XML document,
according to the version of XML used.</p>
</clause>

<clause id="namespace">
<title>Namespace</title>

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

<pre>http://purl.oclc.org/dsdl/schematron</pre>

<p>In subsequent clauses, the prefix <code>sch</code> is taken as
bound to the Schematron namespace URI for exposition purposes.
The prefix <code>sch</code> is not reserved or required by
<this>this part of ISO/IEC 19757</this>. 
</p>

<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>
</clause>

<clause id="whitespace">
<title>Whitespace</title>
<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>


<note><p>Leading and trailing whitespace should be stripped
from attributes defined by this part. 
whitespace should be collapsed in elements that allow text
 defined by this part.
Whitespace may be stripped from elements defined by this part
that do not allow
text.</p>
</note>

   
 </clause>

<!-- ==========================================================-->
<clause>
<title>Core Elements</title>
<p>The grammar for Schematron elements is given in <xref to="relax"/>.</p>

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

<p>The required <code>pattern</code> attribute is
a reference to 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 content 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. Users should note, however, that
the <code>diagnostic</code> element is provided
for such information to encourage clear statement
of the natural-language assertion.</p></note> 

<p>The <code>icon</code>, <code>see</code> and
 <code>fpi</code> attributes allow rich interfaces
 and documentation. They are defined below.</p>
 
<p>The <code>flag</code> attribute allows more detailed
outcomes. It is defined below.</p>
 
<p>The <code>role</code> and
<code>subject</code> attributes allow explicit identification
of some part of a pattern.
They are defined below.</p> 
 
</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>href</code> attribute references
an external well-formed XML document whose document element
is a Schematron element
of a type which allowed by the grammar for Schematron
at the current position in the schema. 
The external document is inserted in place of the <code>include</code>
element.</p>

</clause>

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

<p>A declaration of a named variable. 
If the let element is the child of a <code>rule</code> element, 
the variable is calculated and scoped to the current rule
and context. Otherwise, the variable is calculated  with the context
of the instance document root.</p> 
<p>The required <code>name</code> attribute is the name of the
variable.  The required <code>value</code> attribute is an
expression evaluated in the current context. </p>
<p>It is an error to reference a variable that has not been defined
in the current schema, phase, pattern, or rule, if the query 
language binding allows this to be determined reliably. It is an error
for a variable to be multiply defined in the current schema, phase,
pattern and rule. </p>
<p>The variable is substituted into 
assertion tests and other expressions in the same rule
before the test or expression is evaluated. The query language binding 
specifies which lexical conventions are used to detect
references to variables.</p>
<p>An implementation may provide a facility to override the 
values of top-level variables specified by <code>let</code> elements
under the <code>schema</code> element. For example, an implementation
may allow top-level variables to be supplied on the command line.
The values provided are strings or data objects, not expressions.</p>


</clause>



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

<p>Provides the names of nodes from the instance document to
allow clearer assertions and diagnostics. 
The optional <code>path</code> attribute is an expression 
evaluated in the current context that returns a string that is
the name of a node. In the latter case,
the name of the node is used.   
</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>
<note><p>Because the characters allowed as names may change
in versions of XML subsequent to
<xref to="xml-rec"/>, the RELAX NG Compact schema
for Schematron does not constrain the prefix to particular 
characters.</p></note>
<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>
</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>A structure, simple or complex. A set of rules 
giving constraints that are in some way related. 
The required <code>name</code> attribute is
the name of the pattern. 
</p>
<p>The <code>title</code> and <code>p</code> elements
allow rich documentation.</p>
<p>The <code>icon</code>, <code>see</code> and
 <code>fpi</code> attributes allow rich interfaces
 and documentation.</p>

<p>When a <code>pattern</code> element has the
attribute <code>abstract</code> with a value
<code>true</code>, then the pattern defines an abstract pattern.
An abstract pattern shall not have a <code>is-a</code> attribute
and shall have a <code>name</code> attribute.</p>

<p>Abstract patterns allow a common definition mechanism
for structures which use different names and paths, but which
are at heart the same. For example, there are different 
table markup languages, but they all can be in large part
represented as an abstract pattern where a table contains
rows and rows contain entries, as defined in the following example
using the default query language binding:</p>
<pre><![CDATA[
	<sch:pattern abstract="true" name="table">
		<sch:rule context="$table">
			<sch:assert test="$row">
			The element <name/> is a table.
			Tables contain rows.
			</sch:assert>
		</sch:rule>
		
		<sch:rule context="$row">
			<sch:assert test="$entry">
			The element <name/> is a table row.
			Rows contain entries.
			</sch:assert>
		</sch:rule>
		
	</sch:pattern>
]]></pre>

<p>When a <code>pattern</code> element has the
attribute <code>is-a</code> with a value
specifying the name of an abstract pattern, then the pattern 
is an instance of an abstract pattern.
Such a pattern shall not contain any <code>rule</code>
elements, but shall have <code>param</code> elements
for all parameters used in the abstract pattern.
</p>


<p>The following example uses the abstract pattern
for tables given above to create three patterns for
tables with different names or structures.</p>
<pre><![CDATA[
	<sch:pattern is-a="table" name="HTML_Table">
		<sch:param name="table" value="table"/>
		<sch:param name="row"   value="tr"/>
		<sch:param name="entry" value="td|th"/>
	</sch:pattern>
	
	<sch:pattern is-a="table" name="CALS_Table">
		<sch:param name="table" value="table"/>
		<sch:param name="row"   value=".//row"/>
		<sch:param name="entry" value="cell"/>
	</sch:pattern>
	
	<sch:pattern is-a="table" name="calendar">
		<sch:param name="table" value="calendar/year"/>
		<sch:param name="row"   value="week"/>
		<sch:param name="entry" value="day"/>
	</sch:pattern>
]]></pre>
<p>When creating an instance of an abstract pattern,
the parameter values supplied by the <code>param</code>
element replace the parameter references used in
the abstract patterns. The examples above use the
default query language binding in which the character
<strong>$</strong> is used as the delimiter for 
parameter references.</p>
<p>Thus, given the abstract patterns defined earlier in this
clause, the patterns defined above
are equivalent to
the following, with the <code>name</code>
elements shown expanded:</p>
<pre><![CDATA[
	<sch:pattern name="HTML_table">
		<sch:rule context="table">
			<sch:assert test="tr">
			The element table is a table.
			Tables containing rows.
			</sch:assert>
		</sch:rule>
		
		<sch:rule context="tr">
			<sch:assert test="td|th">
			The element tr is a table row.
			Rows contain entries.
			</sch:assert>
		</sch:rule>
		
	</sch:pattern>
	
	<sch:pattern name="CALS_table">
		<sch:rule context="table">
			<sch:assert test=".//row">
			The element table is a table
			Tables containing rows.
			</sch:assert>
		</sch:rule>
		
		<sch:rule context=".//row">
			<sch:assert test="cell">
			The element row is a table row.
			Rows contain entries.
			</sch:assert>
		</sch:rule>
		
	</sch:pattern>
	
	<sch:pattern name="calendar">
		<sch:rule context="calendar/year">
			<sch:assert test="week">
			The element year is a table.
			Tables containing rows.
			</sch:assert>
		</sch:rule>
		
		<sch:rule context="week">
			<sch:assert test="day">
			The element week is a table row.
			Rows contain entries.
			</sch:assert>
		</sch:rule>
		
	</sch:pattern>
]]></pre>
</clause>


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

<p>A grouping of patterns, to name and declare 
variations in schemas, 
for example, to support progressive validation.
The required <code>id</code> attribute is
the name of the phase. The implementation
determines which phase to use for validating
documents, for example by user command. 
</p>

<p>Two names <code>#ALL</code> and <code>#DEFAULT</code>
have special meanings.
The name <code>#ALL</code> is reserved
and available for use by implementations
denoting that all patterns
are active. The name <code>#DEFAULT</code> is
reserved and available for use by implementations
denoting that the name given in
in the <code>defaultPhase</code> attribute on the
<code>schema</code> element should be used.
If no <code>defaultPhase</code> is specified, then
all patterns are active.
</p>
<note><p>The names <code>#ALL</code> and <code>#DEFAULT</code>
shall not be used in a Schematron schema. 
They are for use when invoking or configuring schema validation,
for example as a command-line parameter.</p></note>

<p>The <code>icon</code>, <code>see</code> and
 <code>fpi</code> attributes allow rich interfaces
 and documentation.</p>
</clause>

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

<p>An assertion made about the context nodes.
The data content 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. Users should note, however, that
the <code>diagnostic</code> element is provided
for such information to encourage clear statement
of the natural-language assertion.</p></note> 

<p>The <code>icon</code>, <code>see</code> and
 <code>fpi</code> attributes allow rich interfaces
 and documentation. They are defined below.</p>
 
 
<p>The <code>flag</code> attribute allows more detailed
outcomes. It is defined below.</p>
 
<p>The <code>role</code> and
<code>subject</code> attributes allow explicit identification
of some part of a pattern.
They are defined below.</p>
</clause>


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

<p>A list of assertions tested within the context
specified by the required <code>context</code> attribute.
The <code>context</code> attribute specifies 
the rule context expression.</p>

 <note><p>It is not an error if a rule never fires 
 in a document. In order to test that a document
 always has some context, a new pattern should
 be created from the context of the document,
 with an assertion requiring the element or attribute.</p></note>

<p>The <code>icon</code>, <code>see</code> and
 <code>fpi</code> attributes allow rich interfaces
 and documentation.</p>

<p>The <code>flag</code> attribute allows more detailed
outcomes. It is defined below.</p>
  
 
<p>The <code>role</code> and
<code>subject</code> attributes allow explicit identification
of some part of a pattern as part of the validation outcome.
They are defined below.</p>

<p>When the <code>rule</code> element has the
attribute <code>abstract</code> with a value
<code>true</code>, then the rule is an abstract rule.
An abstract rule shall not have a <code>context</code> attribute.
An abstract rule is a list of assertions that will be
invoked by other rules belonging to the same pattern
using the <code>extends</code>
element. Abstract rules provide a mechanism for
reducing schema size.</p>

</clause>

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

<p>The top-level element of a Schematron schema.
</p> 
<p>The optional <code>schemaVersion</code> attribute 
gives the version of the schema. Its allowed values are
not defined by <this>this part of ISO/IEC 19757</this>
and its use is implementation-dependent.</p>
<p>The optional <code>queryBinding</code> attribute
provides the short name of the query language binding
in use. If this attribute is specified, it is an
error if it has a value that the current implementation
does not support.</p>
<p>The <code>defaultPhase</code> attribute may be used
to indicate the phase to use in the absence of 
explicit user-supplied information.</p>
<p>The <code>title</code> and <code>p</code> elements
allow rich documentation.</p>
<p>The <code>icon</code>, <code>see</code> and
 <code>fpi</code> attributes allow rich interfaces
 and documentation.</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 a string.
</p>
<p>Variable references in the <code>select</code> attribute are resolved
in the scope of the current schema, phase, pattern and rule.</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>Ancillary Elements and Attributes</title>


 <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>

<note><p>Diagnostics in multiple languages may be supported
by using a different <code>diagnostic</code> element
for each language, with the appropriate <code>xml:lang</code>
language attribute, and referencing all the unique identifiers
of the <code>diagnostics</code> elements in the 
<code>diagnostics</code> attribute of the assertion.
<xref to="relax"/> gives a simple example of a multi-lingual 
schema.</p></note>

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

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

<p>Section containing individual diagnostic elements.</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 initial 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
and other element.
</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 given
by the <code>subject</code> attribute.
</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 
context node of the current rule. If no 
subject attribute is specified, the
current subject node may be used.</p>

<note><p>The <code>subject</code> attribute is required because
the rule context may have been selected for reasons of
convenience or performance, in association with the particular
assertion tests. In such cases, the rule context may not be
be useful to identify to users, and the nodes located by the
<code>subject</code> attribute may be
more useful. Similarly, it may not be possible to determine
from an assertion test which nodes the assertion test has tested.
In such a case, the nodes located by the
<code>subject</code> attribute may be
more useful.</p></note>

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



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

<p>A summary of the purpose or role of the schema  or pattern,
for the purpose of documentation or a rich user interface.</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 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.
</p>
<note><p><This>This part of ISO/IEC 19757</This> does not constrain other information 
provided by an implementation nor
other uses of Schematron schemas.
However, it is the intent of <this>this part of ISO/IEC 19757</this> to support implementations
to provide rich, specific diagnostics customised 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 <code>defaultPhase</code> 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>Minimal Syntax</title>


<p>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:</p>
<ol>
<li><p>Resolve all inclusions by replacing the <code>include</code> element
by the resource linked to.</p></li>
<li><p>Resolve all abstract patterns by replacing parameter references
 with actual parameter values in all enclosed attributes that contain
 queries.</p></li>
<li><p>Resolve all abstract rules in the schema by replacing the
<code>extends</code> elements with the contents of the abstract rule
identified.</p></li>
<li><p>Negate all sch:report elements into sch:assert elements.</p></li>
<li><p>Remove elements used for diagnostics and documentation.</p></li>
</ol>
<p>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: </p>
<ul>
<li><p><code>//sch:include</code></p></li>
<li><p><code>//sch:pattern[@abstract="true"]</code></p></li>
<li><p><code>//sch:pattern[@is-a]</code></p></li>
<li><p><code>//sch:rule[@abstract="true"]</code></p></li>
<li><p><code>//sch:extends</code></p></li>
<li><p><code>//sch:report</code></p></li>
<li><p><code>//sch:diagnostics</code></p></li>
<li><p><code>//sch:p</code></p></li>
<li><p><code>//sch:title</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 
resolved into the minimal form.</p>

<p>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.     </p>

<p>A document is valid in respect to a schema 
in a phase when
the following predicate is satisfied:      </p>
              
<pre><symbol>∀</symbol> ( context, pattern, rule, assertion):
       ( 
        context <symbol>∈</symbol> instance,
        active-phase <symbol>∈</symbol> schema,  
        pattern <symbol>∈</symbol> active-phase,
        rule <symbol>∈</symbol> pattern,
		assertion <symbol>∈</symbol> rule :
			(
			match ( rule, context, instance ),
			<symbol>∀</symbol> (previous-rule) :
			    (
				previous-rule <symbol>∈</symbol> pattern,
				position (previous-rule) &lt; position( rule):
				 	<symbol>¬</symbol> match(previous-rule, context, instance))
				 )
			)
	    )	
	<symbol>⇔</symbol> assert ( assertion, context, instance) = true
</pre>	

<p>where</p>
  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.

<note><p>In natural language, a document is valid against a schema
in a phase if:

<i>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.</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 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 <code>name</code> query language, a function which returns a 
data value coerceable into a string.</p></li>
<li><p>The <code>value-of</code> query language, a function which returns a 
data value coerceable into a string.</p></li> 
<li><p>The <code>let</code> 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 recognised.</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 recognised.</p></li>
</ul>
<p>The query language binding may also specify the
element types in other namespaces which provide query-language-specific
ancillary information or pragmatic hints.</p>

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

<p>The query language binding shall specify any restrictions
to the value of name tokens.</p>

<p>A Schematron implementation which does
not support the query language binding, specified
in a schema with the <code>queryBinding</code> attribute,
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 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 <code>rule</code> and <code>let</code> elements.
</p>
<p>An <code>rule</code> 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. 
</p>
<note><p>The behaviour of the <code>rule</code> element 
allows constraints that would require a complex context expression
to be factored into
simpler expressions in different rules. </p></note>
<p>An <code>let</code> 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>This part of ISO/IEC 19757</This> does not specify any outcome augmentation 
of the instance being validated.</p>




</clause> 
</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 Compact Syntax) 
schema of <this>this part of ISO/IEC 19757</this>.</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>this part of ISO/IEC 19757</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>this part of ISO/IEC 19757</this> 
that a simple-conformance implementation
shall be able to generate validation reports in
the Schematron Validation Report Language,
defined in <xref to="svrl"/>.
</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 Compact Syntax) schema of <this>this part of ISO/IEC 19757</this>.</p></li>  
<li><p>A valid schema conforms to the constraints
of <xref to="sch"/>, 
the normative ISO Schematron schema of <this>this part of ISO/IEC 19757</this>.</p></li> 
<li><p>A correct schema's attributes conform to the grammars
specified by the query language binding in use.</p></li>
<li><p>A correct schema has one 
definition only in scope for any variable name in any context.</p></li>
<li><p>The values of the attributes <code>prefix</code>, 
<code>name</code> and <code>flag</code> are well-formed names in the
version of XML being used.</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>this part of ISO/IEC 19757</this> 
that a full-conformance  implementation
shall be able to generate validation reports in
the Schematron Validation Report Language,
defined in <xref to="svrl"/>.
</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 schema (RELAX NG Compact Syntax).</p> 

<pre xml:space="preserve" >
<![CDATA[
# 	  (c) International Organization for Standardization 2005. 
# 	  Permission to copy in any form is granted for use with conforming 
# 	  SGML systems and applications as defined in ISO 8879, 
# 	  provided this notice is included in all copies.

default namespace sch = "http://purl.oclc.org/dsdl/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 queryBinding { non-empty-string }?,
    (foreign
     & inclusion*
     &  (title?,
        ns*,
        p*,
        let*,
        phase*,
        pattern+,
        p*,
        diagnostics?))
  }
active =
  element active {
    attribute pattern { xsd:IDREF },
    (foreign & (text | dir | emph | span)*)
  }
assert =
  element assert {
    attribute test { exprValue }, 
    attribute flag { flagValue }?,
    attribute id { xsd:ID }?,
    attribute diagnostics { xsd:IDREFS }?, 
    rich,
    linkable,
    (foreign & (text | name | value-of | emph | dir | span)*)
  }

diagnostic =
  element diagnostic {
    attribute id { xsd:ID },
    rich, 
    (foreign & (text | value-of | emph | dir | span)*)
  }
  
diagnostics = element diagnostics { foreign & inclusion* & diagnostic* }
    
dir =
  element dir {
    attribute value { "ltr" | "rtl" }?,
    (foreign & text)
  }

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

# common declarations
rich = 
    attribute icon { uriValue }?,
    attribute see { uriValue }?,
    attribute fpi { fpiValue }?,
    attribute xml:lang { langValue }?,
    attribute xml:space { "preserve" | "default" }?

inclusion = 
	element include {
		attribute href { uriValue }
}

linkable =
    attribute role { roleValue }?,
    attribute subject { pathValue }?

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

uriValue = xsd:anyURI
pathValue = string
exprValue = string
fpiValue = string
langValue = xsd:language
roleValue = string  
flagValue = string
nameValue = string  # In the default query language binding, xsd:NCNAME
classValue = string

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 Schematron schema.</p>

<pre xml:space="preserve">
<![CDATA[
<!--
 	  (c) International Organization for Standardization 2005. 
 	  Permission to copy in any form is granted for use with conforming 
 	  SGML systems and applications as defined in ISO 8879, 
 	  provided this notice is included in all copies.
 -->
 
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" 
	 xml:lang="en" >
	<sch:title>Schema for Additional Constraints in Schematron</sch:title>
	<sch:ns prefix="sch" uri="http://purl.oclc.org/dsdl/schematron" />
	
	<sch:p>This schema supplies some constraints in addition to those
	given in the ISO RELAX NG Schema for Schematron. 
	</sch:p>
	
	<sch:pattern> 
		<sch:rule context="sch:active">
			<sch:assert test="//sch:pattern[@id=current()/@pattern]">
			The pattern attribute of the active element shall match an 
			id attribute of a pattern.
			</sch:assert>
		</sch:rule>
	
		<sch:rule context="sch:pattern[@is-a]">
			<sch:assert test="//sch:pattern[@abstract='true'][@id=current()/@is-a]">
			The is-a attribute of a pattern element shall match 
			the id attribute of an abstract pattern.
			</sch:assert>
		</sch:rule>

		<sch:rule context="sch:extends">
			<sch:assert test="//sch:rule[@abstract='true'][@id=current()/@rule]">
			The rule attribute of an extends element shall match 
			the id attribute of an abstract rule.
			</sch:assert>
		</sch:rule>	
		
		
		<sch:rule context="sch:let">
			<sch:assert test=
				"not(//sch:pattern[@abstract='true']/sch:param[@name=current()/@name])">
			Variable names and abstract pattern parameters share the same namespace.
			</sch:assert>
		</sch:rule>	
			
	</sch:pattern>
</sch:schema>	
]]>
</pre>

</annex>
<!-- ==========================================================-->
<annex normative="true" id="binding">
<title>Default 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.
Typically, the <code>select</code> attribute contains an expression
returning an element node: the name query takes the local or prefixed name of the
node, not its 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>The notation for signifying the use of parameter of an abstract pattern is to prefix
the name token with the <strong>$</strong> character. 
This is a character not found as a delimiter in URLs or XPaths.
The <strong>$</strong> character not followed by the name
of an in-scope parameter shall not be
treated as a parameter name delimiter. Such a character may 
subsequently be used as a delimiter for a variable name or as
a literal character. </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 context expression, assertion test, name query, value-of
query or let expression.
The <strong>$</strong> character not followed by the name
of an in-scope variable shall be
treated as a literal character.</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>
<p>The attributes <code>name</code> and <code>prefix</code> should
follow the rules for non-colonized names 
for the version of XML used by the document.
</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. 
</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 xml:space="preserve" >
<![CDATA[
<!--
 	  (c) International Organization for Standardization 2005. 
 	  Permission to copy in any form is granted for use with conforming 
 	  SGML systems and applications as defined in ISO 8879, 
 	  provided this notice is included in all copies.
 -->

	 <!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 reported, 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 xml:space="preserve">
<![CDATA[
<!--
 	  (c) International Organization for Standardization 2005. 
 	  Permission to copy in any form is granted for use with conforming 
 	  SGML systems and applications as defined in ISO 8879, 
 	  provided this notice is included in all copies.
 -->
 
 <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" 
	xml:lang="en" >
	<sch:title>Schema for Schematron Validation Report Language</sch:title>
	
	<sch:p>The Schematron Validation Report Language is a simple language for
		implementations to use to compare their conformance. It is basically a
		list of all the assertions that fail when validating a document, in any
		order, together with other information such as which rules fire.
	</sch:p>
	<sch:p>This schema can be used to validate SVRL documents, and provides
	examples of the use of abstract rules and abstract patterns.</sch:p>
	
	<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 contain 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:assert test="string-length(@context) &gt; 0">
				The <sch:name/> element should have a context attribute giving the
				current context, in simple XPath format.
			</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(preceding::*[@id=current()/@id][1]"> 
				Id attributes should be unique in a document.
			</sch:assert>
		</sch:rule>
	</sch:pattern>
	
	<sch:pattern abstract="true" name="requiredAttribute">
		<sch:rule context=" $context ">
			<sch:assert test="string-length( $attribute ) &gt; 0">
				The <sch:name/> element should have a 
				<sch:value-of select="$attribute /name()" /> attribute.
			</sch:assert> 
		</sch:rule>
	</sch:pattern>
	
	<sch:pattern is-a="requiredAttribute">
		<sch:param name="context" value="diagnostic-reference" />
		<sch:param name="attribute" value="@diagnostic" />
	</sch:pattern>	
	
	<sch:pattern is-a="requiredAttribute">
		<sch:param name="context" value="failed-assert or successful-report" />
		<sch:param name="attribute" value="@location" />
	</sch:pattern>	
	
	<sch:pattern is-a="requiredAttribute">
		<sch:param name="context" value="failed-assert or successful-report" />
		<sch:param name="attribute" value="@test" />
	</sch:pattern>	

	<sch:pattern is-a="requiredAttribute">
		<sch:param name="context" value="ns" />
		<sch:param name="attribute" value="@uri" />
	</sch:pattern>	
	
	<sch:pattern is-a="requiredAttribute">
		<sch:param name="context" value="ns" />
		<sch:param name="attribute" value="@prefix" />
	</sch:pattern>				
	
</sch:schema>

]]>

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


<annex normative = "false"  id="req" >
<title>Design Requirements</title>
<p>Motivating design requirements for the schema language with the default
query language binding 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 one-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 with the default
query language binding do not include:</p>
<ul>
<li><p>Simple specification of constraints 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>this part of ISO/IEC 19757</this>:</p>
<ul>
<li><p>Specification of a type system.</p><!-- no PSVI --></li>
<li><p>Generation of links between multiple occurrences of
some datum across multiple documents for the purpose of consistency-checking.</p><!-- XLinkIt patent --></li>

</ul>

</annex>
 
 
 <!-- ==========================================================-->
 <annex normative = "true"  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>this part of ISO/IEC 19757</this>.</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>
<p>These elements should be use the standard Schematron namespace
specified in <xref to="namespace"/>.</p>

<p>When Schematron elements other than the <code>schema</code>
element are used as vocabulary elements by other standards
and schemas, the other standard or schema should specify
mechanisms for defining information otherwise supplied by
Schematron elements, such as <code>ns</code> or <code>let</code>.</p>
</annex>

 
 <!-- ==========================================================-->
 <annex normative = "false"  id="multi">
<title>Use of Schematron for Multi-Lingual Schemas</title>
<p>The following Schematron schema shows how multiple languages
may be supported.</p>
<pre xml:space="preserve">
<![CDATA[

 <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" 
	 xml:lang="en" >
	<sch:title>Example of Multi-Lingual Schema</sch:title>

	<sch:pattern>
		<sch:rule context="dog">
			<sch:assert test="bone" diagnostics="d1 d2">
			A dog should have a bone.
			</sch:assert>
		</sch:rule>
	</sch:pattern>
	
	<sch:diagnostics>
		<sch:diagnostic id="d1" xml:lang="en">
		A dog should have a bone.
		</sch:diagnostic>
		<sch:diagnostic id="d2" xml:lang="de">
		Das Hund muss ein Bein haben.
		</sch:diagnostic>
	</sch:diagnostics>
	
</sch:schema>
			
]]>

</pre>
</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://purl.oclc.org/dsdl/schematron</url>
</referenced-document>

<referenced-document id="XCSL">
<abbrev>XCSL</abbrev>
<title>XML Constraint Specification Language</title>
<field>José Carlos Leite Ramalho</field>
<field>Department of Informatics, School of Engineering, University of
Minho</field>	
<url>http://www.di.uminho.pt/~jcr/PROJS/xcsl-www/</url>
</referenced-document>

</bibliography>

</document>
