<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xmlspec.xsl"?>
<spec w3c-doctype="cr">
	<header>
		<title>CLiX Language Specification</title>
		<version>Version 1.0</version>
		<w3c-designation/>
		<w3c-doctype>Specification,</w3c-doctype>
		<pubdate>
			<day>31</day>
			<month>January</month>
			<year>2004</year>
		</pubdate>
		<publoc>
			<loc href="http://www.clixml.org/spec/clix/clix-rc-1.0.xml">http://www.clixml.org/clix/1.0/clix-rc-1.0.xml</loc>
		</publoc>
		<latestloc>
			<loc href="http://www.clixml.org/spec/clix/clix.xml">http://www.clixml.org/clix/1.0/clix.xml</loc>
		</latestloc>
		<authlist>
			<author role="editor">
				<name>Michael Marconi</name>
				<affiliation>Systemwire</affiliation>
			</author>
			<author role="author">
				<name>Christian Nentwich</name>
				<affiliation>Systemwire</affiliation>
			</author>
		</authlist>
		<copyright>
			<p>Copyright &#xa9; 2002-2004 authors and contributors. All rights reserved.</p>
		</copyright>
		<status>
			<p>This document is the first release of the CLiX constraint language specification. It is not a generic user manual. The intended
	    audience of this document are developers that wish to implement CLiX and users that wish to look up specific details of
	    the language.
	  </p>
		</status>
		<abstract>
			CLiX is the Constraint Language in XML. It is based on first order logic and XPath, and its purpose is to enable the specification
	  		of constraints on the structure and content of XML documents. The goal of CLiX is to enable users and developers to 
	  		express business properties and complex constraints that cannot be handled in traditional schema languages, and to 
	  		automate checks that would otherwise have to be hardcoded.
		</abstract>
		<langusage>
			<language id="EN">English</language>
			<language id="ebnf">EBNF</language>
		</langusage>
		<revisiondesc>
			<p>?</p>
		</revisiondesc>
		<?GENERATE-TOC?>
	</header>
	<body>
		<div1 id="introduction">
			<head>Introduction</head>
			<p>
	      CLiX is a constraint language for XML. It is based on first order logic and <bibref ref="XPATH"/> and 
	      enables the expression of constraints that make assertions about the content of documents. Elements in documents
	      that do not meet these assertions violate the constraints.
	    </p>
			<p>
	      CLiX is on a different level from traditional schema languages like
	      <bibref ref="XMLSCHEMA"/> or <bibref ref="RELAXNG"/>. These languages are intended to specify the structure of XML
	      documents. CLiX constraints assume that the basic structure is already in place and add additional restrictions. CLiX is
	      thus complementary to schema validation and may be applied as an additional step in a validation pipeline.
	    </p>
			<p>
	      Some similarities exist between CLiX and <bibref ref="SCHEMATRON"/>, since both languages are assertion languages, and
	      both are path based. Historically, CLiX had been developed slightly before Schematron, but was the result of research
	      at University College London, and hence had not been as widely distributed as the Schematron community effrot.
	      CLiX differs from Schematron in its degree of expressiveness: first order logic is more expressive than boolean logic,
	      and many constraints where Schematron requires scripting can be handled natively in CLiX. 
	    </p>
		</div1>
		<div1 id="overview">
			<head>Overview</head>
			<p>
	  		  The remainder of this document specifies the CLiX language. This document is <emph>normative</emph>: conforming CLiX 
		    implementations must implement the language semantics specified in this document.
		  </p>
			<p>
		    This specification introduces rule files that contain a list of rules which are fed into a CLiX processor as input.
		    The result of applying the rules to specified documents is not formally specified at this point and is
		  	  left to the implementation, although the <el>clix:report</el> element can be used to associate diagnostic messages with each
		    constraint.
		  </p>
			<p>
	    		The specification begins by defining a generic metadata mechanism that is used to attach authorship and other information
	    		to CLiX rules.
		  </p>
		</div1>
		<div1 id="namespaces">
			<head>Namespaces</head>
			<p>
		    CLiX language elements are associated with the namespace URI <code>http://www.clixml.org/clix/1.0</code>. In the remainder
		    of the specification, the namespace prefix <code>clix</code> will be used to refer to this namespace, as in 
		    <code>clix:rules</code>.
		  </p>
			<p>
		  	Macro invocation is performed using the macro namespace, <code>http://www.clixml.org/clix/1.0/Macro</code>. We will use
		  	the prefix <code>macro</code> to refer to this namespace.
		  </p>
		</div1>
		<!-- Header -->
		<div1 id="header">
			<head>Header</head>
			<p>
	      The purpose of the header elements is to enable the specification of documentation
	      and authorship information for structures, such as rules or macros, in the language. 
	      They effectively provide a simple way of attaching meta-data to these artefacts. Since they are
	      reusable, they are defined here separately.
	    </p>
			<div2>
				<head>Header Schema</head>
				<graphic source="images/header.png"/>
			</div2>
			<p>
				<kw>clix:header</kw>
				<eg id="clix-header"><![CDATA[
<clix:header>
  <!-- Content: (clix:author | clix:comment | clix:description | *)* -->
</clix:header>
]]></eg>
			</p>
			<p>
				<el>clix:header</el> is the containg elements for the header information. The 
		      header can contain a number of fixed CLiX elements, plus elements from other
		      namespaces that can contain arbitrary markup.
	    </p>
			<p>
				<kw>clix:author</kw>
				<eg id="author"><![CDATA[
<!-- Category: header-elements -->
<clix:author>
  <!-- Content: #PCDATA -->
</clix:author>
]]></eg>
			</p>
			<p>
				Author information can be attached using the <el>clix:author</el> element. Since the header content
				model allows multiple occurences of elements, multiple authors can be defined.
			</p>
			<p>
				<kw>clix:comment</kw>
				<eg id="comment"><![CDATA[
<!-- Category: header-elements -->
<clix:comment>
  <!-- Content: #PCDATA -->
</clix:comment>
]]></eg>
			</p>
			<p>
				The <el>clix:comment</el> element is intended to add additional information to CLiX elements, supplementing the
				description. While the description provides a functional overview, the comment is intended as a means for providing
				background information.
			</p>
			<p>
				<kw>clix:description</kw>
				<eg id="description"><![CDATA[
<!-- Category: header-elements -->
<clix:description>
  <!-- Content: (xhtml:* | #PCDATA)* -->
</clix:description>
]]></eg>
			</p>
			<p>
				The <el>clix:description</el> element provides a functional description of the element that it is attached to. It can
				contain text and elements from the XHTML namespace. This facilitates the production of documentation from description
				elements using stylesheets.
			</p>
			<p>
				<kw>*</kw>
           Any element from other namespaces may be included in the header. The content of such elements is completely
           unconstrained and can be used to attach supporting information that can be processed by tools.
			</p>
			<p>
			        The example below shows a simple header, with the three statically defined fields, plus two custom
			        elements <el>meta:date</el> and <el>meta:version</el>. These elements can be processed as data items
			        by third party applications.
			    </p>
			<example>
				<head>Sample header information</head>
				<p>
					<eg><![CDATA[
<clix:header xmlns:meta="http://www.mycompany.com/clix/metadata/1.0">
    <clix:author>Christian Nentwich</clix:author>
    <clix:description>Some sample header info</clix:description>
    <clix:comment>Just for the spec</clix:comment>
    <meta:date>23-04-2003</meta:date>
    <meta:version>2</meta:version>
</clix:header>             
]]></eg>
				</p>
			</example>
		</div1>
		<!-- Rules Files -->
		<div1 id="rules">
			<head>Rules</head>
			<p>
					All CLiX constraints are contained in <kw>rules files</kw>, which must start with the <el>clix:rules</el>
					element.  This is a top-level element and it must contain one or more <el>clix:rule</el> elements.
				</p>
			<div2 id="rules.schema">
				<head>Rules Schema</head>
				<graphic source="images/rules.png"/>
				<p>
					<kw>clix:rules</kw>
					<eg id="clix-rules"><![CDATA[
<clix:rules>
  	<!-- Content: (clix:macros*,clix:variable*,clix:key*,clix:rule+) -->
</clix:rules>
]]></eg>
				</p>
				<p>
					CLiX constraints are contained in <kw>rule files</kw>, which must start with the <el>clix:rules</el>
					element. Any namespace prefixes bound at the <el>clix:rules</el> elements become available for use in
					path expression in the rule file, as explained in <specref ref="path-namespaces"/>.
				</p>
				<p>
				  Optionally, the <el>clix:rules</el> element can contain <kw>macros</kw>, <kw>variable</kw> and <kw>key</kw> elements:
				</p>
				<p>
					<kw>clix:macros</kw>
					<eg id="clix-macros"><![CDATA[
<clix:macros
   href = URI />
]]></eg>
				</p>
				<p>
					Instructs the CLiX processor to include a macro file for macro processing. This mechanism is left
					unspecified in this version of the spec and will be updated in a minor release.
				</p>
				<p>
					<kw>clix:variable</kw>
					<eg id="clix-variable"><![CDATA[
<clix:variable
   id = cdata 
   xpath = absolute path />
]]></eg>
				</p>
				<p>
					<kw>clix:variable</kw> creates a global variable that all rules in a CLiX file may make use of. The
					<att>id</att> attribute becomes the variable name and <att>xpath</att> is evaluated to become the variable
					value. Since there is no context defined at this point, <att>xpath</att> must be an
					<kw>absolute path</kw>, as defined in <specref ref="pathtypes"/>
				</p>
				<p>
					<kw>clix:key</kw>
					<eg id="clix-key"><![CDATA[
<clix:key
   name = cdata 
   match = absolute path 
   use = relative path />
]]></eg>
				</p>
				<p>
					This creates a key for lookup using the <code>key()</code> function inside a path, in exactly the same 
					way as the <bibref ref="XSLT"/>
					<loc href="http://www.w3.org/TR/xslt#key">key construct</loc>. The
					<att>name</att> attribute is a unique identifier for the key. <att>match</att> must be an absolute path
					as defined in <specref ref="pathtypes"/>, and <att>use</att> must be a path relative to the nodes retrieved
					by evaluating the absolute path.
				</p>
				<p>
					A key defined in such a way can then be accessed using the XPath function <code>key(name, nodeset)</code>,
					which evaluates its second path parameter to a node set and gets all elements from the key for which <att>use</att>
					evaluates to the same value.
				</p>
				<example>
					<head>Key example</head>
					<p>
						Suppose we have the following document:
					</p>
					<p>
						<eg><![CDATA[<restaurant>
  <dinner>
    <dessert>Crepes</dessert>
    <price>2.50</price>
  </dinner>
  <dinner>
    <dessert>Chocolate gateaux</dessert>
    <price>3</price>
  </dinner>
  <favourite>Crepes</favourite>
</restaurant>]]></eg>
					</p>
					<p>
						Then we could define a key over the dinners by dessert names using <code>&lt;clix:key name="dessertKey" match="//dinner" use="dessert"/&gt;</code>. Assuming that we have a variable <code>fav</code> bound to the <el>favourites</el> element, we could check
						the price of our favourite dessert using: <code>&lt;clix:equal op1="key('dessertKey',$fav)/price" op2="2.50"/></code>
					</p>
				</example>
				<p/>
				<example>
					<head>Rules file</head>
					<p>
						This is a more complete example of the structure of a rule file:
					</p>
					<p>
						<eg><![CDATA[
<clix:rules xmlns:clix="http://www.clixml.org/clix/1.0" version="1.0">
    <clix:header>
        <clix:author>Michael Marconi</clix:author>
        <clix:description>A set of rule examples</clix:description>
        <clix:comment>This should help to demonstrate the rules element</clix:comment>
    </clix:header>
    <clix:rule id="rule1">
        ...
    </clix:rule>
    <clix:rule id="rule2">
        ...
    </clix:rule>
</clix:rules>
]]></eg>
					</p>
				</example>
			</div2>
			<div2 id="rule.schema">
				<head>Rule Schema</head>
				<graphic source="images/rule.png"/>
				<p>
					<kw>clix:rule</kw>
					<eg id="clix-rule"><![CDATA[
<clix:rule
  id = ID
  disabled = boolean
  <!-- Content: (clix:header?,clix:report?,formula) -->
</clix:rule>
]]></eg>
				</p>
				<p>
					Every rule has a mandatory <att>id</att> attribute that can be used for referencing. It may
					contain a header that provides information about the rule, as specified in
					<specref ref="header"/>. This is followed by the reporting mechanism (see 
					<specref ref="reporting"/>)and a constraint formula. The constraint formula is represented 
					by one of the formula elements defined in <specref ref="formulae"/>.
          </p>
				<p>
					The rule element may also have an optional <att>disabled</att> attribute whose possible values
					include <code>true</code> and <code>false</code>. If the attribute is set to <code>true</code>,
					CLiX processors should not execute the rule, though they are still allowed to load it.
				</p>
			</div2>
			<div2 id="reporting">
				<head>Reporting</head>
				<p>
                        When a rule is violated, it is important to provide diagnostic feedback to the user or
                        a processing application that is evaluating the rule.  The 
                        <el>clix:report</el> element is used to hold markup and text that will describe how
                        the rule has been violated.
                    </p>
				<p>
					<kw>clix:report</kw>
					<eg id="clix-report"><![CDATA[
<clix:report>
  <!-- Content: any -->
</clix:report>
]]></eg>
				</p>
				<p>
                        The content model of <el>clix:report</el> is completely unrestricted. This means that report
                        messages can contain arbitrary XML markup. They may also make use of XHTML elements, which can be
                        use to generate HTML or XHTML reports depending on the serializer that is attached to the
                        implementation.
                    </p>
			</div2>
			<div2 id="formulae">
				<head>Constraint formulas</head>
				<p>
					Rules in CLiX are based on a fairly simple language that combines first order
					logic with XPath: <term>quantifiers</term> are used to iterate over
					sets of nodes, <term>boolean operators</term> like <code>and</code> and <code>or</code>
					allow the construction of more complex formulae, and <term>predicates</term> like <code>equals</code> 
					and <code>notequals</code> compare sets of nodes to get a result.
					The purpose of this section is to define an XML syntax for this formula language.
				</p>
				<p>
		        Every construct in the language makes use of XPath to retrieve elements from documents for
		        processing. The XPath expressions that can be used to address elements in documents are restricted 
		        depending on the formula type. The next few sections define the permissible types of path expressions.
		    </p>
				<div3 id="path-namespaces">
					<head>Namespace prefixes in paths</head>
					<p>
			    	XPath location steps use prefixes to retrieve elements from certain namespaces. For example, given our
			    	definition of the <code>clix</code> prefix above, <code>/clix:rules/clix:rule</code> would select all
			    	<code>rule</code> elements in the namespace <code>http://www.clixml.org/clix/1.0</code>.
			    </p>
					<p>
			    	When CLiX formulas make use of namespace prefixes in their paths, those prefixes must be bound. CLiX processors
			    	will accept all prefixes bound at the root of the rule file, <code>clix:rules</code> as valid prefixes for
			    	path expressions. The following example shows how to write a rule over elements in a custom namespace,
			    	<code>http://www.mycompany.com/mylanguage</code>:
			    </p>
					<example id="example-path-namespace">
						<head>Example of rule with namespaces</head>
						<p>
							<eg><![CDATA[<clix:rules xmlns:clix="http://www.clixml.org/clix/1.0"
  xmlns:mine="http://www.mycompany.com/mylanguage">

  <clix:rule id="rule-1">
    <clix:forall var="x" in="//mine:elements">
      <clix:equal op1="$x/mine:value" op2="'15'"/>
    </clix:forall>
  </clix:rule>

</clix:rules>]]></eg>
						</p>
					</example>
				</div3>
				<div3 id="pathtypes">
					<head>Absolute Paths, Quantifier Paths and Predicate Paths</head>
					<p>
					  The CLiX formula constructs make use of XPath to select elements from documents. Predicate elements
					  like <el>clix:equal</el> may be relative to variables only, global variables must use
					  absolute path expressions and quantifiers like <el>clix:forall</el> need path expressions that evaluate
					  to node sets, since they are iteration constructs. We will define these three path types below.
					</p>
					<p>
					  An <term>absolute path</term> starts either with a <code>/</code> or a <code>//</code>. If the path is
					  a union, then each path in the union must be absolute itself. For example,
					  <code>/foo/bar</code> is an absolute path and so is <code>/foo | /bar</code>. 
					</p>
					<example>
						<head>Legal absolute paths</head>
						<p>
							<itemizedlist>
								<item>
									<p>
										<code>/foo/bar</code> is an absolute path that selects all elements
                                    <code><![CDATA[<bar>]]></code> contained in <code><![CDATA[<foo>]]></code>.</p>
								</item>
								<item>
									<p>
										<code>/foo/@bar</code> is an absolute path that selects the attribute
                                    <code>bar</code> in all elements <code><![CDATA[<foo>]]></code>.</p>
								</item>
								<item>
									<p>
										<code>/foo/bar/text()</code> is an absolute path that selects all
                                    text nodes in <code><![CDATA[<bar>]]></code>.</p>
								</item>
							</itemizedlist>
						</p>
					</example>
					<p>
						The following examples are all illegal:                        
					</p>
					<example>
						<head>Illegal absolute paths</head>
						<p>
							<itemizedlist>
								<item>
									<p>
										<code>$x/foo</code> is illegal because it is relative to a variable (x).
									</p>
								</item>
								<item>
									<p>
										<code>substring(/foo,1,5)</code> is illegal because, even though the contained path
										is absolute, the expression as a whole does not begin with an absolute path.
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
					<p>
						A <term>quantifier path</term> is either an <term>absolute path</term> or a path expression whose locator paths
						are relative to a variable. In addition, a quantifier path <emph>must</emph> evaluate
						to a node set. This is because these paths are used by <el>clix:forall</el> and <el>clix:exists</el>, which are iteration
						constructs.
					</p>
					<example>
						<head>Legal quantifier paths</head>
						<p>
							<itemizedlist>
								<item>
									<p>
										<code>/foo/bar</code> is legal because is an absolute path and selects a set of <code>bar</code> nodes.
									</p>
								</item>
								<item>
									<p>
										<code>/foo/@att</code> is legal because is an absolute path and selects a set containing the
										<code>att</code> attribute, or an empty set if no such attribute is present.
									</p>
								</item>
								<item>
									<p>
										<code>$x/foo/@bar</code> is legal because it is relative to a variable and selects an attribute node.
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
					<p>
						The following examples are all <emph>illegal</emph>:
					</p>
					<example>
						<head>Illegal quantifier paths</head>
						<p>
							<itemizedlist>
								<item>
									<p>
										<code>foo/bar</code> is legal because is neither absolute, nor relative to a variable. It assumes an
										implied context node.
									</p>
								</item>
								<item>
									<p>
										<code>substring(/foo/@att,1,5)</code> is illegal because it results in a string.
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
					<p>
					  A <term>predicate path</term> is a path expression that may contain only location paths that are relative to
					  variables, or expressions that yield strings, booleans or numbers. It is called a predicate path becaues it 
					  is the only permissible type of path in the CLiX "predicates" like <el>clix:equal</el>. As an example, <code>$x/bar</code> 
					  is a predicate path and so is <code>54</code>. 
					</p>
					<p>
					  Predicate paths are always evaluated to yield a value of type string, number or boolean. If a path 
					  evaluates to a node set, the node set is converted to a string using the conversion rules set out 
					  in <specref ref="nodeset-conversion"/>. The following are examples of legal predicate paths:
					</p>
					<example>
						<head>Legal predicate paths</head>
						<p>
							<itemizedlist>
								<item>
									<p>
										<code>54</code> is legal because it selects a number</p>
								</item>
								<item>
									<p>
										<code>true()</code> is legal because it selects a boolean.</p>
								</item>
								<item>
									<p>
										<code>$x/foo/@bar</code> is legal because it selects a nodeset that contains an attribute node.</p>
								</item>
								<item>
									<p>
										<code>substring($x/foo,5)</code> is legal because it selects a string, and because the parameter 
										path is relative to a variable.
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
					<p>
					  The following examples are all illegal predicate paths:
					</p>
					<example>
						<head>Illegal predicate paths</head>
						<p>
							<itemizedlist>
								<item>
									<p>
										<code>/foo/bar</code> is illegal because it is not relative to a variable.</p>
								</item>
								<item>
									<p>
										<code>substring(/foo,5)</code> is illegal because the path parameter is not relative to a variable.</p>
								</item>
							</itemizedlist>
						</p>
					</example>
				</div3>
				<div3 id="nodeset-conversion">
					<head>Node set conversion</head>
					<p>
						The result of evaluating a <term>predicate path</term> is always a string, number or boolean. Nevertheless, 
						paths that evaluate to node sets, for example <code>/foo/bar</code> or <code>$x/@bar</code> are legal predicate
						paths. We therefore need to define conversion rules for converting node sets to strings.
			     </p>
					<p>
						A node set is converted to a string by determining the <emph>string value</emph> of each node in the set, and then
						concatenating the string values into a single string. The string values for the different types of nodes are
						defined as follows:
		  	    </p>
					<itemizedlist>
						<item>
							<p>
								<emph>Elements:</emph> the string value is the concatenated value of all text node children of the element</p>
						</item>
						<item>
							<p>
								<emph>Attributes:</emph> the string value is the value of the attribute.</p>
						</item>
						<item>
							<p>
								<emph>Text nodes:</emph> the value is the content of the text node.</p>
						</item>
						<item>
							<p>
								<emph>Comments:</emph> the value is the content of the comment, excluding the <code>&lt;!--</code>
						    and <code>--&gt;</code> escape characters.
						  </p>
						</item>
						<item>
							<p>
								<emph>Processing instructions:</emph> the value is the string content of the processing instruction following
						    the target, but excluding the terminating <code>?&gt;</code>
							</p>
						</item>
					</itemizedlist>
					<p>
						Here is an example document to illustrate these conversion rules:
		  	    </p>
					<example>
						<head>Sample document for conversion rules</head>
						<p>
							<eg><![CDATA[
<foo>
    <bar id="1">a</bar>
    <bar id="2">b</bar>
</foo>
]]></eg>
						</p>
					</example>
					<p>
						In this document, assuming that <code>x</code> is bound to the root element: 
						<itemizedlist>
							<item>
								<p>
									the value of	<code>$x/bar[1]/@id</code> is <code>"1"</code>,
								</p>
							</item>
							<item>
								<p>
									the value of <code>$x/bar/@id</code> is <code>"12"</code>,
								</p>
							</item>
							<item>
								<p>
									and the value of <code>$x/bar</code> is <code>"ab"</code>.
								</p>
							</item>
						</itemizedlist>
					</p>
				</div3>
				<div3 id="forall">
					<head>clix:forall</head>
					<p>
						<eg id="clix-forall"><![CDATA[
<clix:forall
  var = cdata
  in = quantifierpath>
  <!-- Content: formula -->
</clix:forall>
]]></eg>
					</p>
					<p>
						<el>clix:forall</el> is a universal quantifier that iterates over a set of nodes and returns
               <code>true</code> if and only if its subformula evaluates to <code>true</code> for all assignments
               to the variable.
            </p>
					<p>
						<att>var</att> is the variable that the quantifier will bind nodes to. It must be a valid
               XPath variable identifier. In addition, <emph>no variable with the same name must be bound
	            in any ancestor formula</emph>. The following example is illegal:                        
            </p>
					<example>
						<head>Illegal, duplicate variable binding</head>
						<p>
							<eg><![CDATA[
<clix:forall var="x" in="/spec">
  <clix:forall var="x" in="//p">
    ..
  </clix:forall>
</clix:forall>
]]></eg>
						</p>
					</example>
					<p>
						<att>in</att> defines an <term>quantifier path</term> that is evaluated to a set of nodes to iterate
               over. The path must follow the constraint on quantifier paths defined in <specref ref="pathtypes"/>.
			    </p>
					<p>
						Here is an example of a constraint that says all elements <el>price</el> must have a
						<att>currency</att> attribute set to <code>EUR</code>:
					</p>
					<example>
						<head>Using forall</head>
						<p>
							<eg><![CDATA[
<clix:forall var="price" in="/items/item/price">
  <clix:equal op1="$price/@currency" op2="'EUR'"/>
</clix:forall>
]]></eg>
						</p>
					</example>
				</div3>
				<div3 id="exists">
					<head>clix:exists</head>
					<p>
						<eg id="clix-exists"><![CDATA[
<clix:exists
  var = cdata
  in = quantifierpath>
  <!-- Content: formula? -->
</clix:exists>
]]></eg>
					</p>
					<p>
						<el>clix:exists</el> is an existential quantifier that iterates over a node set, binding a variable to each
			node in turn, and returns <code>true</code> if and only if its subformula returns <code>true</code> for at least
			one assignment to the variable. If <el>clix:exists</el> has no subformula, if returns <code>true</code> if and
			only if the set selected using the path expression is non-empty.
		      </p>
					<p>
						<att>var</att> is the variable that the quantifier will bind nodes to. It must be a valid
                        XPath variable identifier. No duplicate bindings are allowed, as specified in <specref ref="forall"/>.
		      </p>
					<p>
						<att>in</att> defines an <term>quantifier path</term> that is evaluated to a set of nodes to iterate
			over. The path must follow the constraint on quantifier paths defined in <specref ref="pathtypes"/>.
		      </p>
					<p>
						The following constraint expresses that every <el>dinner</el> element must include a
						<el>dessert</el> element:
					</p>
					<example>
						<head>Using exists</head>
						<p>
							<eg><![CDATA[
<clix:forall var="dinner" in="/restaurant/dinner">
  <clix:exists var="d" in="$dinner/dessert"/>
</clix:forall>
]]></eg>
						</p>
					</example>
				</div3>
				<div3 id="not">
					<head>clix:not</head>
					<p>
						<eg id="clix-not"><![CDATA[
<clix:not>
  <!-- Content: formula -->
</clix:not>
]]></eg>
					</p>
					<p>
						<el>clix:not</el> implements logical negation <emph>not</emph>. It returns <code>true</code> if its subformula 
						returns <code>false</code>, otherwise it returns <code>false</code>.
		      </p>
				</div3>
				<div3 id="and">
					<head>clix:and</head>
					<p>
						<eg id="clix-and"><![CDATA[
<clix:and>
  <!-- Content: (formula,formula) -->
</clix:and>
]]></eg>
					</p>
					<p>
						<el>clix:and</el> implements logical conjunction: it returns <code>true</code> if and only if both of its
			subformulae are true. This behaviour is captured in the following truth-table, where <code>f1</code> refers 
			to the first subformula and <code>f2</code> to the second:
		      </p>
					<p>
						<table border="1" rules="all" frame="border">
							<caption>Truth table for and</caption>
							<thead>
								<tr>
									<th>f1</th>
									<th>f2</th>
									<th>f1 and f2</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>true</td>
									<td>true</td>
									<td>true</td>
								</tr>
								<tr>
									<td>true</td>
									<td>false</td>
									<td>false</td>
								</tr>
								<tr>
									<td>false</td>
									<td>true</td>
									<td>false</td>
								</tr>
								<tr>
									<td>false</td>
									<td>false</td>
									<td>false</td>
								</tr>
							</tbody>
						</table>
					</p>
				</div3>
				<p>
						The following constraint expresses that every <el>dinner</el> element must include a
						<el>dessert</el> and a <el>price</el>:
					</p>
				<example>
					<head>Using and</head>
					<p>
						<eg><![CDATA[
<clix:forall var="dinner" in="/restaurant/dinner">
  <clix:and>
    <clix:exists var="d" in="$dinner/dessert"/>
    <clix:exists var="d" in="$dinner/price"/>
  </clix:and>
</clix:forall>
]]></eg>
					</p>
				</example>
				<div3 id="or">
					<head>clix:or</head>
					<p>
						<eg id="clix-or"><![CDATA[
<clix:or>
  <!-- Content: (formula,formula) -->
</clix:or>
]]></eg>
					</p>
					<p>
						<el>clix:or</el> implements logical disjunction: it returns <code>true</code> if either of its
			subformulae are true. Another way of looking at this is that it returns <code>false</code> only if both
			subformulae are false. This behaviour is captured in the following truth-table, where <code>f1</code> refers 
			to the first subformula and <code>f2</code> to the second:
		      </p>
					<p>
						<table border="1" rules="all" frame="border">
							<caption>Truth table for or</caption>
							<thead>
								<tr>
									<th>f1</th>
									<th>f2</th>
									<th>f1 or f2</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>true</td>
									<td>true</td>
									<td>true</td>
								</tr>
								<tr>
									<td>true</td>
									<td>false</td>
									<td>true</td>
								</tr>
								<tr>
									<td>false</td>
									<td>true</td>
									<td>true</td>
								</tr>
								<tr>
									<td>false</td>
									<td>false</td>
									<td>false</td>
								</tr>
							</tbody>
						</table>
					</p>
				</div3>
				<div3 id="implies">
					<head>clix:implies</head>
					<p>
						<eg id="clix-implies"><![CDATA[
<clix:implies>
  <!-- Content: (formula,formula) -->
</clix:implies>
]]></eg>
					</p>
					<p>
						<el>clix:implies</el> provides logical implication. "a implies b", where <code>a</code> and <code>b</code> are
			the two subformulae, expresses the constraint that if <code>a</code> is true then <code>b</code> must also be
			true. It does not express any notion about what happens when <code>a</code> is false - in this case the outcome
			of the implication is always true. This is captured more precisely in the following truth table:
		      </p>
					<p>
						<table border="1" rules="all" frame="border">
							<caption>Truth table for implies</caption>
							<thead>
								<tr>
									<th>f1</th>
									<th>f2</th>
									<th>f1 implies f2</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>true</td>
									<td>true</td>
									<td>true</td>
								</tr>
								<tr>
									<td>true</td>
									<td>false</td>
									<td>false</td>
								</tr>
								<tr>
									<td>false</td>
									<td>true</td>
									<td>true</td>
								</tr>
								<tr>
									<td>false</td>
									<td>false</td>
									<td>true</td>
								</tr>
							</tbody>
						</table>
					</p>
				</div3>
				<div3 id="iff">
					<head>clix:iff</head>
					<p>
						<eg id="clix-iff"><![CDATA[
<clix:iff>
  <!-- Content: (formula,formula) -->
</clix:iff>
]]></eg>
					</p>
					<p>
						<el>clix:iff</el> is a shorthand for "if and only if". It is <code>true</code> if both subformulae evaluate to
			the same result, that is if they are either both <code>true</code> or both <code>false</code>. "a iff b" is
			a common way of abbreviating the equivalent "(a implies b) and (b implies a)":
		      </p>
					<p>
						<table border="1" rules="all" frame="border">
							<caption>Truth table for iff</caption>
							<thead>
								<tr>
									<th>f1</th>
									<th>f2</th>
									<th>f1 iff f2</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>true</td>
									<td>true</td>
									<td>true</td>
								</tr>
								<tr>
									<td>true</td>
									<td>false</td>
									<td>false</td>
								</tr>
								<tr>
									<td>false</td>
									<td>true</td>
									<td>false</td>
								</tr>
								<tr>
									<td>false</td>
									<td>false</td>
									<td>true</td>
								</tr>
							</tbody>
						</table>
					</p>
				</div3>
				<div3 id="equal">
					<head>clix:equal</head>
					<p>
						<eg id="clix-equal"><![CDATA[
<clix:equal
  op1 = predicatepath
  op2 = predicatepath/>
]]></eg>
					</p>
					<p>
						<el>clix:equal</el> compares two values for equality and returns <code>true</code> if and only if the values
						are equal. The two parameters are <term>predicate paths</term> and have to meet the constraints set out in
						<specref ref="pathtypes"/>. If both parameters evaluate to the same types, they are compared directly, that is
						strings are compared to strings using standard string comparison, numbers are compared to numbers using numeric
						comparison (which disregard lexical artefacts so that for example <code>5.0</code> is equal to <code>5</code>)
						and booleans are similarly compared using a boolean comparison.
 		      </p>
					<p>
 		      		If either parameter evaluates to a node set, it is converted using the conversion rules specified
 		      		in <specref ref="nodeset-conversion"/> and treated like a string. The following casting rules are then
 		      		applied as normal.
 		      	</p>
					<p>
						If the two parameters do <emph>not</emph> evaluate to the same type, casting rules are applied to convert the
						type of lower priority into the type of the other parameter. The order of the parameters is insignificant,
						type priority is the overriding concern. Thus, <code>Type 1</code> and <code>Type 2</code> in the following table
						do not refer to the types of the first and second parameter, but are simply a way of referring to a pair of
						types. The <td>Base Type</td> is the type that the lower priority type is converted into:
		      </p>
					<p>
						<table border="1">
							<caption>Type conversion rules</caption>
							<thead>
								<tr>
									<td>Type 1</td>
									<td>Type 2</td>
									<td>Base Type</td>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>Boolean</td>
									<td>Number</td>
									<td>Boolean</td>
								</tr>
								<tr>
									<td>Boolean</td>
									<td>String</td>
									<td>String</td>
								</tr>
								<tr>
									<td>String</td>
									<td>Number</td>
									<td>String</td>
								</tr>
							</tbody>
						</table>
					</p>
					<p>
						There are thus three type conversions that may take place and their implementation proceeds as follows:
		      </p>
					<itemizedlist>
						<item>
							<p>
								<emph>Number to Boolean:</emph> A non-zero number except <code>NaN</code> is converted to 
						    <code>true</code>. <code>0</code> and <code>NaN</code> are converted to <code>false</code>.
					    </p>
						</item>
						<item>
							<p>
								<emph>Boolean to String:</emph>
								<code>true</code> is converted to <code>"true"</code> and
						    <code>false</code> is converted to <code>"false"</code>.
						  </p>
						</item>
						<item>
							<p>
								<emph>Number to String:</emph> Numbers with zero remainders are converted by taking the string
						    representation of the integer part of the number on a decimal base, preceded by a minus sign if the
						    number is negative. Thus <code>5</code> is converted to <code>"5"</code>. Numbers with non-zero remainders
						    are represented as decimal numbers with a period representing the decimal point, with at least one digit
						    in the integer part, and as many digits in the fractional part as are required to distinguish the number from
						    all other IEEE754 values. Thus <code>5.23400</code> is converted to <code>"5.234"</code>. Finally,
						    <code>NaN</code> is converted to <code>"NaN"</code>.
					    </p>
						</item>
					</itemizedlist>
					<p>
						As a result of these conversions, care must be taken when comparing numbers to strings. For example,
						<code>&lt;clix:equal op1="5" op2="'5.0'"/&gt;</code> returns <code>false</code> because the number 
						<code>5</code> would be converted into the string <code>"5"</code>, which is not equal to
						<code>"5.0"</code>. In general, it would be best to compare numbers to numbers directly, or to make use
						of the XPath <code>number</code> function where this is not possible.
		        </p>
					<example>
						<head>Using equal</head>
						<p>
							Assume the following example document, and that the variable <code>x</code> has been bound to
							<el>bar1</el> and <code>y</code> has been bound to <el>bar2</el>:
						</p>
						<p>
							<eg><![CDATA[<foo>
	<bar1>A value</bar1>
	<bar2>5.0</bar2>
</foo>
]]></eg>
						</p>
						<p>
							Then equal would behave as follows:
							<itemizedlist>
								<item>
									<p>
										<code>&lt;clix:equal op1="$x" op2="'A value'"/&gt;</code> is true
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:equal op1="$y" op2="5"/&gt;</code> is false
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:equal op1="number($y)" op2="5"/&gt;</code> is true
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
				</div3>
				<div3 id="notEqual">
					<head>clix:notEqual</head>
					<p>
						<eg id="clix-notequal"><![CDATA[
<clix:notequal
  op1 = predicatepath
  op2 = predicatepath/>
]]></eg>
					</p>
					<p>
						<el>clix:notequal</el> compares two values for equality and returns <code>true</code> if and only if
						the values are not equal. The two parameters are <term>predicate paths</term> and have to meet the 
						constraints set out in <specref ref="pathtypes"/>. Differing parameter types are cast to a base using the
						rules specified for <specref ref="equal"/>. 
					</p>
					<p>
						The behaviour of <el>clix:notequal</el> is such that the following
						two formulae are equivalent:
					
			<eg><![CDATA[
<clix:notequal op1="$x/bar" op2="$y/bar"/>

<clix:not>
  <clix:equal op1="$x/bar" op2="$y/bar"/>
</clix:not>]]></eg>
					</p>
				</div3>
				<div3 id="same">
					<head>clix:same</head>
					<p>
						<eg id="clix-same"><![CDATA[
<clix:same
  op1 = varref
  op2 = varref />
]]></eg>
					</p>
					<p>
						<el>clix:same</el> is the only predicate in CLiX that does not take two XPaths as a parameter.
						Instead, it takes two variable references of the form <code>$varname</code> and checks if
						<emph>exactly</emph> the same nodes are bound to the two variables.
					</p>
					<p>
						This is different from <el>clix:equal</el>, because the two parameters are not compared by
						value. Take the following document as an example:
					</p>
					<p>
						<eg><![CDATA[<foo>
	<bar1>A value</bar1>
	<bar2>A value</bar2>
</foo>
]]></eg>
					</p>
					<p>
						If you assume that <code>x</code> is bound to <el>bar1</el> and <code>y</code> is bound
						to <el>bar2</el>, then:
						<itemizedlist>
							<item>
								<p>
									<code>&lt;clix:same op1="$x" op2="$y"/&gt;</code> is false because <code>x</code>
									does not point to the same node as <code>y</code>.
								</p>
							</item>
							<item>
								<p>
									<code>&lt;clix:equal op1="$x" op2="$y"/&gt;</code> is true, because the two nodes
									contain the same value
								</p>
							</item>
							<item>
								<p>
									<code>&lt;clix:same op1="$x" op2="$x"/&gt;</code> is true 
								</p>
							</item>
						</itemizedlist>
					</p>
					<p>
						Same is useful for certain types of constraints like complex uniqueness constraints. We can
						express that all elements <el>foo</el> are unique if compared by <att>@id</att> as follows:
					</p>
					<example>
						<head>Using same</head>
						<p>
							<eg><![CDATA[<clix:forall var="x" in="/foo">
  <clix:forall var="y" in="/foo">
    <clix:implies>
      <clix:equal op1="$x/@id" op2="$y/@id"/>
      <clix:same op1="$x" op2="$y"/>
    </clix:implies>
  </clix:forall>
</clix:forall>]]></eg>
						</p>
					</example>
				</div3>
				<div3 id="less">
					<head>clix:less</head>
					<p>
						<eg id="clix-less"><![CDATA[
<clix:less
  op1 = predicatepath
  op2 = predicatepath/>
]]></eg>
					</p>
					<p>
						<el>clix:less</el> compares its two parameters and returns true if the first parameter is either
						lexicographically or numerically strictly less than the second, in the case of strings and numbers, or if it is
						not equal to the second, in the case of booleans. The two parameters are <term>predicate paths</term> and 
						have to meet the constraints set out in <specref ref="pathtypes"/>. Before comparison, different types
						of parameters are cast to a common base as specified for <specref ref="equal"/>
					</p>
					<example>
						<head>Using less</head>
						<p>
							Assume the following example document, and that the variable <code>x</code> has been bound to
							<el>bar1</el> and <code>y</code> has been bound to <el>bar2</el>:
						</p>
						<p>
							<eg><![CDATA[<foo>
	<bar1>A value</bar1>
	<bar2>5.0</bar2>
</foo>
]]></eg>
						</p>
						<p>
							Then <el>clix:less</el> would be evaluated as follows:
							<itemizedlist>
								<item>
									<p>
										<code>&lt;clix:less op1="$x" op2="'No value'"/&gt;</code> is true
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:less op1="number($y)" op2="6"/&gt;</code> is true
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:less op1="number($y)" op2="5"/&gt;</code> is false - the value
										needs to be strictly less.
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:less op1="true()" op2="false()"/&gt;</code> is true
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
				</div3>
				<div3 id="lessOrEqual">
					<head>clix:lessOrEqual</head>
					<p>
						<eg id="clix-lessorequal"><![CDATA[
<clix:lessOrEqual
  op1 = predicatepath
  op2 = predicatepath/>
]]></eg>
					</p>
					<p>
						<el>clix:lessOrEqual</el> is a combination of <el>clix:less</el> and <el>clix:equal</el>. 
						The two parameters are <term>predicate paths</term> and have to meet the constraints set out 
						in <specref ref="pathtypes"/>. The following two formulae are equivalent:
					</p>
					<p>
						<eg><![CDATA[
<clix:lessOrEqual op1="$x" op="$y"/>

<clix:or>
  <clix:less op1="$x" op="$y"/>
  <clix:equal op1="$x" op="$y"/>  
</clix:or>]]></eg>
					</p>
				</div3>
				<div3 id="greater">
					<head>clix:greater</head>
					<p>
						<eg id="clix-greater"><![CDATA[
<clix:greater
  op1 = predicatepath
  op2 = predicatepath/>
]]></eg>
					</p>
					<p>
						<el>clix:greater</el> compares its two parameters and returns true if the first parameter is either
						lexicographically or numerically strictly greater than the second, in the case of strings and numbers, or if it is
						not equal to the second, in the case of booleans. The two parameters are <term>predicate paths</term> and 
						have to meet the constraints set out in <specref ref="pathtypes"/>. Before comparison, different types
						of parameters are cast to a common base as specified for <specref ref="equal"/>
					</p>
					<p>
						With the exception of booleans, for which both <el>clix:greater</el> and <el>clix:less</el> return 
						true if and only if the two parameters evaluate to the same boolean value, the following two formulae
						are equivalent:
					</p>
					<p>
						<eg><![CDATA[
<clix:greater op1="$x" op="$y"/>

<clix:less op1="$y" op="$x"/>]]></eg>
					</p>
					<example>
						<head>Using greater</head>
						<p>
							Assume the following example document, and that the variable <code>x</code> has been bound to
							<el>bar1</el> and <code>y</code> has been bound to <el>bar2</el>:
						</p>
						<p>
							<eg><![CDATA[<foo>
	<bar1>A value</bar1>
	<bar2>5.0</bar2>
</foo>
]]></eg>
						</p>
						<p>
							Then <el>clix:greater</el> would be evaluated as follows:
							<itemizedlist>
								<item>
									<p>
										<code>&lt;clix:greater op1="$x" op2="'No value'"/&gt;</code> is false
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:greater op1="number($y)" op2="5"/&gt;</code> is false - the value
										needs to be strictly greater.
									</p>
								</item>
								<item>
									<p>
										<code>&lt;clix:greater op1="true()" op2="false()"/&gt;</code> is true
									</p>
								</item>
							</itemizedlist>
						</p>
					</example>
				</div3>
				<div3 id="greaterOrEqual">
					<head>clix:greaterOrEqual</head>
					<p>
						<eg id="clix-greaterorequal"><![CDATA[
<clix:greaterOrEqual
  op1 = predicatepath
  op2 = predicatepath/>
]]></eg>
					</p>
					<p>
						<el>clix:greaterOrEqual</el> is a combination of <el>clix:greater</el> and <el>clix:equal</el>. 
						The two parameters are <term>predicate paths</term> and have to meet the constraints set out 
						in <specref ref="pathtypes"/>. The following two formulae are equivalent:
					</p>
					<p>
						<eg><![CDATA[
<clix:greaterOrEqual op1="$x" op="$y"/>

<clix:or>
  <clix:greater op1="$x" op="$y"/>
  <clix:equal op1="$x" op="$y"/>  
</clix:or>]]></eg>
					</p>
				</div3>
			</div2>
			<div2 id="extension">
				<head>Extension Mechanisms</head>
				<p>
					CLiX provides two extension mechanisms for the constraint language, plugin operators and 
					macros. Plugin operators are scripted predicates that can take a number of parameters and
					return true or false. They can be used to perform a variety of tasks like database lookups,
					communication with legacy systems or extensive computation.
				</p>
				<p>
					Macros are parameterised CLiX formulas that are kept in a macro definition file. They can be
					invoked in a rule to automatically expand the rule. This makes it possible to reuse frequently
					used constraint types. Macros are not further defined in this version of the spec but will be 
					added in a minor release.
				</p>
				<div3 id="operator">
					<head>clix:operator</head>
					<p>
						<eg id="clix-operator"><![CDATA[
<clix:operator
  name = cdata>
  <!-- Content: clix:param* --> 
</clix:operator>
]]></eg>
					</p>
					<p>
						<el>clix:operator</el> can be used wherever any other predicate like <el>clix:equal</el> or
						<el>clix:notEqual</el> can be used. Like these predicates, it takes a number of parameters and
						returns true of false. The difference is that the operator can take any number of parameters, and its
						computation is outside the scope of this specification. 
					</p>
					<p>
						It is assume that a CLiX execution engine will make operators available for use in a formula. The way
						this is done is language specific and thus this specification does not constrain it further. The only 
						requirement imposed here is that the <att>name</att> attribute of the operator must point to some
						implementation construct with the same name, and implementors should clearly specify how this relationship
						is established.
					</p>
					<p>
						An operator can take a number of <el>clix:param</el> elements, which are defined as follows:
					</p>
					<p>
						<eg id="clix-operator-param"><![CDATA[
<clix:param
  name = cdata
  value = predicatepath/>]]></eg>
					</p>
					<p>
						Every parameter has a <att>name</att> and a <att>value</att>. The name must bind to a parameter that the
						externally specified implementation expects. For example, in an ECMAScript implementation, this will reference
						a parameter passed to the function implementing the operator. The <att>value</att> must contain a 
						predicate path, as specified in <specref ref="pathtypes"/>. Implementing CLiX processors will evaluate this
						predicate path and pass its value on as a string, number or boolean to the operator implementation.
					</p>
					<example>
						<head>Using operator</head>
						<p>
							Suppose we want to check that some element in a document is a prime number, and we provide an operator
							implementation that can execute this check. We would make this operator available in some programming
							language and then invoke it as follows:
						</p>
						<p>
							<eg><![CDATA[
<clix:forall var="n" in="/mylist/number">
  <clix:operator name="isPrime">
    <clix:param name="num" value="number($n)"/>
  </clix:operator>
</clix:forall>
]]></eg>
						</p>
					</example>
				</div3>
				<div3 id="macro">
					<head>macro:*</head>
					<p>
						This formula construct is used for macro invocation. This mechanism will be defined in a minor version
						upgrade of this specification.
					</p>
				</div3>
			</div2>
		</div1>
		<!--
        <div1 id="operators">
            <head>Plug-in Operators</head>
        </div1>
-->
		<!--        <div1 id="macros">
            <head>Macros</head>
        </div1>-->
	</body>
	<back>
		<div1 id="references">
			<head>References</head>
			<blist>
				<bibl key="RELAX NG" id="RELAXNG">
					<titleref>RELAX NG.</titleref> OASIS Committee Specification. See <loc href="http://www.oasis-open.org/committees/relax-ng/spec-20011203.html">http://www.oasis-open.org/committees/relax-ng/spec-20011203.html</loc>
				</bibl>
				<bibl key="Schematron" id="SCHEMATRON">
					<titleref>The Schematron Assertion Language.</titleref> See <loc href="http://www.ascc.net/xml/schematron/">http://www.ascc.net/xml/schematron/</loc>
				</bibl>
				<bibl key="XML Schema" id="XMLSCHEMA">
					<titleref>XML Schema.</titleref> W3C Recommendation. See <loc href="http://www.w3.org/XML/Schema">http://www.w3.org/XML/Schema</loc>
				</bibl>
				<bibl key="XPath" id="XPATH">
					<titleref>XML Path Language (XPath) Version 1.0.</titleref> W3C Recommendation. See <loc href="http://www.w3.org/TR/xpath/">http://www.w3.org/TR/xpath/</loc>
				</bibl>
				<bibl key="XSLT" id="XSLT">
					<titleref>XSL Transformations (XSLT) Version 1.0.</titleref> W3C Recommendation. See 
					<loc href="http://www.w3.org/TR/xslt">http://www.w3.org/TR/xslt</loc>
				</bibl>
			</blist>
		</div1>
	</back>
</spec>
