<?xml version="1.0" encoding="utf-8"?><!--
/*
 * Copyright © 2007 World Wide Web Consortium,
 *
 * (Massachusetts Institute of Technology, European Research Consortium for
 * Informatics and Mathematics, Keio University). All Rights Reserved. This
 * work is distributed under the W3C® Document License [1] in the hope that
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231
 */
    -->
<!DOCTYPE spec
  SYSTEM "../xmlspec.dtd">
<spec xmlns:xlink="http://www.w3.org/1999/xlink" w3c-doctype="wd">
    <header>
        <title>Service Modeling Language, Version 1.1</title>

        <w3c-designation>http://www.w3.org/TR/2007/WD-sml-20070806/</w3c-designation>
        <w3c-doctype>W3C Working Draft</w3c-doctype>

        <pubdate>
            <day>6</day>
            <month>August</month>
            <year>2007</year>
        </pubdate>
        <publoc>
            <loc href="http://www.w3.org/TR/2007/WD-sml-20070806/">http://www.w3.org/TR/2007/WD-sml-20070806/</loc>
        </publoc>
	<altlocs>
	  <loc role="xml" href="sml.xml" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML</loc>
	</altlocs>

        <latestloc>
            <loc href="http://www.w3.org/TR/sml/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/sml/</loc>
        </latestloc>
	<authlist>
	  <author role="editor">
	    <name>James Lynn</name>
	    <affiliation>HP</affiliation>
	  </author>
	  <author role="editor">
	    <name>Bhalchandra Pandit</name>
	    <affiliation>Microsoft Corporation</affiliation>
	  </author>
	  <author role="editor">
	    <name>Valentina Popescu</name>
	    <affiliation>IBM Corporation</affiliation>
	  </author>
	  <author role="editor">
	    <name>Virginia Smith</name>
	    <affiliation>HP</affiliation>
	  </author>
	  <author role="editor">
	    <name>Bassam Tabbara </name>
	    <affiliation>Microsoft Corporation</affiliation>
	  </author>
	  <author role="editor">
	    <name>Marvin Waschke</name>
	    <affiliation>CA</affiliation>
	  </author>
	</authlist>
	<abstract>
	  <p>This specification defines the Service Modeling Language, Version 1.1 (SML) used to
	  model complex services and systems, including their
	  structure, constraints, policies, and best practices. SML is
	  based on a profile of XML Schema and Schematron. </p>
	</abstract>
	<status id="status">
	  
	  <p>

                <emph>This section describes the status of this document at the
	  time of its publication. Other documents may supersede this
	  document. A list of current W3C publications and the latest revision
	  of this technical report can be found in the <loc href="http://www.w3.org/TR/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">W3C technical reports index</loc> at
	  http://www.w3.org/TR/.</emph>

