<?xml version="1.0" ?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
	schemaVersion="1.0beta">
	<title>Extra Constraints for XML Schemas</title>
	
	<ns prefix="xsd" uri="http://www.w3.org/2001/XMLSchema" />

	<p>This Schematron schema is an example of using path expressions to express
	the various constraints on W3C XML Schemas that cannot be expressed using
	XML Schemas (i.e. in the "schema for schemas").</p> 
	
	<p>This schema is only a fraction of the constraints. "Representation
	Constraints" can be fairly simply expressed: the number of terms in the
	tests are only complex because the constraints themselves are complex.
	"Component Constraints" are more difficult to express, because they may
	rely on datatype or components in included or imported documents. In those
	cases, the assertion (text) is given but no test is given.</p>	 
	
	<p>Some constraints are further divided into subgroups. The diagnostics
	element has been used to note these, however they could be separate patterns.
	</p>

	<p>Some constraints are not testable, and so do not require assertions.</p>
	<p class="li">Schema Representation Constraint: Schema Document Location Strategy OK </p>
	<p class="li">Schema Representation Constraint: Annotation Definition Representation OK </p>
 
	
	
	
	<pattern id=""  see="http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#src-attribute">
		<title>Schema Representation Constraint: Attribute Declaration Representation OK</title>
		<p>In addition to the conditions imposed on &lt;attribute> element information items by the schema for schemas, all of the following must be true:
</p>
		<rule context="xsd:attribute">
			<assert test="not ( @default and @fixed )">
			default and fixed must not both be present.</assert>
			<assert test="not ( @ default and @use) or @use='optional' ">
			If default and use are both present, use must have the ·actual value· optional.</assert>
			<assert test="parent::xsd:schema or (@ref and not(@name)) or @name ">
			If the item's parent is not &lt;schema>, then 
			one of ref or name must be present, but not both.</assert>
			<assert test="parent::xsd:schema or ( @ref and not( simpleType ) and
			not (@form) and not(@type))">
			If the item's parent is not &lt;schema>, then 
	    	if ref is present, then all of &lt;simpleType>, form and type must be absent.</assert>
			<assert test="not (@type and simpleType)">
			type and &lt;simpleType> must not both be present.</assert>
		 
		</rule>
	</pattern>
	
	<pattern id="coss-attribute"  see="http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#coss-attribute">
		<title>Constraints on Attribute Declaration Schema Components</title>
		<p>All attribute declarations must satisfy the following constraints.</p>
		
		<rule context="xsd:attribute">
		
			<assert test="true()" diagnostics="d1">
			The values of the properties of an attribute declaration must be as 
			described in the property tableau in The Attribute Declaration Schema 
			Component (§3.2.1), modulo the impact of Missing Sub-components (§5.3).
			</assert>
			<assert test="true()">if there is a {value constraint}, the canonical 
			lexical representation of its value must be ·valid· with respect to 
			the {type definition} as defined in String Valid (§3.14.4).
			</assert>
			<assert test="true()">
			If the {type definition} is or is derived from ID then there must not 
			be a {value constraint}.
			</assert>
			<assert test="not(name() = 'xmlns' )" diagnostics="d2" >
			The {name} of an attribute declaration must not match xmlns.</assert>
			<assert test="true()" diagnostics="d3">
			The {target namespace} of an attribute declaration, whether local 
			or top-level, must not match http://www.w3.org/2001/XMLSchema-instance 
			unless it is one of the four built-in declarations given in the next 
			section).</assert>
				<!-- probably this can be tested! -->
		
			
		</rule>
	</pattern>
	
	<p class="h2">To Do</p>
    <p>We want the constraint that only one attribute can be declared.</p>
    
	<diagnostics>
		<diagnostic id="d1">
		Schema Component Constraint: Attribute Declaration Properties Correct 
		</diagnostic>
		<diagnostic id="d2">
		Schema Component Constraint: xmlns Not Allowed
		</diagnostic>
		<diagnostic id="d3">
		Schema Component Constraint: xsi: Not Allowed
		Note: This reinforces the special status of these attributes, 
		so that they not only need not be declared to be allowed in instances, 
		but must not be declared. It also removes any temptation to experiment 
		with supplying global or fixed values for e.g. xsi:type or xsi:nil, 
		which would be seriously misleading, as they would have no effect.
		</diagnostic>
	</diagnostics>	
</schema>