
    <inform-div1 id="detection">
	<head>Detecting Patterns</head>
	<p>
	The patterns defined by this specification may be detected in a description 
	such as an <bibref ref="XMLSchema"/>, <bibref ref="WSDL20"/> or <bibref ref="WSDL11"/>
	document using an <bibref ref="XPath20"/> processor. 
	The following example illustrates detecting a pattern 
	using an <bibref ref="XSLT20"/> stylesheet: 
	</p>
       <exampleInner id="detector-XSLT20">
	  <eg xml:space="preserve">
&lt;xsl:stylesheet version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:ex="http://www.w3.org/2002/ws/databinding/examples/6/09/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/"&gt;

    &lt;xsl:output method="text" /&gt;

    &lt;xsl:template match="/"&gt;
        &lt;xsl:apply-templates select="//xs:schema" mode="detect"/&gt;
    &lt;/xsl:template&gt;

    &lt;xsl:template match="*" mode="detect"&gt;
        &lt;xsl:if test="count(.//xs:element/@type[resolve-QName(.,..) = xs:QName('xs:string')]) gt 0"&gt;
            http://www.w3.org/2002/ws/databinding/patterns/6/09/StringElement
        &lt;/xsl:if&gt;

	&lt;!-- tests to detect other patterns .. --&gt;

    &lt;/xsl:template&gt;

    &lt;xsl:template match="text()"/&gt;
&lt;/xsl:stylesheet&gt; </eg></exampleInner>
	<p>
	Similarly a <bibref ref="Schematron" /> schema may be assembled from this 
	    specification and used in conjunction with a processor which
	    supports <bibref ref="XPath20"/> as follows:
	</p>
       <exampleInner id="detector-Schematron">
	  <eg xml:space="preserve">
&lt;sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"&gt;
    &lt;sch:ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"&gt;&lt;/sch:ns&gt;
    &lt;sch:pattern name="Basic"&gt;
        &lt;sch:rule&gt;
	    &lt;sch:report 
	    test="count(.//xs:element/@type[resolve-QName(.,..) = xs:QName('xs:string')]) gt 0"&gt;
		http://www.w3.org/2002/ws/databinding/patterns/6/09/StringElement
	    &lt;/sch:report&gt;
	&lt;/sch:rule&gt;

	&lt;!-- reports to detect other patterns .. --&gt;

    &lt;/sch:pattern&gt;
&lt;/sch:schema&gt;</eg></exampleInner>

     <p>The <bibref ref="XPath20"/> for each <bibref ref="XMLSchema"/> pattern is constructed to return a set containing all of the Element and Attribute nodes covered by an individual pattern. Elements and attributes contained within a <bibref ref="XMLSchema"/> document not covered by a set of patterns may be detected using an <bibref ref="XPath2.0"/> expression as in the following <bibref ref="XSLT20"/> extract:</p>
       <exampleInner id="detector-Schematron">
	  <eg xml:space="preserve">
  &lt;xsl:if select="(.//* | .//@*)   except
        ( @targetNamespace
            | .//xs:element[resolve-QName(@type,.) = xs:QName('xs:string')]/(@type)
	    | .. other pattern XPaths ..
        )"&gt; 
	    unexpected elements or attributes detected
	&lt;/xsl:if&gt;		
	    </eg></exampleInner>
    </inform-div1>