</p>

      <p>This is the first Public Working Draft of the Service Modeling Language, Version 1.1 
      specification for review by W3C members and other
      interested parties. It has been developed by the
      <loc href="http://www.w3.org/XML/SML/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Service Modeling Language (SML) Working Group</loc>, which is a part of the
      <loc href="http://www.w3.org/XML/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Extensible Markup Language (XML) Activity</loc>.</p>

      <p>The features and algorithms described in the normative
      portion of the document are specified in enough detail adequate
      for early implementation experiments.</p>

      <p>Publication as a Working Draft does not imply endorsement by
      the W3C Membership. This is a draft document and may be updated,
      replaced or obsoleted by other documents at any time. It is
      inappropriate to cite this document as other than work in
      progress.</p>

      <p>Comments on this document are invited and are to be sent to
      the public-sml@w3.org mailing list (<loc href="http://lists.w3.org/Archives/Public/public-sml/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public archive</loc>).</p>

      <p>This document was produced by a group operating under the
      <loc href="http://www.w3.org/2004/01/pp-impl/41079/status" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">5 February 2004 W3C Patent Policy</loc>.
      W3C maintains a public list of
      any patent disclosures made in connection with the deliverables
      of the group; that page also includes instructions for
      disclosing a patent. An individual who has actual knowledge of a
      patent which the individual believes contains Essential Claim(s)
      must disclose the information in accordance with section 6 of
      the W3C Patent Policy.</p>
	</status>

	<langusage>
        <language id="en-US">English</language>
    </langusage>
    <revisiondesc>
        <p>Last Modified: $Date: 2007/08/07 22:09:18 $</p>
    </revisiondesc>
    </header>
    <body>
      <div1 id="Introduction">
	<head>Introduction (Non-Normative)</head>

<p>The Service Modeling Language (SML) provides a rich set of
constructs for creating models of complex services and systems. Depending on the application domain, these
models may include information such as configuration, deployment,
monitoring, policy, health, capacity planning, target operating range,
service level agreements, and so on. Models provide value in several
important ways.</p>
<olist>
  <item>
<p>Models focus on capturing all
    <b>invariant aspects</b> of a service/system that must be
    maintained for the service/system to function properly.</p>
  </item>
  <item>
                    <p>Models represent a powerful mechanism for
    <b>validating changes</b> <b>before</b> applying the changes
    to a service/system. Also, when changes happen in a running
    service/system, they can be validated against the intended state
    described in the model. The actual service/system and its model together
    enable a <b>self-healing service/system</b> ― the ultimate objective.
    <b>Models of a service/system must necessarily stay decoupled from the
    live service/system to create the control loop</b>
</p>
  </item>
  <item>
<p>Models are units of
    <b>communication</b> <b>and collaboration</b> between
    designers, implementers, operators, and users; and can easily be shared,
    tracked, and revision controlled. This is important because complex
    services are often built and maintained by a variety of people playing
    different roles.</p>
  </item>
  <item>
<p>Models drive <b>modularity</b>,
    <b>re-use, and standardization</b>. Most real-world complex
    services and systems are composed of sufficiently complex parts.  Re-use
    and standardization of services/systems and their parts is a key factor
    in reducing overall production and operation cost and in increasing
    reliability.</p>
  </item>
  <item>
<p>Models enable
    increased <b>automation</b> of
    management tasks. Automation facilities exposed by the majority of
    services/systems today could be driven by software ― not people ―
    both for reliable initial realization of a service/system as well as for
    ongoing lifecycle management.</p>
  </item>
</olist>


<p>A model in SML is realized as a set of interrelated XML documents. The XML
documents contain information about the parts of a service, as well as
the constraints that each part must satisfy for the service to function
properly. Constraints are captured in two ways:</p>
<olist>
  <item>
                    <p>

                        <b>Schemas</b> ― these are
    constraints on the structure and content of the documents in a model. SML
    uses a profile of XML Schema 1.0 [<bibref ref="XSD1"/>, <bibref ref="XSD2"/>] as the schema language. In addition SML
    defines a set of extensions to XML Schema to support inter-document
    references.</p>
  </item>
  <item>
                    <p>

                        <b>Rules</b> ― are Boolean expressions that constrain
  the structure and content of documents in a model. SML uses a
  profile of Schematron [<bibref ref="Schematron"/>, <bibref ref="intro_schematron"/>, <bibref ref="improving_schematron"/>] and
  XPath 1.0 [<bibref ref="XPath"/>] for rules.</p>
  </item>
</olist>

<p>One of the important operations on the model is
to establish its validity. This involves checking whether all data in a model
satisfies the schemas and rules declared. </p>

<p>This specification focuses primarily on defining the profile of XML Schema
and Schematron used by SML, as well as the process of model validation. It is
assumed that the reader is familiar with XML Schema and Schematron. </p>

      </div1>
<div1 id="Notations_and_Terminology">
<head>Notations and Terminology</head>
<div2 id="Notational_Conventions">
  <head>Notational Conventions</head>

	    <p>
	      The keywords "<rfc2119>MUST</rfc2119>", "<rfc2119>MUST
	      NOT</rfc2119>", "<rfc2119>REQUIRED</rfc2119>",
	      "<rfc2119>SHALL</rfc2119>", "<rfc2119>SHALL
	      NOT</rfc2119>", "<rfc2119>SHOULD</rfc2119>",
	      "<rfc2119>SHOULD NOT</rfc2119>",
	      "<rfc2119>RECOMMENDED</rfc2119>",
	      "<rfc2119>MAY</rfc2119>", and
	      "<rfc2119>OPTIONAL</rfc2119>" in this document are to be
	      interpreted as described in RFC 2119 [<bibref ref="RFC2119"/>].
	    </p>
</div2>
<div2 id="Terminology">
<head>Terminology</head>
  <glist>
    
    <gitem>
      <label id="document">Document</label>
      <def>
	<p>A well-formed XML 1.0 <term>document</term>, as defined in [<bibref ref="XML10"/>].</p>
      </def>
    </gitem>
  <gitem>
    <label id="model">Model</label>
    <def>
      <p>A set of inter-related documents that describe a service
      or system.  Each <term>model</term> consists of two disjoint subsets of
      documents –definition documents and instance documents.</p>
    </def>
  </gitem>
  <gitem>
    <label id="rule">Rule</label>
    <def>
      <p>A <term>rule</term> is a boolean expression that constrains the structure and content of a
      set of documents in a model. </p>
    </def>
  </gitem>
  <gitem>
    <label id="model_definition">Model Definition</label>
    <def>
      <p>The subset of documents in a model that describes the schemas
      and rules that govern the structure and content of the model's
      documents.  This specification defines two types of <term>model
      definition</term> document - Schema documents that conform
      to SML's profile of XML Schema and rule documents that conform
      to SML's profile of Schematron – but permits implementations to
      define other types of model definition documents. Such other
      types of model definition documents do not play any role in SML
      model validation.</p>
    </def>
  </gitem>
  <gitem>
    <label id="model_instance">Model Instance</label>
    <def>
      <p>A <term>model instance</term> is the subset of documents in a
      model that describe the structure and content of the modeled
      entities.</p>
    </def>
  </gitem>
  <gitem>
    <label id="model_validation_t">Model Validation</label>
    <def>
      <p>The <term>model validation</term> is the process of verifying
      that all documents in a model are valid with respect to the
      model's definition documents.</p>
    </def>
  </gitem>
  <gitem>
    <label id="model_validator">Model Validator</label>
    <def>
      <p>A <term>model validator</term> is an embodiment capable of
      performing model validation</p>
    </def>
  </gitem>
  </glist>

</div2>
<div2 id="XML_Namespaces">
<head>XML Namespaces</head>

<p>
<specref ref="Table1"/> lists XML namespaces that are used in this
specification. The choice of any namespace prefix is arbitrary and not
semantically significant.</p>

<table border="1" cellspacing="0" id="Table1">
  <caption>XML Namespaces used in this specification.</caption>
  <thead>
    <tr>
      <th rowspan="1" colspan="1">Prefix</th>
      <th rowspan="1" colspan="1">XML Namespace</th>
      <th rowspan="1" colspan="1">Specification(s)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://www.w3.org/2007/08/sml</code>
</td>
      <td rowspan="1" colspan="1">This specification</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>smlerr</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://www.w3.org/2007/08/sml-err</code>
</td>
      <td rowspan="1" colspan="1">This specification</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>smlfn</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://www.w3.org/2007/08/sml-function</code>
</td>
      <td rowspan="1" colspan="1">This specification</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>wsa</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://www.w3.org/2005/08/addressing</code>
</td>
      <td rowspan="1" colspan="1">[<bibref ref="WSADDR-CORE"/>]</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>xs</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://www.w3.org/2001/XMLSchema</code>
</td>
      <td rowspan="1" colspan="1">[<bibref ref="XSD1"/>, <bibref ref="XSD2"/>]</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sch</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://purl.oclc.org/dsdl/schematron</code>
</td>
      <td rowspan="1" colspan="1">[<bibref ref="Schematron"/>]</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>xsi</code>
</td>
      <td rowspan="1" colspan="1">
                                <code>http://www.w3.org/2001/XMLSchema-instance</code>
</td>
      <td rowspan="1" colspan="1">XML Schema instance, as defined in [<bibref ref="XSD1"/>]</td>
    </tr>
  </tbody>
</table>
</div2>
</div1>
<div1 id="Schemas">
<head>Schemas</head>

<p>SML uses a profile of W3C XML Schema 1.0 [<bibref ref="XSD1"/>, <bibref ref="XSD2"/>] to define constraints on the
structure of data in a <termref def="model">model</termref>.</p>

<p>SML scenarios require several features that either do not exist or are not
fully supported in XML Schema. These features can be classified as
follows:</p>
<ulist>
  <item>
                    <p>
<b>References</b> – XML Schema does not have any support
    for <b>inter-document</b> references, although it does support
    <b>intra-document</b> references through <code>xs:ID</code>,
    <code>xs:IDREF</code>, <code>xs:key</code> and <code>xs:keyref</code>.
    Inter-document references are fundamental to SML since a document is a
    unit of versioning. SML extends XML Schema to support inter-document
    references and a set of constraints on inter-document references.</p>
  </item>
  <item>
                    <p>

<b>Rules</b> – XML Schema does not support a language
    for defining arbitrary rules on the structure and content of XML
    documents. SML uses Schematron to express assertions on the structure and
    content of XML documents.</p>
  </item>
</ulist>

<p>XML Schema supports two forms of extension: "attributes in different
namespace" and "application information elements"; both forms are used
by SML extensions.</p>

<div2 id="References">
<head>References</head>

<p>XML documents introduce boundaries across content that needs to be
treated as a unit. XML Schema does not have any support for
inter-document references. SML extends XML Schema to support
inter-document references and a set of constraints on inter-document
references.</p>

<p>Support for inter-document references includes:</p>
<ulist>
  <item>
<p>A new data type that
    represents references to elements in other documents.</p>
  </item>
  <item>
<p>Multiple addressing
    schemes for representing references. </p>
  </item>
  <item>
<p>Constraints on the type
    of a referenced element. </p>
  </item>
  <item>

<p>The ability to define
    key, unique, and key reference constraints across inter-document
    references. </p>
  </item>
</ulist>

<p>An SML reference is a link from one element to another. It can be
represented by using a variety of schemes, such as Uniform Resource
Identifiers (URIs) [<bibref ref="RFC3986"/>] and Endpoint References
(EPRs) [<bibref ref="WSADDR-CORE"/>]. SML does not mandate the use of
any specific scheme for representing references; implementations are
free to choose suitable schemes for representing
references.  References <rfc2119>MUST</rfc2119> be supported by
<termref def="model_validator">model validators</termref> that conform
to this specification.</p>

<p>Reference elements <rfc2119>MUST</rfc2119> be identified by
<code>sml:ref="true"</code> or <code>sml:ref="1"</code> where
 <code>sml:ref</code> is a global attribute whose declaration is as follows:</p>

<eg xml:space="preserve">&lt;xs:attribute name="ref" type="xs:boolean" /&gt;</eg>

<p>An element that has <code>sml:ref="true"</code>
<rfc2119>MUST</rfc2119> be treated as a reference element, i.e., its
child elements <rfc2119>MAY</rfc2119> contain 
one or more reference schemes. This mechanism enables schema-less
identification of reference elements, i.e., reference elements can be
identified without relying on PSVI.</p>

<p>The following example illustrates the use
of <code>sml:ref</code>. Consider the
following schema fragment:</p>

<eg xml:space="preserve">&lt;xs:element name="EnrolledCourse"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="Name" type="xs:string"/&gt;
        &lt;xs:element name="Grade" type="xs:string"/&gt;
        &lt;xs:any namespace="##any" minOccurs="0"
                maxOccurs="unbounded" processContents="lax"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:anyAttribute namespace="##any" processContents="lax"/&gt;
    &lt;/xs:complexType&gt;
&lt;/xs:element&gt;

&lt;xs:complexType name="StudentType"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="ID" type="xs:string"/&gt;
      &lt;xs:element name="Name" type="xs:string"/&gt;
      &lt;xs:element name="EnrolledCourses" minOccurs="0"&gt;
        &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element ref="tns:EnrolledCourse"
                        maxOccurs="unbounded"/&gt;
          &lt;/xs:sequence&gt;
        &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
    &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;</eg>

<p>The schema definition in the above example is
SML agnostic and does not make use of any SML attributes, elements, or types.
The <code>EnrolledCourse</code> element,
however, has an open content model and this can be used to mark instances
of <code>EnrolledCourse</code> as
reference elements as shown below:</p>

<eg xml:space="preserve">&lt;Student xmlns="http://www.university.example.org/ns"
         xmlns:sml="http://www.w3.org/2007/08/sml"
         xmlns:wsa="http://www.w3.org/2005/08/addressing"&gt;
  &lt;ID&gt;1000&lt;/ID&gt;
  &lt;Name&gt;John Doe&lt;/Name&gt;
  &lt;EnrolledCourses&gt;
    &lt;EnrolledCourse sml:ref="true"&gt;
      &lt;Name&gt;PHY101&lt;/Name&gt;
      &lt;Grade&gt;A&lt;/Grade&gt;
      &lt;sml:uri&gt;
        http://www.university.example.org/Universities/MIT/Courses.xml#xmlns(u=http://www.university.example.org/ns)
        xpointer(/u:Courses/u:Course[u:Name='PHY101'])
      &lt;/sml:uri&gt;
      &lt;wsa:EndpointReference&gt;
        &lt;wsa:Address&gt;http://www.university.example.org&lt;/wsa:Address&gt;
        &lt;/wsa:EndpointReference&gt;
    &lt;/EnrolledCourse&gt;
    &lt;EnrolledCourse sml:ref="false"&gt;
      &lt;Name&gt;MAT100&lt;/Name&gt;
      &lt;Grade&gt;B&lt;/Grade&gt;
      &lt;sml:uri&gt;
        http://www.university.example.org/Universities/MIT/Courses.xml#xmlns(u=http://www.university.example.org/ns)
        xpointer(/u:Courses/u:Course[u:Name='MAT100'])
      &lt;/sml:uri&gt;
    &lt;/EnrolledCourse&gt;
    &lt;EnrolledCourse&gt;
      &lt;Name&gt;SocialSkills&lt;/Name&gt;
      &lt;Grade&gt;F&lt;/Grade&gt;
    &lt;/EnrolledCourse&gt;
  &lt;/EnrolledCourses&gt;
&lt;/Student&gt;</eg>

<p>The first <code>EnrolledCourse</code> element in the above example
is a reference element since it specifies
<code>sml:ref="true"</code>. Assuming that references are
represented using URI and EPR schemes, it has two representations of the
reference to the element for course  PHY101. The second and third
<code>EnrolledCourse</code> elements are not reference elements; the
second element specifies <code>sml:ref="false"</code> and
the third element does not specify the <code>sml:ref</code>
attribute. Note that the second element has a child element that
contains a reference scheme referring to course MAT100, but this reference will be
ignored since <code>sml:ref="false"</code> for the second
element.</p>

<p>A reference element <rfc2119>MAY</rfc2119> be empty or have a null
value provided that this is allowed by the element's schema. For
example, consider the following variation of the
<code>EnrolledCourse</code> element declaration:</p>

<eg xml:space="preserve">&lt;xs:element name="EnrolledCourse" nillable="true"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="Name" type="xs:string"/&gt;
        &lt;xs:element name="Grade" type="xs:string"/&gt;
        &lt;xs:any namespace="##any" minOccurs="0"
                maxOccurs="unbounded" processContents="lax"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:anyAttribute namespace="##any" processContents="lax"/&gt;
    &lt;/xs:complexType&gt;
&lt;/xs:element&gt;</eg>

<p>The above declaration allows null values for
instances of <code>EnrolledCourse</code>. Thus, an <code>EnrolledCourse</code> 
reference element can have null value as shown in the following
example (the first <code>EnrolledCourse</code> 
element has null value):</p>

<eg xml:space="preserve">&lt;Student xmlns="http://www.university.example.org/ns"
         xmlns:sml="http://www.w3.org/2007/08/sml"
         xmlns:wsa="http://www.w3.org/2005/08/addressing"&gt;
  &lt;ID&gt;1000&lt;/ID&gt;
  &lt;Name&gt;John Doe&lt;/Name&gt;
  &lt;EnrolledCourses&gt;
    &lt;EnrolledCourse sml:ref="true" xsi:nil="true"/&gt;
    &lt;EnrolledCourse sml:ref="false"&gt;
      &lt;Name&gt;MAT100&lt;/Name&gt;
      &lt;Grade&gt;B&lt;/Grade&gt;
      &lt;sml:uri&gt;
        http://www.university.example.org/Universities/MIT/Courses.xml#xmlns(u=http://www.university.example.org/ns)
        xpointer(/u:Courses/u:Course[u:Name='MAT100'])
      &lt;/sml:uri&gt;
    &lt;/EnrolledCourse&gt;
    &lt;EnrolledCourse&gt;
      &lt;Name&gt;SocialSkills&lt;/Name&gt;
      &lt;Grade&gt;F&lt;/Grade&gt;
    &lt;/EnrolledCourse&gt;
  &lt;/EnrolledCourses&gt;
&lt;/Student&gt;</eg>

<p>SML also supports several schema-based constraints on
reference elements. The <code>sml:refType</code> type has been defined to
allow model authors to make use of these schema-based constraints in
their model's schema. The definition of <code>sml:refType</code> fixes
the value of <code>sml:ref</code> to <code>true</code>, and hence all
elements of type <code>sml:refType</code> are reference elements.  
The <code>sml:refType</code> is defined as follows<code>:</code>
</p>

<eg xml:space="preserve">&lt;xs:complexType name="refType" sml:acyclic="false"&gt;
   &lt;xs:sequence&gt;
     &lt;xs:any namespace="##any" minOccurs="0"
             maxOccurs="unbounded"
             processContents="lax"/&gt;
   &lt;/xs:sequence&gt;
   &lt;xs:attribute ref="sml:ref" use="required"
                 fixed="true" /&gt;
   &lt;xs:anyAttribute namespace="##any"
                 processContents="lax"/&gt;
&lt;/xs:complexType&gt;</eg>

<p>Note that
the above definition allows elements and attributes from any namespace to
occur in an element whose type is <code>sml:refType</code>. Thus, a scheme for reference elements 
can be implemented by defining an 
XML namespace for the scheme, and references can be represented in this
scheme by nesting element and attribute instances from this namespace as
attributes and children of <code>sml:refType</code> elements.</p>

<p>The
following example illustrates the use of <code>sml:refType</code>:</p>
<eg xml:space="preserve">
&lt;xs:element name="EnrolledCourse" type="sml:refType" sml:targetType="tns:CourseType"/&gt;
&lt;xs:complexType name="StudentType"&gt;
        &lt;xs:sequence&gt;
            &lt;xs:element name="ID" type="xs:string"/&gt;
            &lt;xs:element name="Name" type="xs:string"/&gt;
            &lt;xs:element name="EnrolledCourses" minOccurs="0"&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element ref="tns:EnrolledCourse"
                                    maxOccurs="unbounded"/&gt;
                    &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;</eg>

<p>The <code>EnrolledCourse</code>
element declaration is of
type <code>sml:refType</code> which marks it as a
document reference, and this element declaration is used in
<code>StudentType</code> to reference the elements
corresponding to the courses in which a student is enrolled.</p>

<p>Examples of the use of <code>sml:refType</code> for
<code>EnrolledCourse</code> are found in the section <specref ref="Reference_Schemes"/>.  This section demonstrates the use of the
URI and EPR schemes to define the reference.</p>

<div3 id="Reference_Definitions">
<head>Reference Definitions</head>

<div4 id="SML_Reference">
<head>SML Reference</head>
<p>An element that has either <code>sml:ref="true"</code> or <code>sml:ref="1"</code> specified.</p>
<p>Although either <code>sml:ref="true"</code> or 
<code>sml:ref="1"</code> can be used to identify an SML reference element,
 for the sake of brevity and consistency, the rest of this specification uses 
<code>sml:ref="true"</code> in examples and other definitions.</p>
</div4>

<div4 id="Null_Reference">
<head>Null Reference</head>
<p>A reference element with <code>xsi:nil="true"</code> or no content, provided
that it is allowed by the element's declaration.</p>
</div4>

<div4 id="Dangling_Reference">
<head>Dangling Reference</head>
<p>A non-null reference whose target does not exist.</p>
</div4>

</div3>

<div3 id="Reference_Semantics">
<head>Reference Semantics</head>

<div4 id="At_Most_One_Target">
<head>At Most One Target</head>

<p>Every reference element <rfc2119>MUST</rfc2119> target (or resolve to) 
at most one element in a <termref def="model">model</termref>.
Dangling references are allowed in SML; therefore it is possible that the
target of a reference does not exist in a model. It is an error if a
reference element targets more than one element in a model.</p>

<p>If a single reference element has multiple representations,
every representation <rfc2119>MUST</rfc2119> target the same element.  Validators <rfc2119>MAY</rfc2119> check
this condition.</p>

</div4>
<div4 id="Multiple_References">
<head>Multiple References  </head>

<p>An element in a document <rfc2119>MAY</rfc2119> be targeted by multiple reference elements. 
These reference elements may use different schemes and/or be expressed in different ways.
 </p>

</div4>
<div4 id="Empty_or_Null_References">
<head>Empty or Null References</head>

<p>A <termref def="model_validator">model validator</termref>
<rfc2119>MUST</rfc2119> not perform the SML validation associated with references for a null reference element.</p>

</div4>
<div4 id="deref_28_29_XPath_Extension_Function">
<head>deref() XPath Extension Function</head>

<p>Each <termref def="model_validator">model validator</termref> <rfc2119>MUST</rfc2119> provide an
implementation of the <code>deref()</code> XPath extension function
that is capable of resolving references expressed in the model
validator's chosen scheme(s). This function takes a node-set of
elements and returns a node-set consisting of element nodes
corresponding to the elements referenced by the input node set.  In
particular, for each node <b>R</b> in the input node set the output
node set contains at most one element node.</p>
<ulist>
  <item>
<p>The output node set
    contains one element node for <b>R</b> provided that all of the following conditions are
    true</p>
    <ulist>
      <item>
                                    <p>
                                    <code>sml:ref 
         ="true"</code>
        for <b>R</b>
</p>
      </item>
      <item>
                                    <p>
<b>R</b> contains at least one reference scheme that is understood
        by the implementation</p>
      </item>
      <item>
<p>The reference targets a single element
        in some document in the model</p>
      </item>
    </ulist>
  </item>
  <item>
<p>The output node set
    contains no element node corresponding to <b>R</b> if any of the following conditions is true</p>
    <ulist>
      <item>
<p>the target of
        <b>R</b> is not in the model</p>
      </item>
      <item>
                                    <p>
<b>R</b> is
        an empty or null reference</p>
      </item>
      <item>
                                    <p>
<b>R</b> does not contain any reference scheme that is understood
        by the implementation</p>
      </item>
      <item>
                                    <p>
                                    <code>sml:ref</code> is not specified for <b>R</b>
</p>
      </item>
      <item>
                                    <p>

<code>sml:ref</code> is specified for <b>R</b> and its value is neither <code>"true"</code> nor <code>"1"</code>.
            </p>
      </item>
    </ulist>
  </item>
</ulist>
</div4>
</div3>
</div2>
<div2 id="Reference_Schemes">
<head>Reference Schemes</head>

<p>A reference <rfc2119>MAY</rfc2119> be represented by using a variety of schemes, and SML does
not mandate the use of any specific schemes. Uniform Resource Identifiers
(URIs) [<bibref ref="RFC3986"/>] and endpoint references (EPRs) [<bibref ref="WSADDR-CORE"/>] are two common schemes for
referencing resources. Although SML does not require the use of either
scheme, it does define how a reference <rfc2119>MUST</rfc2119> be represented using the URI
scheme and the EPR scheme.</p>

<div3 id="URI_Scheme">
<head>URI Scheme</head>

<p>References that are represented using the URI scheme
<rfc2119>MUST</rfc2119> be implemented by using the
<code>sml:uri</code> global element as a child of reference elements,
i.e., elements for which <code>sml:ref="true"</code>.  More precisely,
if a <termref def="model_validator">model validator</termref> chooses to represent references using the URI
scheme,</p>
<ulist>
  <item>
<p>It <rfc2119>MUST</rfc2119> represent each reference using
  an instance of the <code>sml:uri</code> global element declaration
  as a child of the reference element.  </p>
  </item>
  <item>

<p>It <rfc2119>MUST</rfc2119> treat each instance of  the
  <code>sml:uri</code> global element declaration, whose parent
  element is a reference element, as a reference represented in the
  URI scheme.</p>
  </item>
</ulist>

<p>For example, if the reference element in <specref ref="References"/> 
is represented using the URI scheme, an instance of
<code>EnrolledCourse</code> will appear as follows:</p>
<eg xml:space="preserve">&lt;EnrolledCourse xmlns="http://www.university.example.org/ns"  sml:ref="true"&gt;
  &lt;sml:uri&gt;http://www.university.example.org/someUri&lt;/sml:uri&gt;
&lt;/EnrolledCourse&gt;</eg>

<p>where <code>http://www.university.example.org/someUri</code> is a
valid URI as defined in [<bibref ref="RFC3986"/>].</p>

<p>Suppose that a <termref def="model">model</termref> has the
following documents, and each document has an associated URI:</p>

<table border="1" cellspacing="0" id="Table2">
  <thead>
    <tr>
      <th rowspan="1" colspan="1">Document</th>
      <th rowspan="1" colspan="1">URI</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td rowspan="1" colspan="1">Course PHY101</td>
      <td rowspan="1" colspan="1">http://www.university.example.org/Universities/MIT/Courses/PHY101.xml</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">Course MAT200</td>
      <td rowspan="1" colspan="1">http://www.university.example.org/Universities/MIT/Courses/MAT200.xml</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">Student 1000</td>
      <td rowspan="1" colspan="1">http://www.university.example.org/Universities/MIT/Students/1000.xml</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">Student 1001</td>
      <td rowspan="1" colspan="1">http://www.university.example.org/Universities/MIT/Students/1001.xml</td>
    </tr>
  </tbody>
</table>

<p>The following is a sample instance document for Student
1000 where the references are represented in the URI scheme:</p>
<eg xml:space="preserve">&lt;Student xmlns="http://www.university.example.org/ns"&gt;
  &lt;ID&gt;1000&lt;/ID&gt;
  &lt;Name&gt;John Doe&lt;/Name&gt;
  &lt;EnrolledCourses&gt;
    &lt;EnrolledCourse sml:ref="true"&gt;
      &lt;sml:uri&gt;http://www.university.example.org/Universities/MIT/Courses/PHY101.xml&lt;/sml:uri&gt;
    &lt;/EnrolledCourse&gt;
    &lt;EnrolledCourse sml:ref="true"&gt;
      &lt;sml:uri&gt;http://www.university.example.org/Universities/MIT/Courses/MAT200.xml&lt;/sml:uri&gt;
    &lt;/EnrolledCourse&gt;
  &lt;/EnrolledCourses&gt;
&lt;/Student&gt;</eg>

<div4 id="Fragment_Identifier">
<head>Fragment Identifier</head>

<p> Fragment identifiers in references that are represented using the
URI scheme <rfc2119>MUST</rfc2119> use the following XPointer [<bibref ref="XPTR"/>] profile: Only two schemes – xmlns() [<bibref ref="XPTR-xmlns"/>] and xpointer() [<bibref ref="XPTR-xpointer"/>] –
are supported.</p>
<ulist>
  <item>

<p>The expression specified
    for the xpointer scheme <rfc2119>MUST</rfc2119> be a restricted XPath 1.0 [<bibref ref="XPath"/>] expression
    that <rfc2119>MUST</rfc2119> resolve to at most one element node. In particular, this
    expression <rfc2119>MUST NOT</rfc2119> contain</p>
    <ulist>
      <item>
<p>the union ("|") operator defined for
        XPath 1.0</p>
      </item>
      <item>
                                    <p>
<code>point()</code> and <code>range()</code> node
        tests defined for the xpointer() scheme</p>
      </item>
    </ulist>
  </item>
  <item>

                                <p>This expression can only use the functions defined in the
  XPath 1.0 core function library [<bibref ref="XPath"/>]. It
  <rfc2119>MUST NOT</rfc2119> use the <code>smlfn:deref</code>
  function and/or the following functions defined for xpointer()
  scheme [<bibref ref="XPTR-xpointer"/>]:</p>
    <ulist>
      <item>
                                    <p>
                                    <code>range-to</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>string-range</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>range</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>range-inside</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>start-point</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>end-point</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>here</code>
                                    </p>
</item>
      <item>
                                    <p>
                                    <code>origin</code>
                                    </p>

</item>
    </ulist>
  </item>
</ulist>

<p>The following example illustrates the use of xpointer
fragments. Consider the case where all courses offered by MIT are stored in a
single XML document – <code>Courses.xml</code> –
whose URI is  <code>http://www.university.example.org/Universities/MIT/Courses.xml</code>. In this case, the element inside
<code>Courses.xml</code> that corresponds to the course
PHY101 can be referenced as follows (assuming that <code>Courses</code>is the root element in
<code>Courses.xml</code>)</p>
<eg xml:space="preserve">&lt;Student xmlns="http://www.university.example.org/ns"&gt;
  &lt;ID&gt;1000&lt;/ID&gt;
  &lt;Name&gt;John Doe&lt;/Name&gt;
  &lt;EnrolledCourses&gt;
    &lt;EnrolledCourse sml:ref="true"&gt;
      &lt;sml:uri&gt;
        http://www.university.example.org/Universities/MIT/Courses.xml#xmlns(u=http://www.university.example.org/ns)
        xpointer(/u:Courses/u:Course[u:Name='PHY101'])
      &lt;/sml:uri&gt;
    &lt;/EnrolledCourse&gt;
  &lt;/EnrolledCourses&gt;
&lt;/Student&gt;</eg>

<p>A reference element can also be used to
reference an element in its own document. To see this consider the following
instance document</p>

<eg xml:space="preserve">&lt;University xmlns="http://www.university.example.org/ns"&gt;
  &lt;Name&gt;MIT&lt;/Name&gt;
  &lt;Courses&gt;
    &lt;Course&gt;
      &lt;Name&gt;PHY101&lt;/Name&gt;
    &lt;/Course&gt;
    &lt;Course&gt;
      &lt;Name&gt;MAT200&lt;/Name&gt;
    &lt;/Course&gt;
  &lt;/Courses&gt;
  &lt;Students&gt;
    &lt;Student&gt;
      &lt;ID&gt;123&lt;/ID&gt;
      &lt;Name&gt;Jane Doe&lt;/Name&gt;
      &lt;EnrolledCourses&gt;
        &lt;EnrolledCourse sml:ref="true"&gt;
          &lt;sml:uri&gt;
            #xmlns(u=http://www.university.example.org/ns)
            xpointer(/u:University/u:Courses/u:Course[u:Name='MAT200']
          &lt;/sml:uri&gt;
        &lt;/EnrolledCourse&gt;
      &lt;/EnrolledCourses&gt;
    &lt;/Student&gt;
  &lt;/Students&gt;
&lt;/University&gt;</eg>

<p>Here, the <code>EnrolledCourse</code> element for the student
Jane Doe references the <code>Course</code> element for MAT200 in
the same document.</p>
</div4>
</div3>
<div3 id="EPR_Scheme">
<head>EPR Scheme</head>

<p>References that are represented using the EPR scheme <rfc2119>MUST</rfc2119> be implemented
by using instances of  <code>wsa:EndpointReference</code> global element declaration [<bibref ref="WSADDR-CORE"/>] as
 child  elements of reference elements. The following example illustrates
how the <code>EnrolledCourse</code> reference that references course PHY101 in MIT university can be
represented using the EPR scheme:</p>
<p>[Example Under Construction]</p>

<eg xml:space="preserve">&lt;EnrolledCourse xmlns="http://www.university.example.org/ns" sml:ref="true"&gt;
  &lt;wsa:EndpointReference
       xmlns:u="http://www.university.example.org/schema"&gt;
    &lt;wsa:Address&gt;http://www.university.example.org&lt;/wsa:Address&gt;
  &lt;/wsa:EndpointReference&gt;
&lt;/EnrolledCourse&gt;</eg>
</div3>
</div2>
<div2 id="Constraints_on_References">
<head>Constraints on References</head>

<p>SML supports the following attributes for expressing constraints on reference elements.
</p>

<table border="1" cellspacing="0" id="Table3">
  <caption>Attributes</caption>
  <thead>
    <tr>
      <th rowspan="1" colspan="1">Name</th>
      <th rowspan="1" colspan="1">Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:acyclic</code>
</td>
      <td rowspan="1" colspan="1">Used to specify whether cycles are supported for a reference.</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:targetElement</code>
</td>
      <td rowspan="1" colspan="1">Used to constrain the name of the reference's target element.</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:targetType</code>
</td>
      <td rowspan="1" colspan="1">Used to constrain the type of the reference's target element.</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:targetRequired</code>
</td>
      <td rowspan="1" colspan="1">Used to specify that a reference's target element is required
        to be present in the model.</td>
    </tr>
  </tbody>
</table>
<p>These attributes <rfc2119>MUST</rfc2119> be supported in the following specified locations only in an SML model:
<ulist>
<item>
                            <p>These attributes <rfc2119>MUST</rfc2119> be supported in XML Schema documents.</p>
</item>
<item>
                            <p>These attributes <rfc2119>MUST</rfc2119> be supported for element declarations of
type <code>sml:refType</code> or a derived type of <code>sml:refType</code>.
 Note that this specification specifies <code>sml:acyclic="false"</code> for 
type <code>sml:refType</code>. </p>
</item>
</ulist> 
</p>

<div3 id="sml_acyclic">
<head>sml:acyclic</head>

<p>
<termref def="model_validator">Model validators</termref> that conform to this specification <rfc2119>MUST</rfc2119> support the
<code>sml:acyclic</code> attribute on derived types of
<code>sml:refType</code>. This is a boolean attribute and its value can be
either <code>true</code> or <code>false</code>. Let <b>R</b> be a
derived type of <code>sml:refType</code>. If
<code>sml:acyclic="true"</code> is specified for <b>R</b>, then
<b>R</b> is an acyclic reference type, i.e., instances of
<b>R</b> <rfc2119>MUST NOT</rfc2119> create cycles in any model. More precisely,
the directed graph whose nodes are documents that contain the source or
target elements for instances of <b>R</b>, and whose
edges are instances of <b>R</b> (an edge is directed
from the document containing the source element to the document containing
the target element),  must be acyclic.</p>

<p>A cyclic reference type can be used to derive cyclic or acyclic reference
types, but all derived types of an acylic reference type are acyclic. Model
validators that conform to this specification <rfc2119>MUST</rfc2119> enforce the following:</p>
<ulist>
  <item>
                            <p>If <b>CR</b> is a cyclic reference
    type and <b>D<sub>CR</sub>
                                </b> is a derived type of
    <b>CR</b>, then <b>D<sub>CR</sub>
                                </b> is an acyclic
    reference if <code>sml:acyclic="true"</code> is specified for
    <b>D<sub>CR</sub>
                                </b>. Otherwise,
    <b>D<sub>CR</sub>
</b> is a cyclic reference</p>
  </item>
  <item>
                            <p>If <b>AR</b> is an acyclic
    reference type and <b>D<sub>AR</sub>
                                </b> is a derived type of
    <b>AR</b>, then <code>sml:acyclic="true"</code> holds for
    <b>D<sub>AR</sub>
                                </b> even if the <code>sml:acyclic</code>
    attribute is not explicitly specified for
    <b>D<sub>AR</sub>
                                </b>. It is an error for
    <b>D<sub>AR</sub>
                                </b> to specify
    <code>sml:acyclic="false"</code>
</p>
  </item>
</ulist>

</div3>
<div3 id="Constraints_on_Targets">
<head>Constraints on Targets</head>

<p>SML supports three attributes: <code>sml:targetElement</code>,
<code>sml:targetRequired</code>, and <code>sml:targetType,</code> for
constraining the target of a reference. These three attributes are
collectively called <code>sml:target*</code> attributes and they <rfc2119>MUST</rfc2119> be
supported on global and local element declarations. <termref def="model_validator">Model validators</termref> that
conform to this specification <rfc2119>MUST</rfc2119> enforce the following:</p>

<p>If one/more of <code>sml:target*</code> attributes are specified (either
explicitly or by default) for a <xspecref href="http://www.w3.org/TR/xmlschema-1/#Particle" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">particle</xspecref>
<b>P</b> in a complex-type definition <b>CT</b>, then all
particles in <b>CT</b> that have the same <xspecref href="http://www.w3.org/TR/xmlschema-1/#e-name" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">name</xspecref> as
<b>P</b> must specify the same set of <code>sml:target*</code>
attributes as <b>P</b> and these attributes must have the same
values as those specified for <b>P</b>. </p>

<p>In particular, all of the following must be enforced:</p>
<ulist>
  <item>
                            <p>If
    <code>sml:targetElement="ns:GTE"</code> for <b>P</b> then
    <code>sml:targetElement="ns:GTE"</code> for all particles in
    <b>CT</b> that have the same name as <b>P</b>
</p>
  </item>
  <item>
                            <p>If
    <code>sml:targetRequired="true"</code> for <b>P</b> then
    <code>sml:targetRequired="true"</code> for all particles in
    <b>CT</b> that have the same name as <b>P</b>
</p>
  </item>
  <item>
                            <p>If
    <code>sml:targetRequired="false"</code> for <b>P</b> then
    <code>sml:targetRequired="false"</code> for all particles in
    <b>CT</b> that have the same name as <b>P</b>
</p>
  </item>
  <item>
                            <p>If
    <code>sml:targetType="ns:T"</code> for <b>P  </b>then
    <code>sml:targetType="ns:T"</code> for all particles in
    <b>CT</b> that have the same name as <b>P</b>

</p>
  </item>
</ulist>

<p>The above conditions on the use of <code>sml:target*</code>
attributes have been defined to reduce the implementation burden  on
 <termref def="model_validator">model validators</termref> for
verifying  that the use of <code>sml:target*</code> attributes is
consistent across derivation by restriction. These conditions enable
model validators to find the restricted particle for a restricting
particle using a simple name match when <code>sml:target*</code>
attributes are specified for these particles.  In the absence of the
above conditions, it is extremely difficult for SML validators to
verify consistent use of <code>sml:target*</code> attributes across a
base type and its restricted derived type. In order to verify
consistent use of an <code>sml:target*</code> attribute on a
restricted particle in the base type and its restricting particle in a
restricted derived type, it is necessary to connect the particles in
the derived type with  those from the restricted base type. However,
this level of support is not provided by most XML Schema frameworks;
thus most SML validators would otherwise need to duplicate large parts
of XML Schema's compilation logic to verify consistent usage of
<code>sml:target*</code> attributes across derivation by
restriction.    
</p>

<div4 id="sml_targetElement">
<head>sml:targetElement</head>

<p>
<termref def="model_validator">Model validators</termref> that conform to this specification <rfc2119>MUST</rfc2119> support the
<code>sml:targetElement</code> attribute on element declarations whose type
is <code>sml:refType</code> or a derived type of <code>sml:refType</code>.
The value of this attribute <rfc2119>MUST</rfc2119> be the qualified name of some global element
declaration. Let <code>sml:targetElement="ns:GTE"</code> for some element
declaration <b>E</b>. Then each element instance of
<b>E</b> <rfc2119>MUST</rfc2119> reference an element that is an instance of
<b>ns:GTE</b> or an instance of some global element declaration in
the substitution group hierarchy whose head is <b>ns:GTE</b>. If a
target element constraint is specified for a global element declaration
<b>G</b> then it continues to apply to all global element
declarations in the substitution group hierarchy whose head is
<b>G</b>. However, a global element declaration in
<b>G</b>'s substitution group can specify a target element
constraint that refines the constraint defined for <b>G</b>. In
particular, model validators that conform to this specification <rfc2119>MUST</rfc2119> enforce
the following:</p>
<ulist>
  <item>
                                <p>If
    <code>sml:targetElement="ns:GTE"</code> is specified for
    <b>G,</b> and <b>S<sub>G</sub>
</b> is a global
    element declaration that specifies <b>G</b> as the value of its
    <code>xs:substitutionGroup</code> attribute, then</p>
    <ulist>
      <item>
                                    <p>if  <code>sml:targetElement</code> is
      specified for <b>S<sub>G</sub>
                                    </b> then its value <rfc2119>MUST</rfc2119>  be
      <b>ns:GTE</b> or the name of a global element declaration in
      the substitution group hierarchy whose head is <b>ns:GTE</b>
</p>
      </item>
      <item>
                                    <p>if <code>sml:targetElement</code> is not
      specified for <b>S<sub>G</sub>
                                    </b>, then
      <code>sml:targetElement="ns:GTE"</code> holds for
      <b>S<sub>G</sub>
</b> by default.</p>
      </item>
    </ulist>
  </item>
</ulist>

<p>If a target element constraint is specified for a particle
<b>P</b> in some type <b>B</b>, then it continues to apply
to each particle <b>P<sub>R</sub>
                            </b> that is a valid
restrictions of <b>P</b> where <b>P<sub>R</sub>
                            </b> is
defined in some restricted derived type of <b>B</b> (see
<quote>
                                <xspecref href="http://www.w3.org/TR/xmlschema-1/#cos-particle-restrict" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Schema
Component Constraint: Particle Valid (Restriction)</xspecref>

                            </quote>, section
3.9.6, <quote>Constraints on Particle Schema Components</quote>,
[<bibref ref="XSD2"/>] for XML Schema's definition of valid
restrictions<b>)</b>.  However, <b>P<sub>R</sub>
</b> can
specify a target element constraint that refines the constraint
defined for <b>P</b>.  In particular, model validators that
conform to this specification <rfc2119>MUST</rfc2119> enforce the
following:</p>
<ulist>
  <item>
                                <p>If
    <code>sml:targetElement="ns:GTE"</code> is specified for
    <b>P</b> and <code>sml:targetElement</code> is specified for
    <b>P<sub>R</sub>
                                    </b>, then the value of
    <code>sml:targetElement</code> for <b>P<sub>R</sub>
                                    </b> must be
    <b>ns:GTE</b> or the name of a global element declaration in
    the substitution group hierarchy whose head is <b>ns:GTE</b>.
    If <code>sml:targetElement</code> is not specified for
    <b>P<sub>R</sub>
                                    </b>, then
    <code>sml:targetElement="ns:GTE"</code> holds for
    <b>P<sub>R</sub>
</b> by default.</p>
  </item>
</ulist>

</div4>
<div4 id="sml_targetRequired">
<head>sml:targetRequired</head>

<p>
<termref def="model_validator">Model validators</termref> that conform to this specification <rfc2119>MUST</rfc2119> support the  
<code>sml:targetRequired</code> attribute   on element declarations whose
type is <code>sml:refType</code> or a derived type of
<code>sml:refType</code>. If  <code>sml:targetRequired
="true"</code> for an element declaration <b>E</b>, then
each element instance of <b>E</b> <rfc2119>MUST</rfc2119> target some element in the
model, i.e., no instance of <b>E</b> can be null, empty, or contain
a dangling reference. Otherwise, instances of <b>E</b> can be
empty, null, or contain dangling references. If this attribute is not
specified, then its value is assumed to be <code>"false"</code>. </p>

<p>Model validators that conform to this specification <rfc2119>MUST</rfc2119> enforce the
following:</p>
<ulist>
  <item>
                                <p>If the <code>sml:targetRequired</code>
     attribute is specified for a global element declaration
    <b>G</b> then the specified value applies by default to each
    global element declaration <b>S<sub>G</sub>
                                    </b> in the
    substitution group hierarchy whose head is <b>G</b> unless the
    <code>sml:targetRequired</code>  attribute is specified for
    <b>S<sub>G</sub>
                                    </b>
                                    <b>.</b>
</p>
  </item>
  <item>
<p>If
    <code>sml:targetRequired="true"</code> is specified for a global
    element declaration <b>G</b> then
    <code>sml:targetRequired="false"</code>  <rfc2119>MUST NOT</rfc2119> be specified for
    any element declaration in the substitution group hierarchy whose head is
    <b>G</b>.</p>
  </item>
  <item>
                                <p>If <code>sml:targetRequired</code> attribute
    is  specified for a particle  <b>P</b> in some type
    <b>B</b>, then the specified value applies by default to  to
    each particle <b>P<sub>R</sub>
                                    </b> that is a valid restriction
    of <b>P</b> unless the <code>sml:targetRequired</code>
    attribute is specified for <b>P<sub>R</sub>
                                    </b>
    (see <quote>
                                    <xspecref href="http://www.w3.org/TR/xmlschema-1/#cos-particle-restrict" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Schema
Component Constraint: Particle Valid (Restriction)</xspecref>

</quote>, section
3.9.6, <quote>Constraints on Particle Schema Components</quote>,
[<bibref ref="XSD2"/>]
    for XML Schema's definition of valid restrictions<b>)</b>.</p>
  </item>
  <item>
                                <p>If <code>sml:targetRequired="true"</code> for a particle <b>P</b> <code>then
    sml:targetRequired="false"</code>  <rfc2119>MUST NOT</rfc2119> be specified for any
    particle <b>P<sub>R</sub>
                                    </b> that is
    a valid restriction of <b>P.</b> <code> </code>
</p>
  </item>
</ulist>

</div4>
<div4 id="sml_targetType">
<head>sml:targetType</head>

<p>
<code>The sml:targetType</code> attribute <rfc2119>MUST</rfc2119>
be supported on element declarations whose type
is <code>sml:refType</code> or a derived type of <code>sml:refType</code>.
The value of this attribute <rfc2119>MUST</rfc2119> be the qualified name of some type
definition. Let <code>sml:targetType="ns:T"</code>  for some element
declaration <b>E</b>. Then each element instance of
<b>E</b> <rfc2119>MUST</rfc2119> reference an element whose type is
<b>ns:T</b> or a derived type of <b>ns:T</b>.</p>

<p>If a target type constraint is specified for a global element declaration
<b>G</b> then it continues to apply to all global element
declarations in the substitution group hierarchy whose head is
<b>G</b>. However, a global element declaration in
<b>G</b>'s substitution group can specify a target type
constraint that refines the constraint defined for <b>G</b>. In
particular, model validators that conform to this specification <rfc2119>MUST</rfc2119> enforce
the following:</p>
<ulist>
  <item>
                                <p>If <code>sml:targetType="ns:T"</code> is
    specified for <b>G,</b> and <b>S<sub>G</sub>
</b> is a
    global element declaration that specifies <b>G</b> as the value
    of its <code>xs:substitutionGroup</code> attribute, then</p>
    <ulist>
      <item>
                                    <p>if the <code>sml:targetType</code>
        attribute is specified for <b>S<sub>G</sub>
                                    </b> the its
        value    MUST be either <b>ns:T</b> or the name of some
        derived type of <b>ns:T</b>
</p>
      </item>
      <item>
                                    <p>if <code>sml:targetType</code> is not
        specified for <b>S<sub>G</sub>
                                    </b>, then
        <code>sml:targetType="ns:T"</code> holds for
        <b>S<sub>G</sub>
</b> by default</p>
      </item>
    </ulist>
  </item>
</ulist>

<p>If the target type constraint is specified for a particle
<b>P</b> in some type <b>B</b>, then it continues to
apply to each particle <b>P<sub>R</sub>
                            </b> that is a valid
restriction of <b>P</b> where <b>P<sub>R</sub>
                            </b> is
defined in some restricted derived type of <b>B</b>. However,
<b>P<sub>R</sub>
</b> can specify a target type constraint that
refines the constraint defined for <b>P</b>. In particular, model
validators that conform to this specification <rfc2119>MUST</rfc2119> enforce the following:</p>
<ulist>
  <item>
                                <p>If <code>sml:targetType="ns:T"</code> is
    specified for <b>P</b> and <code>sml:targetType</code> is
    specified for <b>P<sub>R</sub>
                                    </b> then the value of the
    <code>sml:targetType</code> for <b>P<sub>R</sub>
                                    </b> must be
    <b>ns:T</b> or the name of some derived type of
    <b>ns:T</b>. If <code>sml:targetType</code> is not specified
    for <b>P<sub>R</sub>
                                    </b>, then
    <code>sml:targetType="ns:T"</code> holds for
    <b>P<sub>R</sub>
</b> by default</p>
  </item>
</ulist>
</div4>
</div3>
</div2>
<div2 id="Identity_Constraints">
<head>Identity Constraints</head>

<p>XML Schema supports the definition of key, unique, and key reference
constraints through <code>xs:key</code>, <code>xs:unique</code>, and
<code>xs:keyref</code> elements. However, the scope of these constraints is
restricted to a single document. SML defines analogs for these constraints,
whose scope extends   to multiple documents by allowing them  to traverse
inter-document references. </p>

<p>
<termref def="model_validator">Model validators</termref> that conform to this specification <rfc2119>MUST</rfc2119> support the
following elements for defining identity constraints across references:</p>

<table border="1" cellspacing="0" id="Table5">
  <thead>
    <tr>
      <th rowspan="1" colspan="1">Name</th>
      <th rowspan="1" colspan="1">Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:key</code>
</td>
      <td rowspan="1" colspan="1">Similar to <code>xs:key</code> except that the selector and
        field XPath expression can use <code>smlfn:deref</code> function</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:unique</code>
</td>
      <td rowspan="1" colspan="1">Similar to <code>xs:unique</code> except that the selector and
        field XPath expression can use <code>smlfn:deref</code> function</td>
    </tr>
    <tr>
      <td rowspan="1" colspan="1">
                                <code>sml:keyref</code>
</td>
      <td rowspan="1" colspan="1">Similar to <code>xs:keyref</code> except that the selector and
        field XPath expression can use <code>smlfn:deref</code> function</td>
    </tr>
  </tbody>
</table>


<p>The syntax and semantics of the above elements are according to Section 3.11.2 of the XML Schema specification [<xspecref href="#XSD2" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XML Schema Datatypes</xspecref>], except for the following:</p>
<ulist>
  <item>
                        <p>If an SML identity constraint needs to be
    specified for an element declaration <b>E,</b> then it <rfc2119>MUST</rfc2119> be
    defined in the <code>xs:annotation</code>/<code>xs:appinfo</code>
    descendant element for the <code>xs:element</code> element for
    <b>E</b>
</p>
  </item>
  <item>
<p>An SML identity constraint that is specified
    for an element declaration  <b>E</b> can reuse the definition
    of an SML identity constraint <b>ID'</b> specified for some
    other element declaration <b>E'</b> by specifying the name of
    <b>E'</b> as the value of its <code>ref</code> attribute. In
    particular,</p>
    <ulist>
      <item>
<p>If the <code>ref</code> attribute is
        specified for an SML identity constraint
        element that is specified for an element declaration
        <b>E</b>, then the value of <code>ref</code> attribute <rfc2119>MUST</rfc2119>
        NOT be name of any other SML identity constraint element specified
        for <b>E</b>. </p>
      </item>
      <item>
<p>If the <code>ref</code> attribute is
        specified for an <code>sml:key</code> element, then the value of
        <code>ref</code> attribute <rfc2119>MUST</rfc2119> be name of another SML key
        constraint</p>
      </item>
      <item>
<p>If the <code>ref</code> attribute is
        specified for an <code>sml:unique</code> element then the value of
        the <code>ref</code> attribute <rfc2119>MUST</rfc2119> be name of another SML unique
        constraint</p>
      </item>
      <item>
<p>If the <code>ref</code> attribute is
        specified for an <code>sml:keyref</code> element then the value of
        the <code>ref</code> attribute <rfc2119>MUST</rfc2119> be name of another SML keyref
        constraint</p>
      </item>
      <item>
<p>If the <code>ref</code> attribute is
        specified for an SML identity constraint, then the <code>name</code>
        attribute <rfc2119>MUST NOT</rfc2119> be specified</p>
      </item>
      <item>
<p>If the <code>ref</code> attribute is
        specified for an SML identity constraint, then the
        <code>selector</code> and <code>field</code>
        child elements <rfc2119>MUST NOT</rfc2119> be specified</p>
      </item>
    </ulist>
  </item>
</ulist>

<ulist>
  <item>
<p>If an SML identity constraint is specified for an element
  declaration <b>E</b>, then this constraint is applicable to all
  instances of <b>E</b> in a model, i.e., the identity constraint
  <rfc2119>MUST</rfc2119> be satisfied for each instance of <b>E</b>
  in a valid model </p>
  </item>
  <item>

<p>The <code>sml:selector</code> XPath
    expression <rfc2119>MUST</rfc2119> conform to the following extended BNF</p>
  </item>
</ulist>
<eg xml:space="preserve">Selector ::= Path ( '|' Path)*
Path ::= ('.//')? Step ( '/' Step)* | DerefExpr
DerefExpr ::= (NCName ':')? 'deref(' Step (/Step)* ')'  ('/'Step)* |
              (NCName ':')? 'deref(' DerefExpr ')' (/Step)*
Step::= '.' | NameTest
NameTest ::= QName |'*' | NCName ':' '*'</eg>
<ulist>
  <item>

<p>The <code>sml:field</code> XPath expression
    <rfc2119>MUST</rfc2119> conform to the BNF given above for the selector XPath expression
    with the following modification</p>
  </item>
</ulist>
<eg xml:space="preserve">Path::= ('.//')?  ( Step '/')* ( Step | @NameTest ) |
        DerefExpr ('/' @NameTest)?</eg>
<ulist>
  <item>
                        <p>Each SML identity constraint that is
    specified for a global element declaration <b>G</b> <rfc2119>MUST</rfc2119> be
    treated as if it is specified by default for all global element
    declarations <b>S<sub>G</sub>
                            </b> that are in the substitution
    group hierarchy whose head is <b>G</b>
</p>
  </item>
  <item>
                        <p>Each SML identity
    constraint that is specified for a particle <b>P</b> in
    a complex-type definition <b>CT</b> <rfc2119>MUST</rfc2119> be
    treated as if it is specified by default for all particles
    <b>P<sub>R</sub>
                            </b> in restricted derived
    types of <b>CT</b> that are a valid
    restriction of <b>P</b>
</p>
  </item>
  <item>

                        <p>If one/more SML identity constraints are
    specified (either explicitly or by default) for a particle
    <b>P</b> in a complex-type definition <b>CT</b>, then
    all particles in <b>CT</b> that have the same <xspecref href="http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#e-name" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">name</xspecref>
    as <b>P</b> <rfc2119>MUST</rfc2119> specify the same set of identity constraints as <b>P</b>. This rule
    is defined to reduce the implementation burden for <termref def="model_validator">model validators</termref>. It
    facilitates the matching of restricting and restricted particles using
    their names, and avoids the replication of large parts of XML Schema's
    compilation logic for this purpose.</p>
  </item>
</ulist>

<div3 id="University_Example">
<head>University Example</head>

<p>The following example will be used to illustrate the <code>sml:key</code>,
<code>sml:unique</code>, and <code>sml:keyref</code> constraints across
references.</p>

<eg xml:space="preserve">&lt;xs:element name="Student"
                   type="sml:refType"
                   sml:targetType="tns:StudentType"/&gt;
&lt;xs:element name="Course"
                   type="sml:refType"
                   sml:targetType="tns:CourseType"/&gt;
  
&lt;xs:complexType name="UniversityType"&gt;
  &lt;xs:sequence&gt;
            &lt;xs:element name="Name" type="xs:string"/&gt;
            &lt;xs:element name="Students" minOccurs="0"&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element ref="tns:Student" maxOccurs="unbounded"/&gt;
                    &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
            &lt;xs:element name="Courses" minOccurs="0"&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element ref="tns:Course" maxOccurs="unbounded"/&gt;                              
                    &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
  &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;

        &lt;xs:element name="EnrolledStudent"
                    type="sml:refType"
                    sml:targetType="tns:StudentType"/&gt;
        &lt;xs:element name="EnrolledCourse"
                    type="sml:refType"
                    sml:targetType="tns:CourseType"/&gt;

&lt;xs:complexType name="StudentType"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="ID" type="xs:string"/&gt;
            &lt;xs:element name="SSN" type="xs:string" minOccurs="0"/&gt;
            &lt;xs:element name="Name" type="xs:string"/&gt;
            &lt;xs:element name="EnrolledCourses" minOccurs="0"&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element ref="tns:EnrolledCourse"
                                    maxOccurs="unbounded"/&gt;
                    &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;

&lt;xs:complexType name="CourseType"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="Name" type="xs:string"/&gt;
            &lt;xs:element name="EnrolledStudents" minOccurs="0"&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element ref="tns:EnrolledStudent"
                                    maxOccurs="unbounded"/&gt;
                    &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;</eg>

</div3>
<div3 id="sml_key_unique">
<head>sml:key and sml:unique</head>

<p>XML Schema supports key and uniqueness constraints through
<code>xs:key</code> and <code>xs:unique,</code> but these constraints can
only be specified within a single XML document. The <code>sml:key</code> and
<code>sml:unique</code> elements  support the specification of key and
uniqueness constraints across documents.  We'll use the <code>UniversityType</code> (see <specref ref="University_Example"/>)
definition to illustrate this concept. It is reasonable to expect that each
student in a university must have a unique identity, and this identity must
be specified. This can be expressed as follows:</p>
<eg xml:space="preserve">&lt;xs:element name="University" type="tns:UniversityType"&gt;
        &lt;xs:annotation&gt;
            &lt;xs:appinfo&gt;
                &lt;sml:key name="StudentIDisKey"&gt;
                   &lt;sml:selector xpath="smlfn:deref(tns:Students/tns:Student)/tns:ID"/&gt;
                   &lt;sml:field xpath="."/&gt;  
                &lt;/sml:key&gt;  
            &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</eg>

<p>The <code>sml:key</code> and <code>sml:unique</code> constraints are
similar but not the same. <code>sml:key</code> requires that the specified
fields must be present in instance documents and have unique values, whereas
<code>sml:unique</code> simply requires the specified fields to have unique
values but does not require them to be present in instance documents.  Thus
keys imply uniqueness, but uniqueness does not imply keys.  For example,
students in a university must have a unique social security numbers, but the
university may have foreign students who do not possess this number. This
constraint can be specified as follows:</p>
<eg xml:space="preserve">&lt;xs:element name="University" type="tns:UniversityType"&gt;
        &lt;xs:annotation&gt;
            &lt;xs:appinfo&gt;
                &lt;sml:unique name="StudentSSNisUnique"&gt;
                   &lt;sml:selector xpath="smlfn:deref(tns:Students/tns:Student)"/&gt;
                   &lt;sml:field xpath="tns:SSN"/&gt;  
                &lt;/sml:unique&gt;  
            &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</eg>

<p>The <code>sml:key</code> and <code>sml:unique</code>  constraint
are always specified in the context of a scoping element. In the above
example, the <code>University</code> element declaration is the
context for the key and unique constraints.</p>

<p>The following example illustrates the use of the <code>ref</code>
attribute in an SML identity constraint:</p>
<eg xml:space="preserve">&lt;xs:element name="PrivateUniversity" type="tns:UniversityType"&gt;
        &lt;xs:annotation&gt;
            &lt;xs:appinfo&gt;
                &lt;sml:unique ref="tns:StudentSSNisUnique"/&gt;
            &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</eg>

<p>In the above example, the <code>PrivateUniversity</code> element
declaration specifies the <code>StudentSSNisUnique</code> unique
constraint by referencing its definition in the
<code>University</code> element declaration.</p>
</div3>
<div3 id="sml_keyref">
<head>sml:keyref</head>

<p>XML Schema supports key references through <code>xs:keyref</code> to
ensure that one set of values is a subset of another set of values within an
XML document. Such constraints are similar to foreign keys in relational
databases. Key references in XML Schema are only supported within a single
XML document. The <code>sml:keyref</code> element allows key references to be
specified across XML documents, and can be used to scope references to point
to elements within a valid range. The following example uses
<code>sml:keyref</code> to capture the requirement that courses in a
university can only enroll students from the same university:</p>
<eg xml:space="preserve">&lt;xs:element name="University" type="tns:UniversityType"&gt;
        &lt;xs:annotation&gt;
            &lt;xs:appinfo&gt;
                &lt;sml:key name="StudentIDisKey"&gt;
                   &lt;sml:selector xpath="smlfn:deref(tns:Students/tns:Student)"/&gt;
                   &lt;sml:field xpath="tns:ID"/&gt;  
                &lt;/sml:key&gt;  
                &lt;sml:keyref name="CourseStudents" refer="tns:StudentIDisKey"&gt;
                   &lt;sml:selector xpath="smlfn:deref(
                                        smlfn:deref(tns:Courses/tns:Course)/
                                        tns:EnrolledStudents/tns:EnrolledStudent)"/&gt;
                   &lt;sml:field xpath="tns:ID"/&gt;
                &lt;/sml:keyref&gt;
            &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</eg>

<p>The above constraint specifies that for a university, the set of IDs of
students enrolled in courses is a subset of the set of IDs of students in a
university. In particular, the <code>selector</code> and <code>field</code>
elements in <code>StudentIDisKey</code> key constraint identify the set of
IDs of students in a university, and the <code>selector</code> and
<code>field</code> elements in <code>CourseStudents</code> key reference
constraint identify the set of IDs of students enrolled in courses.   </p>
</div3>
</div2>
</div1>
<div1 id="Rules">
<head>Rules</head>

<p>XML Schema
supports a number of built-in grammar-based constraints but it does not
support a language for defining arbitrary <termref def="rule">rules</termref> for constraining the
structure and content of documents. Schematron [<bibref ref="Schematron"/>] is an ISO/IEC standard for
defining assertions concerning a set of XML documents. SML uses a profile of
the Schematron schema to add support for user-defined constraints. SML uses
XPath1.0, augmented with the <code>smlfn:deref()</code>  extension function, as its constraint language. <termref def="model_validator">Model
validators</termref> that conform to this specification are <rfc2119>REQUIRED</rfc2119> to support and
evaluate XPath 1.0 expressions augmented with the
<code>smlfn:deref()</code> function in the body of
Schematron constraints. This section assumes that the reader is familiar with
Schematron concepts; the Schematron standard is documented in [<bibref ref="Schematron"/>] and [<bibref ref="intro_schematron"/>, <bibref ref="improving_schematron"/>]
are good tutorials on an older version of Schematron.</p>

<p>User-defined constraints can be specified using the
<code>sch:assert</code> and <code>sch:report</code> elements from Schematron.
 The following example uses <code>sch:assert</code> elements to specify two
constraints:</p>
<ulist>
  <item>
<p>An IPv4 address must have four bytes</p>
  </item>
  <item>
<p>An IPv6 address must have sixteen bytes</p>
  </item>
</ulist>
<eg xml:space="preserve">&lt;xs:simpleType  name="IPAddressVersionType"&gt;
       &lt;xs:restriction base="xs:string" &gt;
           &lt;xs:enumeration value="V4" /&gt;
           &lt;xs:enumeration value="V6" /&gt;
        &lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;

&lt;xs:complexType name="IPAddress"&gt;
        &lt;xs:annotation&gt;
            &lt;xs:appinfo&gt;
                &lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
                   &lt;sch:ns prefix="tns" uri="urn:IPAddress" /&gt;
                   &lt;sch:pattern id="Length"&gt;
                      &lt;sch:rule context="."&gt;
                         &lt;sch:assert test="tns:version != 'V4' or count(tns:address) = 4"&gt;
                              A v4 IP address must have 4 bytes.
                         &lt;/sch:assert&gt;
                         &lt;sch:assert test="tns:version != 'V6' or count(tns:address) = 16"&gt;
                              A v6 IP address must have 16 bytes.
                         &lt;/sch:assert&gt;
                      &lt;/sch:rule&gt;
                   &lt;/sch:pattern&gt;
                &lt;/sch:schema&gt;            
            &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
        &lt;xs:sequence&gt;
            &lt;xs:element name="version" type="tns:IPAddressVersionType" /&gt;
            &lt;xs:element name="address" type="xs:byte" minOccurs="4" maxOccurs="16" /&gt;
        &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;</eg>

<p>A Schematron pattern embedded in the
<code>xs:annotation/xs:appinfo</code> element for a complex
type definition or an element declaration is applicable to all instances of
the complex type or element. In the above example, the pattern
<code>Length</code> is applicable for all elements whose
type is <code>IPAddress</code> or a derived type
of <code>IPAddress</code>. A pattern can have one or
more <termref def="rule">rules</termref>, and each rule specifies a context expression using the
<code>context</code> attribute. The value of the
<code>context</code> attribute is an XPath expression that
is evaluated in the context of each applicable element, and results in an
element node set for which the assert and report test expressions defined in
the rule are evaluated. In the above example
<code>context="."</code> therefore the two assert
expressions are evaluated in the context of each applicable element, i.e.,
each element of type <code>IPAddress</code>.  The
test expression for an <code>assert</code> is a
boolean expression, and the <code>assert</code> is
violated (or fires) if its test expression evaluates to false.  For example,
the following XML document violates the <code>assert</code> that requires an IPv6 address to have sixteen address
bytes</p>
<eg xml:space="preserve">&lt;myIPAddress xmlns="urn:IPAddress"&gt;
  &lt;version&gt;v6&lt;/version&gt;
  &lt;address&gt;100&lt;/address&gt;
  &lt;address&gt;200&lt;/address&gt;
  &lt;address&gt;10&lt;/address&gt;
  &lt;address&gt;1&lt;/address&gt;
  &lt;address&gt;10&lt;/address&gt;
  &lt;address&gt;1&lt;/address&gt;
&lt;/myIPAddress&gt;</eg>

<p>In general, a <code>rule</code> element can include multiple <code>assert</code> and <code>report</code> elements.
A <code>report</code> also specifies a test
expression, just like an <code>assert</code>.
However, a <code>report</code> is violated (or
fires) if its test expression evaluates to true. Thus, an
<code>assert</code> can be converted to a
<code>report</code> by simply negating its test expression.
The following example uses <code>report</code> elements to represent the IP address constraints of the previous
example:</p>
<eg xml:space="preserve">    &lt;xs:simpleType  name="IPAddressVersionType"&gt;
        &lt;xs:restriction base="xs:string"&gt;
           &lt;xs:enumeration value="V4"/&gt;
           &lt;xs:enumeration value="V6"/&gt;
        &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;

    &lt;xs:complexType name="IPAddress"&gt;
        &lt;xs:annotation&gt;
            &lt;xs:appinfo&gt;
                &lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
                    &lt;sch:ns prefix="tns" uri="urn:IPAddress" /&gt;
                    &lt;sch:pattern id="Length"&gt;
                        &lt;sch:rule context="."&gt;
                            &lt;sch:report test="tns:version = 'V4' and count(tns:address)!= 4"&gt;
                                A v4 IP address must have 4 bytes.
                            &lt;/sch:report&gt;
                            &lt;sch:report test="tns:version = 'V6' and count(tns:address) != 16"&gt;
                                A v6 IP address must have 16 bytes.
                            &lt;/sch:report&gt;
                        &lt;/sch:rule&gt;
                    &lt;/sch:pattern&gt;
                &lt;/sch:schema&gt;            
            &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
        &lt;xs:sequence&gt;
            &lt;xs:element name="version" type="tns:IPAddressVersionType" /&gt;
            &lt;xs:element name="address" type="xs:byte" minOccurs="4" maxOccurs="16" /&gt;
        &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;</eg>

<p>If an <code>assert</code> or <code>report</code> is violated, then
the violation must be reported during <termref def="model_validation_t">model validation</termref> together with the
specified message.  Model validation must evaluate each Schematron pattern
for all of its applicable elements contained in the model.  </p>

<p>The message can include substitution strings based on
XPath expressions. These can be specified using the
<code>sch:value-of</code> element. The following example
uses the <code>sch:value-of</code> element to
include the number of specified address bytes in the message:</p>
<eg xml:space="preserve">     &lt;sch:assert test="tns:version != 'v4' or count(tns:address) = 4"&gt;
          A v4 IP address must have 4 bytes instead of the specified
          &lt;sch:value-of select="string(count(tns:address))"/&gt; bytes.
     &lt;/sch:assert&gt;</eg>

<p>In addition to being embedded in complex
type definitions, constraints can also be embedded in global element
declarations. Such constraints are evaluated for each instance element
corresponding to the global element declaration. Consider the following
example:</p>

<eg xml:space="preserve">&lt;xs:element name="StrictUniversity" type="tns:UniversityType"&gt;
    &lt;xs:annotation&gt;
        &lt;xs:appinfo&gt;
            &lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
                &lt;sch:ns prefix="u" uri="http://www.university.example.org/ns" /&gt;
                &lt;sch:ns prefix="smlfn"  
                        uri="http://www.w3.org/2007/08/sml-function"/&gt;
                &lt;sch:pattern id="StudentPattern"&gt;
                    &lt;sch:rule context="smlfn:deref(u:Students/u:Student)"&gt;
                        &lt;sch:assert test="starts-with(u:ID,'99')"&gt;
                            The specified ID &lt;sch:value-of select="string(u:ID)"/&gt;
                             does not begin with 99
                        &lt;/sch:assert&gt;
                        &lt;sch:assert test="count(u:Courses/u:Course)&gt;0"&gt;
                            The student &lt;sch:value-of select="string(u:ID)"/&gt; must be enrolled
                            in at least one course
                        &lt;/sch:assert&gt;
                    &lt;/sch:rule&gt;
                &lt;/sch:pattern&gt;
             &lt;/sch:schema&gt;
         &lt;/xs:appinfo&gt;
    &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</eg>

<p>The constraints defined in
<code>StudentPattern</code> are applicable to all element
instances of the <code>StrictUniversity</code> global element declaration. For each
<code>StrictUniversity</code> element, the XPath expression
specified as the value of the <code>context</code> attribute is evaluated to return a node set, and the test
expressions for the two asserts are evaluated for each node in this node set.
 The context expression for the <termref def="rule">rule</termref> returns a node set consisting of
all <code>Student</code> elements referenced by an
instance of <code>StrictUniversity</code>, and the
test expressions for the two asserts are evaluated for each element node in
this node set.  Thus, these two asserts verify the following conditions for
each instance of <code>StrictUniversity</code>
</p>
<ulist>
  <item>
<p>The ID of each student must begin with
    '99'</p>
  </item>
  <item>
<p>Each student must be enrolled in at least
    one course</p>
  </item>
</ulist>

<p>
<termref def="model_validator">Model validators</termref> that conform to this
specification  MUST behave as follows:  </p>
<ulist>
  <item>
<p>Each Schematron pattern
    that is embedded in the <code>xs:annotation/xs:appinfo</code>
    element for a global complex-type definition
    <b>CT</b> <rfc2119>MUST</rfc2119> be evaluated for all element
    instances of type <b>CT</b> in a model
    during the model's validation</p>
  </item>
</ulist>
<ulist>
  <item>
<p>Each Schematron pattern that is embedded in the
  <code>xs:annotation/xs:appinfo</code> element for a global element
  declaration <b>G</b> <rfc2119>MUST</rfc2119> be evaluated for all
  element instances of <b>G</b> in a model during the model's
  validation</p>
  </item>
  <item>
<p>A pattern <rfc2119>MUST</rfc2119> be evaluated for an
  instance element by evaluating the <code>rule</code> elements of the
  pattern in the order of their definition. The context expression for
  a rule <rfc2119>MUST</rfc2119> be evaluated in the context of the
  instance element, and all asserts and reports contained in the first
  rule whose context expression evaluates to a non-empty node set
  <rfc2119>MUST</rfc2119> be evaluated for each node in this node
  set.</p>
  </item>
</ulist>

<p>
<termref def="model_validator">Model validators</termref> that
conform to this specification <rfc2119>MUST</rfc2119> provide a
mechanism to support binding of Schematron patterns that are authored
in separate documents, i.e., not embedded in schema definition, to a
set of documents in a model. The mechanism for binding such Schematron
patterns to a set of documents in a model is implementation-dependent
and hence outside the scope of this specification.  The following
example shows the constraints for <code>StrictUniversity</code>
expressed in a separate document:</p>
<eg xml:space="preserve">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
        &lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
            &lt;sch:ns prefix="u" uri="http://www.university.example.org/ns" /&gt;
            &lt;sch:ns prefix="smlfn" uri="http://www.w3.org/2007/08/sml-function"/&gt;
            &lt;sch:pattern id="StudentPattern"&gt;
                &lt;sch:rule context="smlfn:deref(u:Students/u:Student)"&gt;
                    &lt;sch:assert test="starts-with(u:ID,'99')"&gt;
                        The specified ID &lt;sch:value-of select="string(u:ID)"/&gt;
                        does not begin with 99
                    &lt;/sch:assert&gt;
                    &lt;sch:assert test="count(u:Course/u:Courses)&gt;0"&gt;
                        The student &lt;sch:value-of select="string(u:ID)"/&gt; must be enrolled
                        in at least one course
                    &lt;/sch:assert&gt;
                &lt;/sch:rule&gt;
            &lt;/sch:pattern&gt;
&lt;/sch:schema&gt;</eg>

<p>The binding of the
<code>StudentPattern</code> pattern to instances of
<code>StrictUniversity</code> element is implementation-dependent 
and hence outside the scope of this specification.</p>

<div2 id="Localization_of_Error_Messages">
<head>Localization of Error Messages</head>
<div3 id="localizationid">

<head>smlerr:localizationid</head>
<p>Localization of the natural-language error messages, which provide
details about asserts and reports, <rfc2119>MAY</rfc2119> be supported
by model validators that conform to this specification. Such model
validators <rfc2119>MAY</rfc2119> support the use of
<code>smlerr:localizationid</code> attribute on
<code>sch:report</code> and <code>sch:assert</code> to specify the
identity of the resource containing the localized versions of the
natural-language error message.</p>
<p>Model validators that conform to this
specification but do not support
<code>smlerr:localizationid</code> attribute
<rfc2119>MUST</rfc2119> ignore all <code>smlerr:localizationid</code>
attributes in a model; they <rfc2119>MUST NOT</rfc2119> treat the
model as invalid just because it contains
<code>smlerr:localizationid</code> attributes.</p>
<p>The
mechanisms for mapping values of <code>smlerr:localizationid</code> to
the corresponding localization resources are implementation-dependent
and hence outside the scope of this specification.</p>
</div3>
</div2>
<div2 id="Schematron_Profile">
<head>Schematron Profile</head>

<p>SML supports a conforming profile of
Schematron. All elements and attributes are supported.  </p>

<div3 id="Limited_Support">
<head>Limited Support</head>

<p>If the <code>queryBinding</code>
attribute is specified, then its value <rfc2119>MUST</rfc2119> be set to
"xpath1.0"</p>
</div3>
</div2>
</div1>
<div1 id="Structured_XML_Output_from_Schematron_Rules">
<head>Structured XML Output
from Schematron Rules</head>

<p>Schematron has rich support for natural-language error
and diagnostic messages that provide details about failed assertions. As per
the Schematron specification the content of the
<code>sch:assert</code>,
<code>sch:report</code>, and the optional
<code>sch:diagnostic</code> elements should be natural
language assertions or messages. To facilitate machine processable output
from the evaluation of Schemtron rules, this specification extends Schematron
by adding support for structured XML output that provides details about
failed assertions. This structured XML data can be consumed by an application
to perform some application-specific tasks required to handle a failed
assertion. This is an <rfc2119>OPTIONAL</rfc2119> feature and model validators that conform to
this specification are not <rfc2119>REQUIRED</rfc2119> to support it. Model validators
that conform to this specification but do not support
<code>smlerr:output</code> element <rfc2119>MUST</rfc2119> ignore all <code>smlerr:output</code>
elements in a model; they <rfc2119>MUST NOT</rfc2119> treat the model as invalid just because it
contains <code>smlerr:output</code> elements. </p>

<div2 id="smlerr_output">
<head>smlerr:output</head>

<p>This element is used to specify the structured XML output for one/more
failed assertions. It is supported as a child of the <code>sch:rule</code>
element. An <code>sch:rule</code> element can contain multiple
<code>smlerr:output</code> elements. The schema definition for
<code>smlerr:output</code> is as follows:</p>
<eg xml:space="preserve">  &lt;xs:element name="output" type="smlerr:outputType"/&gt;

  &lt;xs:complexType name="outputType"&gt;
      &lt;xs:attribute name="id" type="xs:ID"
                    use="required"/&gt;
      &lt;xs:attribute name="applicationUri" type="xs:anyURI"
                  use="optional"/&gt;
      &lt;xs:attribute name="expression" type="xs:string" use="required"/&gt;
  &lt;/xs:complexType&gt;</eg>

<p>
<code>id =</code> a required attribute that defines the
identity of an <code>smlerr:output</code> element. This identity is used by an <code>assert</code> and/or <code>report</code> element
to specify that the expression specified in the <code>expression</code> attribute of the <code>smlerr:output</code> element must be evaluated to
generate structured XML when the assert/report fires. This identity is specified on one or more <code>assert</code> and/or <code>report</code> elements'
<code>smlerr:outputids</code> attribute.  Each time such an assert or report fires, the
<code>smlerr:output</code> element's <code>expression</code> attribute is evaluated to generate
structured XML.   </p>

<p>
<code>applicationUri</code> = an optional attribute that specifies the
identity of the application for which the output is generated</p>

<p>

<code>expression</code>= an XPath 1.0 expression that evaluates to a node
set containing element and attribute nodes only. If the node set contains
namespace, processing instructions, comments, or text nodes, then no output
is generated. The expression is evaluated in the context of the node selected
by the <code>context</code> attribute in the  parent <code>sch:rule</code>
element. This XPath expression can use the <code>deref()</code> extension
function.</p>

<div3 id="smlerr_outputids">
<head> smlerr:outputids</head>

<p>This global attribute can be used in a 
<code>sch:report</code> or <code>sch:assert</code> element to specify the
identities of the <code>smlerr:output</code> elements whose expressions must
be evaluated to generate XML output when the assert/report fires.</p>
<eg xml:space="preserve">&lt;xs:attribute name="outputids" type="xs:IDREFS"/&gt;</eg>

</div3>
<div3 id="smlerr_attributeNode">
<head>smlerr:attributeNode</head>

<p>This element is used for serialization of each attribute node in the node
set resulting from the evaluation of the <code>expression</code> attribute on an
<code>smlerr:output</code> element.</p>

<eg xml:space="preserve">  &lt;xs:element name="attributeNode" type="smlerr:attributeNodeType"/&gt;

  &lt;xs:complexType name="attributeNodeType"&gt;
      &lt;xs:simpleContent&gt;
          &lt;xs:extension base="xs:string"&gt;
              &lt;xs:attribute name="name" type="xs:QName"/&gt;
          &lt;/xs:extension&gt;
      &lt;/xs:simpleContent&gt;
  &lt;/xs:complexType&gt;</eg>

<p>The value of the <code>name</code> attribute is the
qualified name of the attribute whose value is being serialized.</p>
</div3>
<div3 id="smlerr_errorDateType">
<head>smlerr:errorDataType</head>

<p>This element is used for enclosing the structured XML
generated by an <code>smlerr:output</code> element.
 </p>
<eg xml:space="preserve">  &lt;xs:element name="errorData" type="smlerr:errorDataType"/&gt;
  &lt;xs:complexType name="errorDataType"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:any namespace="##any" maxOccurs="unbounded" processContents="skip"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;</eg>

</div3>
<div3 id="Semantics">
<head>Semantics</head>

<p>When a report/assert fires, then all <code>smlerr:output</code> elements
whose ID is listed in the <code>outputids</code> attribute on 
that <code>sch:report</code> or <code>sch:assert</code>
element are evaluated. For each such
<code>smlerr:output</code>,  the expression specified in its
<code>expression</code> attribute is evaluated, and the resulting node set is 
serialized into XML by concatenating each node and enclosing the serialized
XML fragment in the <code>smlerr:errorData</code> element to create a
well-formed XML document. The resulting document is returned to the
application that initiated the <termref def="model_validation_t">model validation</termref>. The serialization is only
performed if the node set contains attribute and/or element nodes. Otherwise,
no structured XML is serialized and an empty <code>smlerr:errorData</code>
element is returned.</p>

<p>The nodes in the node set may be serialized in any order.  Element nodes
are serialized directly into their XML representation, and
attribute nodes are serialized by using the <code>smlerr:attributeNode</code>
element.</p>

<p>All namespace bindings defined (through the <code>sch:ns</code> element)
for the parent <code>sch:rule</code>, <code>sch:pattern</code>, or
<code>sch:schema</code> elements remain valid and can be used in the
expression specified in the <code>expression</code> attribute.</p>

</div3>
<div3 id="Examples">
<head>Examples</head>

<p>The following example illustrates the use of <code>smlerr:output</code>
</p>

<eg xml:space="preserve">   &lt;xs:simpleType  name="IPAddressVersionType"&gt;
       &lt;xs:restriction base="xs:string"&gt;
           &lt;xs:enumeration value="V4"/&gt;
           &lt;xs:enumeration value="V6"/&gt;
       &lt;/xs:restriction&gt;
   &lt;/xs:simpleType&gt;

   &lt;xs:complexType name="IPAddressType"&gt;
       &lt;xs:annotation&gt;
           &lt;xs:appinfo&gt;
               &lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
                   &lt;sch:ns prefix="tns" uri="urn:IPAddress" /&gt;
                   &lt;sch:pattern id="Length"&gt;
                       &lt;sch:rule context="."&gt;
                           &lt;sch:report id="v4" test="tns:version = 'V4' and count(tns:address)!= 4"
                                       smlerr:outputids="IPXML"&gt;
                               A v4 IP address must have 4 bytes.
                           &lt;/sch:report&gt;
                           &lt;sch:report id="v6" test="tns:version = 'V6' and count(tns:address) != 16"
                                       smlerr:outputids="IPXML"&gt;
                               A v6 IP address must have 16 bytes.
                           &lt;/sch:report&gt;
                           &lt;smlerr:output applicationUri="someApplicationUri"
                                       id="IPXML"
                                       expression="."&gt;
                           &lt;/smlerr:output&gt;
                       &lt;/sch:rule&gt;
                   &lt;/sch:pattern&gt;
               &lt;/sch:schema&gt;
           &lt;/xs:appinfo&gt;
       &lt;/xs:annotation&gt;
       &lt;xs:sequence&gt;
           &lt;xs:element name="version" type="tns:IPAddressVersionType" /&gt;
           &lt;xs:element name="address" type="xs:byte"
                       minOccurs="4" maxOccurs="16" /&gt;
       &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;</eg>

<p>If the report with <code>id="v4"</code> fires for an element
<code>ipaddress</code> of type <code>IPAddressType</code>, then the output
may look like</p>

<eg xml:space="preserve">&lt;smlerr:errorData xmlns:smlerr="http://www.w3.org/2007/08/sml-err"&gt;
  &lt;ipaddress xmlns="urn:IPAddress"&gt;
    &lt;version&gt;v4&lt;/version&gt;
    &lt;address&gt;10&lt;/address&gt;
    &lt;address&gt;10&lt;/address&gt;
    &lt;address&gt;20&lt;/address&gt;
    &lt;address&gt;0&lt;/address&gt;
    &lt;address&gt;0&lt;/address&gt;  
  &lt;/ipaddress&gt;
&lt;/smlerr:errorData&gt;</eg>

<p>The following example illustrates an
<code>smlerr:output</code> element whose expression results
in attribute nodes</p>
<eg xml:space="preserve">  &lt;xs:complexType name="universityType"&gt;
      &lt;xs:annotation&gt;
          &lt;xs:appinfo&gt;
              &lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
                  &lt;sch:ns prefix="u" uri="http://www.university.example.org/ns" /&gt;
                  &lt;sch:pattern id="Count"&gt;
                      &lt;sch:rule context="."&gt;
                          &lt;sch:assert id="StudentCount"
                                      test="count(u:student)&amp;gt;20"
                                      smlerr:outputids="StudentXml"&gt;
                              A university must have  more than 20 students 
                          &lt;/sch:assert&gt;
                          &lt;smlerr:output id="StudentXml"  
                                         expression="@name|@isPublic" /&gt;
                      &lt;/sch:rule&gt;
                  &lt;/sch:pattern&gt;
              &lt;/sch:schema&gt;
          &lt;/xs:appinfo&gt;
      &lt;/xs:annotation&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="student" type="sml:refType"
                      minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute name="name" type="xs:string"/&gt;
      &lt;xs:attribute name="isPublic" type="xs:boolean"/&gt;
  &lt;/xs:complexType&gt;</eg>

<p>If  the assert fires for an element of type
<code>universityType</code> then the output may look
like</p>

<eg xml:space="preserve">&lt;smlerr:errorData xmlns:sml="http://www.w3.org/2007/08/sml-err"&gt;
  &lt;smlerr:attributeNode xmlns:u="http://www.university.example.org/ns"
                        name="u:name"&gt;MIT&lt;/smlerr:attributeNode&gt;
  &lt;smlerr:attributeNode xmlns:u="http://www.university.example.org/ns"
                        name="u:isPublic"&gt;false&lt;/smlerr:attributeNode&gt;
&lt;/smlerr:errorData&gt;</eg>
</div3>
</div2>
</div1>
<div1 id="Model_Validation">
<head>Model Validation</head>

<p>
                <termref def="model_validation_t">Model validation</termref> is the process of examining each document in a model and
verifying that this document is valid with respect to the <termref def="model_definition">model's
definition</termref> documents, i.e., each document satisfies the schemas and rules
defined in the model's definition documents.  All of the following <rfc2119>MUST</rfc2119> be
true for a valid <termref def="model">model</termref>:</p>
<ulist>
  <item>
                    <p>Each <termref def="document">document</termref> in the model <rfc2119>MUST</rfc2119> be a
    well-formed XML document [<bibref ref="XML10"/>]</p>
  </item>
  <item>

<p>Each XML Schema document in the model's
    definition documents <rfc2119>MUST</rfc2119> be a valid XML Schema document [<bibref ref="XSD2"/>]</p>
  </item>
  <item>

<p>Each Schematron document in the model's
    definition documents <rfc2119>MUST</rfc2119> be a valid Schematron document [<bibref ref="Schematron"/>]</p>
  </item>
  <item>
<p>Each document in the model <rfc2119>MUST</rfc2119> be XML
    Schema valid with respect to the XML Schema documents in the model's
    definition documents</p>
  </item>
  <item>
<p>Each document in the model <rfc2119>MUST</rfc2119> satisfy all
    applicable <code>sml:target*</code> and Schematron constraints</p>
  </item>
  <item>

<p>The model <rfc2119>MUST NOT</rfc2119> contain a cycle whose
    edges are references of type <b>R</b> if <b>R</b> is
    an acyclic reference type</p>
  </item>
</ulist>

<div2 id="Schematron_Phase">
<head>Schematron Phase</head>
<p>A phase in schematron can be used to define
a collection of patterns. A schematron processor can optionally evaluate only
rules within a specific phase. For model validation, rule evaluation happens
on the #ALL phase, implying that every rule in every pattern is
evaluated.</p>
</div2>
</div1>
<div1 id="SML_Extension_Reference">
<head>SML Extension Reference</head>

<p>This section is a non-normative reference of the SML extensions to XML
Schema and XPath 1.0. </p>

<div2 id="Types">
<head>Types</head>

<div3 id="sml_refType">
<head>sml:refType</head>

<p>A complex type representing a reference to an element. </p>

<eg xml:space="preserve">    &lt;xs:complexType name="refType" sml:acyclic="false"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:any namespace="##any" minOccurs="0"
                maxOccurs="unbounded"
                processContents="lax"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute ref="sml:ref" use="required"
                    fixed="true" /&gt;
      &lt;xs:anyAttribute namespace="##any"
                       processContents="lax"/&gt;
    &lt;/xs:complexType&gt;</eg>

<p>No specific
scheme is mandated for representing references, and a <termref def="model_validator">model validator</termref> is free
to choose any suitable scheme. However, each reference value must resolve to
a single element. <code>sml:refType</code> can only
be used with element declarations; it is not supported on attribute
declarations.</p>
</div3>
</div2>
<div2 id="Attributes">
<head>Attributes</head>

<div3 id="sml_acyclic2">
<head>sml:acyclic</head>

<p>Used to specify that a derived type of <code>sml:refType</code> is
acyclic, i.e., its instances do not create any cycles in a model. </p>
<eg xml:space="preserve">&lt;xs:attribute name="acyclic" type="xs:boolean"/&gt;</eg>

<p>If this attribute is set to true for a
derived type <code>D</code> of
<code>sml:refType</code>, then instances of <code>D</code> (including any derived
types of <code>D</code>) can not create any cycles
in a model. More precisely, the directed graph whose nodes are documents that
contain the source or target elements for instances of
<code>D</code>, and whose edges are instances of
<code>D</code> (an edge is directed from the document
containing the source element to the document containing the target element),
 must be acyclic. A model is invalid if its documents result in a cyclic
graph using instances of <code>D</code>. In
the following example, <code>Hostref</code> is a restricted derived type of <code>sml:refType</code>
and its instances can not create any cycles:</p>

<eg xml:space="preserve">&lt;xs:complexType name="Hostref" sml:acyclic="true"&gt;
  &lt;xs:complexContent&gt;
    &lt;xs:restriction base="sml:refType"/&gt;
  &lt;/xs:complexContent&gt;
&lt;/xs:complexType&gt;</eg>

<p>If
the <code>sml:acyclic</code> attribute is not
specified or set to false for a derived type of
<code>sml:refType</code>, then instances of this reference
type may create cycles in a model. Note that <code>sml:acyclic</code>
is specified as <code>"false</code>" for <code>sml:refType</code>; hence
its instances are allowed to create cycles in a model.</p>

</div3>
<div3 id="sml_ref">
<head>sml:ref</head>

<p>This global attribute is used to identify reference elements.</p>
<eg xml:space="preserve">&lt;xs:attribute name="ref" type="xs:boolean"/&gt;</eg>

<p> Any element that has sml:ref="true" will be treated as a
reference element. Note that sml:ref="true" for all elements
whose type is sml:refType or a derived type sml:refType.</p>

</div3>
<div3 id="sml_targetElement2">
<head>sml:targetElement</head>

<p>A <code>QName</code> representing the name of a referenced element</p>
<eg xml:space="preserve"> &lt;xs:attribute name="targetElement" type="xs:QName"/&gt;</eg>

<p>
<code>sml:targetElement</code> is supported as an attribute for  element
declarations  whose type is
<code>sml:refType</code> or a type derived by restriction
from <code>sml:refType.</code> The value of this
attribute must be the name of some global element declaration. Let
<code>sml:targetElement="ns:GTE"</code> for some element declaration
<b>E</b>. Then each element instance of <b>E</b> must
target an element that is an instance of <b>ns:GTE</b> or an
instance of some global element declaration in the substitution group
hierarchy whose head is <b>ns:GTE</b>.</p>

<p>In the following example, the element referenced by
instances of <code>HostOS</code> must be instances
of <code>win:Windows</code>
</p>
<eg xml:space="preserve">          &lt;xs:element name="HostOS" type="sml:refType"
                      sml:targetElement="win:Windows"
                      minOccurs="0"/&gt;</eg>

<p>A model is invalid if its documents violate
one/more sml:targetElement constraints.</p>

</div3>
<div3 id="sml_targetRequired2">
<head>sml:targetRequired</head>

<p>Used to specify that instances of a reference element must target elements
in the model, i.e., an instance of the reference element can not be empty or
null, or contain a dangling reference which does not target any element in
the model.</p>
<eg xml:space="preserve">&lt;xs:attribute name="targetRequired" type="xs:boolean"/&gt;</eg>

<p>In the
following example, the <code>targetRequired</code> attribute is used to specify that application instances must have
a host operating system.</p>
<eg xml:space="preserve">  &lt;xs:complexType name="ApplicationType"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="Name" type="xs:string"/&gt;
      &lt;xs:element name="Vendor" type="xs:string"/&gt;
      &lt;xs:element name="Version" type="xs:string"/&gt;
      &lt;xs:element name="HostOSRef" type="sml:refType"
                  sml:targetRequired="true"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;</eg>

<p>A model is invalid if its documents violate one/more
<code>sml:targetRequired</code> constraints.</p>

</div3>
<div3 id="sml_targetType2">
<head>sml:targetType</head>

<p>A <code>QName</code> representing the type of a referenced element</p>
<eg xml:space="preserve">    &lt;xs:attribute name="targetType" type="xs:QName"&gt;</eg>

<p>

<code>sml:targetType</code> is supported as an attribute for element
declarations  whose type is
<code>sml:refType</code> or a type derived by restriction
from <code>sml:refType</code>. If the value of this
attribute is specified as <code>T</code>, then the
type of the referenced element must either be <code>T</code> or a derived type of <code>T</code>. In
the following example, the type of the element referenced by the
<code>OperatingSystem</code> element must be
"<code>ibm:LinuxType</code>" or its derived
type</p>
<eg xml:space="preserve">          &lt;xs:element name="OperatingSystem" type="sml:refType"
                      sml:targetType="ibm:LinuxType"
                      minOccurs="0"/&gt;</eg>

<p>A model is invalid if its documents violate
one/more sml:targetType constraints.</p>
</div3>
</div2>
<div2 id="Elements">
<head>Elements</head>

<div3 id="sml_key">
<head>sml:key</head>

<p>This element is used to specify a key constraint in some scope. The
semantics are essentially the same as that for <code>xs:key</code> but
<code>sml:key</code> can also be used to specify key constraints on other
documents, i.e., the  <code>sml:selector</code> child element of
<code>sml:key</code> can contain <code>deref</code> functions to resolve
elements in another document.</p>
<eg xml:space="preserve">&lt;xs:element name="key" type="sml:keybase"/&gt;</eg>

<p>

<code>sml:key</code> is supported in the <code>appinfo</code>
of an <code>xs:element</code>.  </p>

</div3>
<div3 id="sml_keyref2">
<head>sml:keyref</head>

<p>Applies a constraint in the context of the containing xs:element that scopes the range of a nested document
reference.</p>
<eg xml:space="preserve">    &lt;xs:element name="keyref"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:complexContent&gt;
          &lt;xs:extension base="sml:keybase"&gt;
            &lt;xs:attribute name="refer" type="xs:QName" use="required"/&gt;
          &lt;/xs:extension&gt;
        &lt;/xs:complexContent&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;&gt;</eg>

<p>

<code>sml:keyref</code> is supported in the
<code>appinfo</code> of an <code>xs:element</code>.
 </p>

</div3>
<div3 id="sml_unique">
<head>sml:unique</head>

<p>This element is used to specify a uniqueness constraint in some scope. The
semantics are essentially the same as that for <code>xs:unique</code> but
<code>sml:unique</code> can also be used to specify uniqueness constraints on
other documents, i.e., the  <code>sml:selector</code> child element of
<code>sml:unique</code> can contain <code>deref</code> functions to resolve
elements in another document.</p>
<eg xml:space="preserve">&lt;xs:element name="unique" type="sml:keybase"/&gt;</eg>

<p>

<code>sml:unique</code> is supported in the
<code>appinfo</code> of an <code>xs:element</code>.
 </p>

</div3>
<div3 id="sml_uri">
<head>sml:uri</head>

<p>Specifies a reference in URI scheme. </p>
<eg xml:space="preserve">&lt;xs:element name="uri" type="xs:anyURI"/&gt;</eg>

<p>This element must be used to specify references that use the
URI scheme.</p>
</div3>
</div2>
<div2 id="XPath_functions">
<head>XPath functions</head>

<div3 id="smlfn_deref">
<head>smlfn:deref</head>
<eg xml:space="preserve">node-set deref(node-set)</eg>

<p>This function takes a node-set of elements and attempts to resolve the
references contained in the elements that have
<code>sml:ref="true".</code>    The resulting node-set is the set of
elements that are obtained by successfully resolving (or de-referencing) the
 reference contained in each element in the input node-set for which
<code>sml:ref="true".</code>  For example,</p>
<eg xml:space="preserve">deref(/u:Universities/u:Students/u:Student)</eg>

<p>will resolve the reference in element
<code>Student</code>. The target of the reference must
always be an element.</p>
</div3>
</div2>
</div1>
<div1 id="bibl">
  <head>References</head>
    <div2 id="Normative-References">
        <head>Normative References</head>

	<blist>
	    <bibl key="IETF RFC 2119" href="http://www.ietf.org/rfc/rfc2119.txt" id="RFC2119" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Key words for use in RFCs to Indicate
	    Requirement Levels</titleref>, S. Bradner, Author. Internet
	    Engineering Task Force, June 1999. Available at
	    http://www.ietf.org/rfc/rfc2119.txt.
	  </bibl>
	    <bibl key="IETF RFC 3986" href="http://www.ietf.org/rfc/rfc3986.txt" id="RFC3986" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	        <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Uniform Resource Identifier (URI): Generic Syntax
	        </titleref>, T. Berners-Lee, R. Fielding and L. Masinter,
	        Authors. Network Working Group,
	        January 2005. Available at
	        http://www.ietf.org/rfc/rfc3986.txt.
	    </bibl>

	  <bibl key="ISO/IEC 19757-3" id="Schematron" href="http://standards.iso.org/ittf/PubliclyAvailableStandards/c040833_ISO_IEC_19757-3_2006(E).zip" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Information technology ― Document Schema
	    Definition Languages (DSDL) ― Part 3: Rule-based
	    validation ― Schematron</titleref>. International
	    Organization for Standardization and International
	    Electrotechnical Commission, 1 January 2006. Available at
	    http://standards.iso.org/ittf/PubliclyAvailableStandards/c040833_ISO_IEC_19757-3_2006(E).zip
	  </bibl>
	  <bibl key="WS-Addressing Core" id="WSADDR-CORE" href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Web Services Addressing 1.0 - Core</titleref>,
	    M. Gudgin, M. Hadley, and T. Rogers, Editors. World Wide
	    Web Consortium, 9 May 2006. This version of the
	    WS-Addressing Core Recommendation is
	    http://www.w3.org/TR/2006/REC-ws-addr-core-20060509. The
	    <loc href="http://www.w3.org/TR/ws-addr-core" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
	    version of WS-Addressing Core</loc> is available at
	    http://www.w3.org/TR/ws-addr-core.
	  </bibl>
	  <bibl id="XML10" key="XML 1.0" href="http://www.w3.org/TR/2006/REC-xml-20060816" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Extensible Markup Language (XML) 1.0 (Fourth
	    Edition)</titleref>, T.  Bray, J. Paoli,
	    C. M. Sperberg-McQueen, and E. Maler, Editors. World Wide
	    Web Consortium, 10 February 1998, revised 16 August 2006. This version of the XML
	    1.0 Recommendation is
	    http://www.w3.org/TR/2006/REC-xml-20060816. The <loc href="http://www.w3.org/TR/REC-xml/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest version of XML
	    1.0</loc> is available at http://www.w3.org/TR/REC-xml.
	  </bibl>
	  <bibl id="XSD1" key="XML Schema Structures" href="http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XML Schema Part 1: Structures Second
	    Edition</titleref>, H. Thompson, D. Beech, M. Maloney, and
	    N. Mendelsohn, Editors. World Wide Web Consortium, 2 May
	    2001, revised 28 October 2004. This version of the XML
	    Schema Part 1 Recommendation is
	    http://www.w3.org/TR/2004/REC-xmlschema-1-20041028. The
	    <loc href="http://www.w3.org/TR/xmlschema-1/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
	    version of XML Schema Part 1</loc> is available at
	    http://www.w3.org/TR/xmlschema-1.
	  </bibl>

	  <bibl key="XML Schema Datatypes" id="XSD2" href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XML Schema Part 2: Datatypes Second
	    Edition</titleref>, P. Byron and A. Malhotra,
	    Editors. World Wide Web Consortium, 2 May 2001, revised 28
	    October 2004. This version of the XML Schema Part 2
	    Recommendation is
	    http://www.w3.org/TR/2004/REC-xmlschema-2-20041028. The
	    <loc href="http://www.w3.org/TR/xmlschema-2/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
	    version of XML Schema Part 2</loc> is available at
	    http://www.w3.org/TR/xmlschema-2.
	  </bibl>
	  <bibl key="XPath 1.0" id="XPath" href="http://www.w3.org/TR/1999/REC-xpath-19991116" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XML Path Language (XPath) Version
	    1.0</titleref>, J. Clark and S. DeRose, Editors. World
	    Wide Web Consortium, 16 November 1999. This version of XML
	    Path Language (XPath) Version 1.0 is
	    http://www.w3.org/TR/1999/REC-xpath-19991116. The
	    <loc href="http://www.w3.org/TR/xpath" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest version of
	    XML Path Language (XPath) Version 1.0</loc> is available
	    at http://www.w3.org/TR/xpath.
	  </bibl>
         <bibl key="XPointer" href="http://www.w3.org/TR/2003/REC-xptr-framework-20030325/" id="XPTR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
            <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XPointer Framework</titleref>, P. Grosso, E.
            Maler, J. Marsh, and N. Walsh, Editors. World Wide Web
            Consortium, 25 March 2003.  This version of the XPointer
            Framework Recommendation is
            http://www.w3.org/TR/2003/REC-xptr-framework-20030325/ The
            <loc href="http://www.w3.org/TR/xptr-framework/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
            version of XPointer Framework</loc> is available at
            http://www.w3.org/TR/xptr-framework/.
          </bibl>
         <bibl key="xmlns() Scheme" href="http://www.w3.org/TR/2003/REC-xptr-xmlns-20030325/" id="XPTR-xmlns" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
            <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XPointer xmlns() Scheme</titleref>, S. DeRose,
            R. Daniel Jr., E.  Maler, and J. Marsh, Editors. World
            Wide Web Consortium, 25 March 2003.  This version of the
            XPointer xmlns() Scheme Recommendation is
            http://www.w3.org/TR/2003/REC-xptr-framework-20030325/ The
            <loc href="http://www.w3.org/TR/xptr-xmlns/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
            version of XPointer xmlns() Scheme</loc> is available at
            http://www.w3.org/TR/xptr-xmlns/.
          </bibl>
	  <bibl key="xpointer() Scheme" href="http://www.w3.org/TR/2002/WD-xptr-xpointer-20021219/" id="XPTR-xpointer" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XPointer xpointer() Scheme</titleref>,
	    S. DeRose, E.  Maler, and R. Daniel Jr., Editors. World
	    Wide Web Consortium, 19 December 2002.  This version of
	    the XPointer xpointer() Scheme specification is
	    http://www.w3.org/TR/2002/WD-xptr-xpointer-20021219/. The
	    <loc href="http://www.w3.org/TR/xptr-xpointer/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
	    version of XPointer xpointer() Scheme</loc> is available
	    at http://www.w3.org/TR/xptr-xpointer/.
	  </bibl>
	</blist>

    </div2>

    <div2 id="Informative-References">
        <head>Informative References</head>

	<blist>
	  <bibl key="Introduction to Schematron" id="intro_schematron" href="http://www.xml.com/pub/a/2003/11/12/schematron.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">An Introduction to Schematron</titleref>, Eddie
	    Robertsson, Author.  O'Reilly Media, Inc., 12 November
	    2003. Available at
	    http://www.xml.com/pub/a/2003/11/12/schematron.html
	  </bibl>
	  <bibl key="Improving Validation with      Schematron" id="improving_schematron" href="http://msdn2.microsoft.com/en-us/library/Aa468554.aspx" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Improving XML Document Validation with
	    Schematron</titleref>, Dare Obasanjo, Author. Microsoft
	    Corporation, September 2004. Available at
	    http://msdn2.microsoft.com/en-us/library/Aa468554.aspx
	  </bibl>
	  <bibl id="XSD0" key="XML Schema Primer" href="http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
	    <titleref xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XML Schema Part 0: Primer Second
	    Edition</titleref>, D. Fallside and P. Walmsley,
	    Editors. World Wide Web Consortium, 2 May 2001, revised 28
	    October 2004. This version of the XML Schema Part 0
	    Recommendation is
	    http://www.w3.org/TR/2004/REC-xmlschema-0-20041028. The
	    <loc href="http://www.w3.org/TR/xmlschema-0/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest
	    version of XML Schema Part 0</loc> is available at
	    http://www.w3.org/TR/xmlschema-0.
	  </bibl>
	</blist>
    </div2>
  </div1>
</body>
    <back>
      <div1 id="Appendix1">
	<head>Normative SML Schema</head>
<eg xml:space="preserve">&lt;?xml version="1.0" encoding="utf-8"?&gt;&#xD;
&#xD;
&lt;!--
/*
 * Copyright © 2007 World Wide Web Consortium,
 *
 * (Massachusetts Institute of Technology, European Research Consortium for
 * Informatics and Mathematics, Keio University). All Rights Reserved. This
 * work is distributed under the W3C® Document License [1] in the hope that
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231
 */
--&gt;&#xD;
&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sml="http://www.w3.org/2007/08/sml" targetNamespace="http://www.w3.org/2007/08/sml" elementFormDefault="qualified" blockDefault="#all" version="1.0" xml:lang="en" finalDefault="" attributeFormDefault="unqualified"&gt;&#xD;
  &#xD;
   &lt;!--
      References
      ==========
  --&gt;&#xD;
   &#xD;
  &lt;xs:complexType name="refType" sml:acyclic="false" mixed="false"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	A complex type representing a reference to an element&#xD;
	in the same or a different document. No specific scheme is  &#xD;
	mandated for references; an implementation is free to&#xD;
	choose an appropriate scheme such as URI, EPR, etc.&#xD;
	The target of the reference must unambigously identify a&#xD;
	single element.&#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
    &lt;xs:attribute ref="sml:ref" use="required" fixed="true"/&gt;&#xD;
    &lt;xs:anyAttribute namespace="##any" processContents="lax"/&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
  &#xD;
   &lt;!-- CONTEXT: To be used in &lt;xs:element&gt; --&gt;&#xD;
   &#xD;
  &lt;xs:attribute name="ref" type="xs:boolean"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	Specifies if the element contains a reference&#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:attribute&gt;&#xD;
  &#xD;
   &lt;!-- CONTEXT: To be used in &lt;xs:element&gt; where type="sml:refType"--&gt;&#xD;
   &#xD;
  &lt;xs:attribute name="targetElement" type="xs:QName"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	A qualified name of an element in the&#xD;
	referenced document.&#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:attribute&gt;&#xD;
  &#xD;
   &lt;!-- CONTEXT: To be used in &lt;xs:element&gt; where type="sml:refType"--&gt;&#xD;
   &#xD;
  &lt;xs:attribute name="targetRequired" type="xs:boolean"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	If true, requires the target element of the reference to&#xD;
	exist in the model.&#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:attribute&gt;&#xD;
  &#xD;
   &lt;!-- CONTEXT: To be used in &lt;xs:element&gt; where type="sml:refType"--&gt;&#xD;
   &#xD;
  &lt;xs:attribute name="targetType" type="xs:QName"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	A qualified name of the type of the element in the&#xD;
	referenced document.&#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:attribute&gt;&#xD;
  &#xD;
   &lt;!-- CONTEXT: To be used in sml:refType and its derived types--&gt;&#xD;
   &#xD;
  &lt;xs:attribute name="acyclic" type="xs:boolean"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	If this attribute is set to true for a derived type D of&#xD;
	sml:refType, then instances of D should not create any&#xD;
	cycles in a model. More precisely, the directed graph whose&#xD;
	edges represent instances of D, and whose nodes represent&#xD;
	documents that contain the source or target elements for&#xD;
	instances of D, must be acyclic.&#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:attribute&gt;&#xD;
  &#xD;
   &lt;!-- CONTEXT: Represents a reference using the URI scheme. To be
       used as a child  element of elements for which
       sml:ref="true". --&gt;&#xD;
   &#xD;
  &lt;xs:element name="uri" type="xs:anyURI"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:documentation&gt;&#xD;
	References in URI scheme must be representend by this&#xD;
	element.  &#xD;
      &lt;/xs:documentation&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:element&gt;&#xD;
&#xD;
  &#xD;
   &lt;!--
      Uniqueness and Key constraints
      ==============================
  --&gt;&#xD;
   &#xD;
&#xD;
  &lt;xs:complexType name="keybase" mixed="false"&gt;&#xD;
    &lt;xs:sequence minOccurs="0"&gt;&#xD;
      &lt;xs:element name="selector" type="sml:selectorXPathType"/&gt;&#xD;
      &lt;xs:element name="field" type="sml:fieldXPathType" maxOccurs="unbounded"/&gt;&#xD;
      &lt;xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
    &lt;xs:attribute name="name" type="xs:NCName"/&gt;&#xD;
    &lt;xs:attribute name="ref" type="xs:QName"/&gt;&#xD;
    &lt;xs:anyAttribute namespace="##other" processContents="lax"/&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
  &lt;xs:element name="key" type="sml:keybase"/&gt;&#xD;
  &lt;xs:element name="unique" type="sml:keybase"/&gt;&#xD;
  &lt;xs:element name="keyref"&gt;&#xD;
    &lt;xs:complexType mixed="false"&gt;&#xD;
      &lt;xs:complexContent&gt;&#xD;
	&lt;xs:extension base="sml:keybase"&gt;&#xD;
	  &lt;xs:attribute name="refer" type="xs:QName" use="required"/&gt;&#xD;
	&lt;/xs:extension&gt;&#xD;
      &lt;/xs:complexContent&gt;&#xD;
    &lt;/xs:complexType&gt;&#xD;
  &lt;/xs:element&gt;&#xD;
&#xD;
  &#xD;
   &lt;!--
      Other Complex Types
      ==================
  --&gt;&#xD;
   &#xD;
&#xD;
  &lt;xs:complexType name="selectorXPathType" mixed="false"&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
    &lt;xs:attribute name="xpath" use="required"&gt;&#xD;
      &lt;xs:simpleType&gt;&#xD;
	&lt;xs:restriction base="xs:string"&gt;&#xD;
	  &#xD;
   &lt;!-- TODO: add a pattern facet for selector xpath --&gt;&#xD;
   &#xD;
	&lt;/xs:restriction&gt;&#xD;
      &lt;/xs:simpleType&gt;&#xD;
    &lt;/xs:attribute&gt;&#xD;
    &lt;xs:anyAttribute namespace="##other" processContents="lax"/&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&#xD;
  &lt;xs:complexType name="fieldXPathType" mixed="false"&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
    &lt;xs:attribute name="xpath" use="required"&gt;&#xD;
      &lt;xs:simpleType&gt;&#xD;
	&lt;xs:restriction base="xs:string"&gt;&#xD;
	  &#xD;
   &lt;!-- TODO: add a pattern facet for field xpath --&gt;&#xD;
   &#xD;
	&lt;/xs:restriction&gt;&#xD;
      &lt;/xs:simpleType&gt;&#xD;
    &lt;/xs:attribute&gt;&#xD;
    &lt;xs:anyAttribute namespace="##other" processContents="lax"/&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&lt;/xs:schema&gt;&#xD;
</eg>
      </div1>
      <div1 id="Appendix2">
	<head>Normative SML Error Schema</head>
<eg xml:space="preserve">&lt;?xml version="1.0" encoding="utf-8"?&gt;&#xD;
&#xD;
&lt;!--
/*
 * Copyright © 2007 World Wide Web Consortium,
 *
 * (Massachusetts Institute of Technology, European Research Consortium for
 * Informatics and Mathematics, Keio University). All Rights Reserved. This
 * work is distributed under the W3C® Document License [1] in the hope that
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231
 */
--&gt;&#xD;
&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:smlerr="http://www.w3.org/2007/08/sml-err" targetNamespace="http://www.w3.org/2007/08/sml-err" elementFormDefault="qualified" blockDefault="#all" version="1.0" xml:lang="en" finalDefault="" attributeFormDefault="unqualified"&gt;&#xD;
&#xD;
  &lt;xs:element name="errorData" type="smlerr:errorDataType"/&gt;&#xD;
  &lt;xs:element name="output" type="smlerr:outputType"/&gt;&#xD;
  &lt;xs:element name="attributeNode" type="smlerr:attributeNodeType"/&gt;&#xD;
&#xD;
  &lt;xs:attribute name="outputids" type="xs:IDREFS"/&gt;&#xD;
  &lt;xs:attribute name="localizationid" type="xs:anyURI"/&gt;&#xD;
&#xD;
  &lt;xs:complexType name="outputType" mixed="false"&gt;&#xD;
    &lt;xs:attribute name="id" type="xs:ID" use="required"/&gt;&#xD;
    &lt;xs:attribute name="applicationUri" type="xs:anyURI"/&gt;&#xD;
    &lt;xs:attribute name="expression" type="xs:string" use="required"/&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&#xD;
  &lt;xs:complexType name="attributeNodeType" mixed="false"&gt;&#xD;
    &lt;xs:simpleContent&gt;&#xD;
      &lt;xs:extension base="xs:string"&gt;&#xD;
	&lt;xs:attribute name="name" type="xs:QName"/&gt;&#xD;
      &lt;/xs:extension&gt;&#xD;
    &lt;/xs:simpleContent&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&#xD;
  &lt;xs:complexType name="errorDataType" mixed="false"&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:any namespace="##any" maxOccurs="unbounded" processContents="skip" minOccurs="1"/&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&lt;/xs:schema&gt;&#xD;
</eg>
      </div1>
      <inform-div1 id="Appendix3">
	<head>Sample Model</head>

<p>This sample model illustrates the use of the following SML extensions:</p>
<ulist>
  <item>
<p>Inter-document references</p>
  </item>
  <item>
                    <p>
<code>key</code> and <code>keyref</code> constraints</p>
  </item>
  <item>
<p>User-defined constraints</p>
  </item>
</ulist>
<eg xml:space="preserve">&lt;?xml version="1.0" encoding="utf-8"?&gt;&#xD;
&#xD;
&lt;!--
/*
 * Copyright ©  World Wide Web Consortium,
 *
 * (Massachusetts Institute of Technology, European Research Consortium for
 * Informatics and Mathematics, Keio University). All Rights Reserved. This
 * work is distributed under the W3C® Document License [1] in the hope that
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231
 */
--&gt;&#xD;
&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.org/SampleModel" xmlns:sml="http://www.w3.org/2007/08/sml" xmlns:smlfn="http://www.w3.org/2007/08/sml-function" xmlns:sch="http://purl.oclc.org/dsdl/schematron" targetNamespace="http://example.org/SampleModel" elementFormDefault="qualified" finalDefault="" blockDefault="" attributeFormDefault="unqualified"&gt;&#xD;
&#xD;
  &lt;xs:import namespace="http://www.w3.org/2007/08/sml"/&gt;&#xD;
&#xD;
  &lt;xs:simpleType name="SecurityLevel"&gt;&#xD;
    &lt;xs:restriction base="xs:string"&gt;&#xD;
      &lt;xs:enumeration value="Low"/&gt;&#xD;
      &lt;xs:enumeration value="Medium"/&gt;&#xD;
      &lt;xs:enumeration value="High"/&gt;&#xD;
    &lt;/xs:restriction&gt;&#xD;
  &lt;/xs:simpleType&gt;&#xD;
&#xD;
  &lt;xs:complexType name="Hostref" sml:acyclic="true" mixed="false"&gt;&#xD;
    &lt;xs:complexContent&gt;&#xD;
      &lt;xs:restriction base="sml:refType"/&gt;&#xD;
    &lt;/xs:complexContent&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&#xD;
  &#xD;
   &lt;!-- This element represents the host operating system for
       an application. Note that the type of the referenced
       element must be OperatingSystemType or a derived type
       of OperatingSystemType --&gt;&#xD;
   &#xD;
  &lt;xs:element name="HostOSRef" type="tns:Hostref" sml:targetType="tns:OperatingSystemType"/&gt;&#xD;
&#xD;
  &lt;xs:complexType name="ApplicationType" mixed="false"&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:element name="Name" type="xs:string"/&gt;&#xD;
      &lt;xs:element name="Vendor" type="xs:string"/&gt;&#xD;
      &lt;xs:element name="Version" type="xs:string"/&gt;&#xD;
      &lt;xs:element ref="tns:HostOSRef" minOccurs="0"/&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
  &lt;/xs:complexType&gt; &#xD;
&#xD;
  &lt;xs:simpleType name="ProtocolType"&gt;&#xD;
    &lt;xs:list&gt;&#xD;
      &lt;xs:simpleType&gt;&#xD;
	&lt;xs:restriction base="xs:string"&gt;&#xD;
	  &lt;xs:enumeration value="TCP"/&gt;&#xD;
	  &lt;xs:enumeration value="UDP"/&gt;&#xD;
	  &lt;xs:enumeration value="SMTP"/&gt;&#xD;
	  &lt;xs:enumeration value="SNMP"/&gt;&#xD;
	&lt;/xs:restriction&gt;&#xD;
      &lt;/xs:simpleType&gt;&#xD;
    &lt;/xs:list&gt;&#xD;
  &lt;/xs:simpleType&gt;&#xD;
&#xD;
  &lt;xs:element name="GuestAppRef" type="sml:refType" sml:targetType="tns:ApplicationType"/&gt;&#xD;
&#xD;
  &lt;xs:complexType name="OperatingSystemType" mixed="false"&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:element name="Name" type="xs:string"/&gt;&#xD;
      &lt;xs:element name="FirewallEnabled" type="xs:boolean"/&gt;&#xD;
      &lt;xs:element name="Protocol" type="tns:ProtocolType"/&gt;&#xD;
      &#xD;
   &lt;!-- The following element represents the applications hosted by
	   operating system --&gt;&#xD;
   &#xD;
      &lt;xs:element name="Applications" minOccurs="0"&gt;&#xD;
	&lt;xs:complexType mixed="false"&gt;&#xD;
	  &lt;xs:sequence&gt;&#xD;
	    &lt;xs:element ref="tns:GuestAppRef" maxOccurs="unbounded"/&gt;&#xD;
	  &lt;/xs:sequence&gt;&#xD;
	&lt;/xs:complexType&gt;&#xD;
      &lt;/xs:element&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
  &lt;/xs:complexType&gt;&#xD;
&#xD;
  &lt;xs:element name="OSRef" type="sml:refType" sml:targetType="tns:OperatingSystemType"/&gt;&#xD;
&#xD;
  &lt;xs:complexType name="WorkstationType" mixed="false"&gt;&#xD;
    &lt;xs:sequence&gt;&#xD;
      &lt;xs:element name="Name" type="xs:string"/&gt;&#xD;
      &lt;xs:element ref="tns:OSRef"/&gt;&#xD;
      &lt;xs:element name="Applications" minOccurs="0"&gt;&#xD;
	&lt;xs:complexType mixed="false"&gt;&#xD;
	  &lt;xs:sequence&gt;&#xD;
	    &lt;xs:element ref="tns:GuestAppRef" maxOccurs="unbounded"/&gt;&#xD;
	  &lt;/xs:sequence&gt;&#xD;
	&lt;/xs:complexType&gt;&#xD;
      &lt;/xs:element&gt;&#xD;
    &lt;/xs:sequence&gt;&#xD;
  &lt;/xs:complexType&gt; &#xD;
&#xD;
  &lt;xs:element name="Workstation" type="tns:WorkstationType"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:appinfo&gt;&#xD;
	&lt;sch:schema&gt;&#xD;
	  &lt;sch:ns prefix="sm" uri="SampleModel"/&gt;&#xD;
	  &lt;sch:ns prefix="smlfn" uri="http://www.w3.org/2007/08/sml-function"/&gt;&#xD;
	  &lt;sch:pattern id="OneHostOS"&gt;&#xD;
	    &#xD;
   &lt;!-- The constraints in the following rule are evaluated  
		 For all instances of the Workstation global element--&gt;&#xD;
   &#xD;
	    &lt;sch:rule context="."&gt;&#xD;
	      &#xD;
   &lt;!-- define a named variable - MyApplications -
		   for use in test expression--&gt;&#xD;
   &#xD;
	      &lt;sch:let name="MyApplications" value="smlfn:deref(sm:Applications/sm:GuestAppRef)"/&gt;&#xD;
	      &lt;sch:assert test="count($MyApplications)=count($MyApplications/sm:HostOSRef)"&gt;&#xD;
		Each application in workstation&#xD;
		&lt;sch:value-of select="string(sm:Name)"/&gt;&#xD;
		must be hosted on an operating system&#xD;
	      &lt;/sch:assert&gt;&#xD;
	    &lt;/sch:rule&gt;&#xD;
	  &lt;/sch:pattern&gt;&#xD;
	&lt;/sch:schema&gt;&#xD;
&#xD;
	&#xD;
   &lt;!-- In a workstation, (Vendor,Name,Version) is the key for
	     guest applications --&gt;&#xD;
   &#xD;
	&lt;sml:key name="GuestApplicationKey"&gt;&#xD;
	  &lt;sml:selector xpath="smlfn:deref(tns:Applications/tns:GuestAppRef)"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Vendor"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Name"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Version"/&gt;&#xD;
	&lt;/sml:key&gt;&#xD;
&#xD;
	&#xD;
   &lt;!-- In a workstation, Name is the key for operating system --&gt;&#xD;
   &#xD;
	&lt;sml:key name="OSKey"&gt;&#xD;
	  &lt;sml:selector xpath="smlfn:deref(tns:OSRef)"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Name"/&gt;&#xD;
	&lt;/sml:key&gt;&#xD;
	&#xD;
	&#xD;
   &lt;!-- In a workstation, the applications hosted by the
	     referenced operatinsystem must be a subset of the
	     applications in the workstation --&gt;&#xD;
   &#xD;
	&lt;sml:keyref name="OSGuestApplication" refer="tns:GuestApplicationKey"&gt;&#xD;
	  &lt;sml:selector xpath="smlfn:deref(tns:OSRef)/tns:Applications/tns:GuestAppRef"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Vendor"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Name"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Version"/&gt;   &#xD;
	&lt;/sml:keyref&gt;&#xD;
&#xD;
	&#xD;
   &lt;!-- In a workstation, the host operating system of guest
	     applications must be a subset of the operating system in
	     the workstation --&gt;&#xD;
   &#xD;
	&lt;sml:keyref name="ApplicationHostOS" refer="tns:OSKey"&gt;&#xD;
	  &lt;sml:selector xpath="smlfn:deref(tns:Applications/tns:GuestAppRef)/tns:HostOSRef"/&gt;&#xD;
	  &lt;sml:field xpath="tns:Name"/&gt;&#xD;
	&lt;/sml:keyref&gt;&#xD;
      &lt;/xs:appinfo&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:element&gt;&#xD;
&#xD;
  &lt;xs:element name="SecureWorkstation" type="tns:WorkstationType"&gt;&#xD;
    &lt;xs:annotation&gt;&#xD;
      &lt;xs:appinfo&gt;&#xD;
	&lt;sch:schema&gt;&#xD;
	  &lt;sch:ns prefix="sm" uri="SampleModel"/&gt;&#xD;
	  &lt;sch:ns prefix="smlfn" uri="http://www.w3.org/2007/08/sml-function"/&gt;&#xD;
	  &lt;sch:pattern id="SecureApplication"&gt;&#xD;
	    &lt;sch:rule context="smlfn:deref(sm:Applications/sm:Application)"&gt;&#xD;
	      &lt;sch:report test="sm:SecurityLevel!='High'"&gt;&#xD;
		Application &lt;sch:value-of select="string(sm:Name)"/&gt;&#xD;
		from &lt;sch:value-of select="string(sm:Vendor)"/&gt;&#xD;
		does not have high security level&#xD;
	      &lt;/sch:report&gt;&#xD;
	      &lt;sch:assert test="sm:Vendor='TrustedVendor'"&gt;&#xD;
		A secure workstation can only contain&#xD;
		applications from TrustedVendor&#xD;
	      &lt;/sch:assert&gt;&#xD;
	    &lt;/sch:rule&gt;&#xD;
	  &lt;/sch:pattern&gt;&#xD;
	&lt;/sch:schema&gt;&#xD;
      &lt;/xs:appinfo&gt;&#xD;
    &lt;/xs:annotation&gt;&#xD;
  &lt;/xs:element&gt;&#xD;
&#xD;
&lt;/xs:schema&gt;&#xD;
</eg>
      </inform-div1>
<inform-div1 id="Acknowledgements">
<head>Acknowledgements</head>

<p>The editors acknowledge the members of the Service Modeling Language Working
Group, the members of other W3C Working Groups, and industry experts
in other forums who have contributed directly or indirectly to the
process or content of creating this document.</p>
<p>At the time this specification was published, the members of the
Service Modeling Language Working Group were:</p>

<p>John Arwe (IBM Corporation), Jordan Boucher (Sun Microsystems, Inc.), Pratul Dublish (Microsoft Corporation), Zulah Eckert (BEA Systems, Inc.), Sandy Gao (IBM Corporation), Heather Kreger (IBM Corporation), Philippe Le Hégaret (W3C/MIT), Paul Lipton (CA), James Lynn (HP), Kumar Pandit (Microsoft Corporation), Valentina Popescu (IBM Corporation), Virginia Smith (HP), Michael Sperberg-McQueen (W3C/MIT), Bassam Tabbara (Microsoft Corporation), Vijay Tewari (Intel Corporation), Marvin Waschke (CA), Kirk Wilson (CA), Brian You (IBM Corporation).</p>

</inform-div1>

    </back>
</spec>