<?xml version='1.0'?>
<!-- Wrapper for xmlspec.xsl for XML Schema part 1 -->
<!-- Henry S. Thompson 1999-05-10 -->
<!-- XSL Style sheet, DTD omitted -->
<!DOCTYPE xsl:stylesheet [
<!ENTITY sect   "&#xa7;">
<!ENTITY nbsp   "&#160;">
<!-- width for examples - - set small for variable size -->
<!ENTITY pwidth " width: 1px;"> <!-- 5.8 in works well for printing -->
<!-- width for mappings - - set small doesn't work -->
<!ENTITY twidth " width: 100&#37;;"> <!-- 5.8 in works well for printing -->
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" exclude-result-prefixes="xsd">

 <!-- highlight unprocessed tags
 <xsl:template match="*"><SPAN STYLE="color:GREEN"><xsl:attribute name="TITLE"><xsl:value-of select="name()"/></xsl:attribute><xsl:apply-templates/></SPAN></xsl:template> -->

 <xsl:import href="xmlspec.xsl"/> 

 <xsl:strip-space elements="xsd:*"/>

  <!-- Get and stash schema and schema dump, if present.
       Two stages because we need to establish context for
       unparsed-entity-uri as the input document -->
 
 <xsl:variable name="sdf">
   <xsl:value-of select="/spec/@schemaDump"/>
 </xsl:variable>
 
 <xsl:variable name="sd">
   <xsl:value-of select="/spec/@schemaProper"/>
 </xsl:variable>
 
 <xsl:variable name="dsd">
   <xsl:value-of select="/spec/@datatypeSchemaProper"/>
 </xsl:variable>
 
 <xsl:variable name="sde">
   <xsl:value-of select="/spec/@schemaExample"/>
 </xsl:variable>
 
 <xsl:variable name="ddx">
   <xsl:value-of select="/spec/@datatypeDoc"/>
 </xsl:variable>

 <xsl:variable name="schemaDump" select="document($sdf,/)/*"/>
 <xsl:variable name="schemaProper" select="document($sd,/)/*"/>
 <xsl:variable name="dschemaProper" select="document($dsd,/)/*"/>
 <xsl:variable name="schemaExample" select="document($sde,/)/*"/>
 
 <xsl:variable name="datatypeURL">
  <xsl:value-of select="/spec/back/div1/blist/bibl[@id='ref-xsp2']/loc/@href"/>
 </xsl:variable>
 
 <xsl:variable name="reprelts" select="/spec/body/div1[@id='components']/div2/div3/reprdef/reprelt|/spec/body/div1[@id='composition']/div2[@id='layer2']/div3/reprdef/reprelt"/>

 <xsl:variable name="cnotes" select="//constraintnote"/>
 <xsl:variable name="dcnotes" select="document($ddx,/)//constraintnote"/>
 
 <xsl:template match="stale">
  <p class="stale">
<xsl:text>[Unrestructured material elided]</xsl:text>
  </p><!-- [Begin unrestructured material:
  <div class="stale">
   <xsl:apply-templates/>
  </div>
  <p class="stale">
<xsl:text>End unrestructured material]</xsl:text>
  </p>-->
 </xsl:template>

<!-- Override - - always empty and single in xmlschema-1,
     section numbers after in ()s -->
<!-- Check print for underline, else bold -->
 <xsl:template match="specref" name="specref">
  <xsl:param name="ref"><xsl:value-of select="@ref"/></xsl:param>
		<a href="#{$ref}">
                <xsl:value-of select="id($ref)/head"/>
		<xsl:text> (&sect;</xsl:text>
                <xsl:for-each select="id($ref)">
		<xsl:choose>
		<xsl:when test="ancestor::back">
			<xsl:number level="multiple" count="inform-div1|div1|div2|div3|div4" format="A.1"/>
		</xsl:when>
		<xsl:when test="ancestor::body">
			<xsl:number level="multiple" count="div1|div2|div3|div4" format="1.1"/>
		</xsl:when>
                </xsl:choose>
                </xsl:for-each>
		<xsl:text>)</xsl:text>
		</a>
 </xsl:template>

<!-- Override to get our Definition style in and
     override (W3C CSS) stylesheet's PRE indent -->
	<xsl:template match="spec">
		<html>
		<head>
		<title>
		<xsl:value-of select="header/title"/>
		</title>
                <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
		<style type="text/css">
                   code { font-family: monospace; font-size: 100%}
                   pre { margin: 0em 0cm;
                         padding: 0 0.3cm;
                         white-space: pre;  /* for NS4 */
                         border: none;      /* for NS4 */
                         font-size: 92%; }
                   span.propdef { font-weight: bold; font-family: monospace }
                   span.termdef {color: rgb(133,0,033)}
                   dl.props {margin-bottom: 0em}
                   div.localToc {margin-top: 0em}
                   h3.withToc {margin-bottom: 0em}
                   a.termref {font-family: sans-serif;
                              font-style: italic;
                              color: black;
                              text-decoration: none } 
                   a.eltref { font-family: sans-serif;
                              color: black; 
                              text-decoration: none }
                   a.propref, a.xpropref { color: black; text-decoration: none;
                                           font-family: sans-serif }
                   div.constraintnote { margin-top: 1em }
                   div.constraint {
                      margin-left: 1em; }
                   <!-- constraint clause lists -->
                   div.constraintlist {
                      margin-left: 1em; margin-bottom: 0
                   }
                   div.clnumber {
                      text-indent: -1em;
                      margin-top: 0; margin-bottom: 0 }
                   <!-- schema component definitions -->
                   div.schemaComp { border: 4px double gray; 
                                     margin: 0 1em; padding: 0 }
                   div.compHeader { margin: 4px;
                                    font-weight: bold }
                   span.schemaComp { color: #A52A2A }                  
                   div.compBody { 
                                  border-top-width: 4px;
                                  border-top-style: double;
                                  border-top-color: #d3d3d3;
                                  padding: 4px ; margin: 0}
                   <!-- element displays -->
                   div.reprdef { border: 4px double gray; 
                                     margin: 0 1em; padding: 0 }
                   div.reprHeader { margin: 4px;
                                    font-weight: bold }
                   span.reprdef { color: #A52A2A }                  
                   div.reprBody, div.reprcomp, div.reprdep { 
                                  border-top-width: 4px;
                                  border-top-style: double;
                                  border-top-color: #d3d3d3;
                                  padding: 4px ; margin: 0}
                   p.element-syntax-1 { font-family: monospace }
                   p.element-syntax { font-family: monospace; 
                                  border-top-width: 1px;
                                  border-top-style: solid;
                                  border-top-color: #d3d3d3;
                                  padding: 4px ; margin: 0}
                   <!-- examples with prose -->
                   div.exampleOuter {border: 4px double gray; 
                                     margin: 0 0; padding: 0}                  
                   div.exampleInner { background: #80ffff;
                                      border-top-width: 4px;
                                      border-top-style: double;
                                      border-top-color: #d3d3d3;
                                      border-bottom-width: 4px;
                                      border-bottom-style: double;
                                      border-bottom-color: #d3d3d3;
                                      padding: 4px; margin: 0 }
                   div.exampleWrapper { margin: 4px }
                   div.exampleHeader { color: blue; font-weight: bold;
                                       margin: 4px}
                   <!-- particle restriction table -->
                   table.restricts { margin-top: 1em; margin-bottom: 1em; }
                  <xsl:apply-templates select="." mode="css"/>
                </style>
		<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-{@docStatus}"/>
		</head>
		<body>
                  <xsl:apply-templates/>
		</body>
		</html>
	</xsl:template>


	<!-- Override to get extra text -->
        <xsl:template match="termdef">
             <span class="termdef">
               <a name="{@id}"><xsl:text>[Definition:]&nbsp;&nbsp;</xsl:text></a>
               <xsl:apply-templates/>
             </span>
        </xsl:template>

        <!-- override to get header inside box -->
        <xsl:template match="scrap">
             <div class="scrap">
             <table cellpadding="5" border="1" bgcolor="#f5dcb3" width="100%">
                <tbody>
                  <tr align="left">
                    <td>
                      <strong>
                      <font color="red"><xsl:value-of select="head"/></font>
                      </strong>
                    </td>
                   </tr>
                   <tr><td><table border="0" bgcolor="#f5dcb3"><tbody>
	          <xsl:apply-templates select="prodgroup|prod"/>
                   </tbody></table></td></tr>
                </tbody>
              </table>
              </div>
        </xsl:template>

<!-- special treatment for special common case:  eg inside note -->
        <xsl:template match="note[@role='example' or child::eg]">
          <div class="exampleOuter">
           <div class="exampleHeader">Example</div>
           <xsl:if test="*[1][self::p]">
            <div class="exampleWrapper">
             <xsl:apply-templates select="*[1]"/>
            </div>
           </xsl:if>
           <div class="exampleInner">
            <xsl:apply-templates select="eg"/>
           </div>
           <div class="exampleWrapper">
            <xsl:apply-templates select="*[position()>1 and self::p]"/>
           </div>
          </div>
         </xsl:template>

        <xsl:template match="note/eg">        
         <xsl:call-template name="egbody"/>        
        </xsl:template>

        <xsl:template match="B">
                <b><xsl:apply-templates/></b>
        </xsl:template>
<!-- **************************************************************** -->
<!-- Tables -->
<!-- **************************************************************** -->
<!-- 
     Tables

     just copy over the entire subtree, as is
     except that the children of TD, TH and CAPTION are possibly handled by
     other templates in this stylesheet
  -->
<xsl:template match="table|caption|thead|tfoot|tbody|colgroup|col|tr|th|td">
   <xsl:element name="{name()}">
      <xsl:apply-templates select="* | @* | text()"/>
   </xsl:element>
</xsl:template>

<xsl:template match="
	table/@* |
	thead/@* |
	tfoot/@* |
	tbody/@* |
	colgroup/@* |
	col/@* |
	tr/@* |
	th/@* |
	td/@*">
   <xsl:copy>
      <xsl:apply-templates/>
   </xsl:copy>
</xsl:template>

        <!-- We do this differently from James -->
        <xsl:template match="rhs/com">
             <i class="com"><xsl:apply-templates/></i>
        </xsl:template>

         <xsl:template match="pt">
           <i><xsl:apply-templates/></i>
         </xsl:template>


<!-- 'Choose' cases for XSDL spec  -->
        <xsl:template match="constraintnote">
             <div class="constraintnote">
               <a name="{@id}"></a>
               <b>
                 <xsl:choose>
                      <xsl:when test="@type=&quot;cos&quot;">
                          <xsl:text>Schema Component Constraint:  </xsl:text>
                      </xsl:when>
                  <xsl:when test="@type=&quot;src&quot;">
                          <xsl:text>Schema Representation Constraint:  </xsl:text>
                      </xsl:when>
                      <xsl:when test="@type=&quot;cvc&quot;">
                          <xsl:text>Validation Rule:  </xsl:text>
                      </xsl:when>
                      <xsl:when test="@type=&quot;sic&quot;">
                          <xsl:text>Schema Information Set Contribution:  </xsl:text>
                      </xsl:when>
                      <xsl:otherwise>Constraint:  </xsl:otherwise>
                 </xsl:choose>
               <xsl:value-of select="head"/>
               </b><br/>
               <div class="constraint"><xsl:apply-templates/></div>
               
             </div>
        </xsl:template>

        <!-- Override to avoid stripping prefix (Why does James do this?) -->
	<xsl:template match="issue">
		<xsl:call-template name="insertID"/>
		<blockquote>
			<b>Issue (<xsl:value-of select="@id"/>): </b>
			<xsl:apply-templates/>
		</blockquote>
	</xsl:template>

        <xsl:template match="constraintnote/head"/>
 
 <!-- Our own component definition -->
 
 <xsl:template match="compdef">
  <div class="schemaComp">
   <div class="compHeader">
    <span class="schemaComp">Schema&nbsp;Component</span><xsl:text>:&nbsp;</xsl:text><a href="#{@ref}"><xsl:value-of select="@name"/></a>
   </div>
   <div class="compBody">
    <xsl:apply-templates/>
   </div>
  </div>
 </xsl:template>
 
 <xsl:template match="proplist">
  <dl class="props">
                      <xsl:apply-templates/>
                      </dl>
 </xsl:template>
 
 <!-- we use our own brackets -->
 <xsl:template match="propdef">
  <xsl:call-template name="propdef">
   <xsl:with-param name="ob">{</xsl:with-param>
   <xsl:with-param name="cb">}</xsl:with-param>
  </xsl:call-template>
 </xsl:template>
 
 <xsl:template match="propref">
  <xsl:call-template name="propref">
   <xsl:with-param name="ob">{</xsl:with-param>
   <xsl:with-param name="cb">}</xsl:with-param>
  </xsl:call-template>
 </xsl:template>

 <!-- Our own complex abstract data type to concrete syntax mapping display -->
 
 <xsl:template match="reprdef">
  <div class="reprdef">
   <div class="reprHeader">
    <span class="reprdef">XML&nbsp;Representation&nbsp;Summary</span><xsl:text>:&nbsp;</xsl:text><code><xsl:value-of select="reprelt[1]/@eltname"/></code>
               <xsl:text>&nbsp;Element Information Item</xsl:text>
   </div>
   <div class="reprBody">
    <xsl:apply-templates/>
   </div>
  </div>
 </xsl:template>
 
 <xsl:template match="reprelt">                  
  <xsl:variable name="name" select="@eltname"/>
  <xsl:variable name="class">
   <xsl:call-template name="chooseClass"/>
  </xsl:variable>
  <p class="{$class}">
   <xsl:choose>
     <xsl:when test="@type">
      <xsl:variable name="type" select="@type"/>
      <xsl:call-template name="explicitType">
       <xsl:with-param name="elt" select="@eltname"/>
       <xsl:with-param name="typeDef" select="$schemaDump/xsd:complexType[@name=$type]"/>
       <xsl:with-param name="anchor">
        <xsl:if test="@local"><xsl:value-of select="@local"/>::</xsl:if><xsl:value-of select="@eltname"/>
       </xsl:with-param>
      </xsl:call-template>
     </xsl:when>
     <xsl:when test="$name='example'">
      <!-- cheat like h*** -->
      <xsl:apply-templates select="$schemaExample/xsd:element[@name='example']"/>
     </xsl:when>
     <xsl:otherwise><xsl:apply-templates select="$schemaDump/xsd:element[@name=$name]"/></xsl:otherwise>
    </xsl:choose></p> 
 </xsl:template>

 
 <xsl:template match="reprcomp">
  
  <div class="reprcomp"><xsl:apply-templates select="reprdep"/>
  <xsl:if test="propmap"><table class="reprcomp">
   <thead>
    <tr>
     <th><a><xsl:attribute name="href">#<xsl:value-of select="@ref"/></xsl:attribute><xsl:value-of select="@abstract"/></a><strong>&nbsp;Schema Component</strong></th>
    </tr>
   </thead>
   <tbody>
    <tr>
     <td>
      <table border="0">
       <thead>
        <tr>
         <th align="left">Property</th>
         <th align="left">Representation</th>
        </tr>
       </thead>
       <tbody valign="top">
        <xsl:for-each select="propmap">
         <tr valign="top">
          <td>
<a href="#{@name}" class="propref">{<xsl:value-of select="id(@name)/@name"/>}</a>
</td>
          <td>
           <xsl:apply-templates/>
          </td>
         </tr>
        </xsl:for-each>
       </tbody>
      </table>
     </td>
    </tr>
   </tbody>
  </table></xsl:if></div>
  
 </xsl:template>
 
 <xsl:template match="reprdep|reprdef/p[preceding-sibling::*]">
   <div class="reprdep">
    <xsl:apply-templates/>
   </div>  
 </xsl:template>

 <xsl:template match="xsd:element">
  <xsl:call-template name="explicitType">
   <xsl:with-param name="elt" select="@name"/>
   <xsl:with-param name="typeDef" select="xsd:complexType"/>
   <xsl:with-param name="std" select="@type"/>
   <xsl:with-param name="anchor" select="@name"/>
  </xsl:call-template>
 </xsl:template>
 
 <xsl:template name="chooseClass">
  <xsl:choose>
    <xsl:when test="count(preceding-sibling::*)=0">element-syntax-1</xsl:when>
    <xsl:otherwise>element-syntax</xsl:otherwise>
   </xsl:choose>
 </xsl:template>
 
 <xsl:template name="explicitType">
  <xsl:param name="elt"/>
  <xsl:param name="typeDef"/>
  <xsl:param name="std"/>
  <xsl:param name="anchor"/>
  <xsl:variable name="model" select="$typeDef/xsd:complexContent/xsd:restriction/*[self::xsd:sequence or self::xsd:choice or self::xsd:group or self::xsd:all]">
  </xsl:variable>
   <a name="element-{$anchor}">
    <xsl:text>&lt;</xsl:text>
     <xsl:call-template name="eltname">
      <xsl:with-param name="name">
       <xsl:value-of select="$elt"/>
      </xsl:with-param>
     </xsl:call-template>    
   </a>   
     <xsl:apply-templates select="$typeDef/*/xsd:restriction/xsd:attribute"/>
   <xsl:apply-templates select="$typeDef/*/xsd:restriction/xsd:anyAttribute"/>
     <xsl:choose>
      <xsl:when test="$std">
       <!-- must be a simple type - - never happens? -->
       <xsl:variable name="localDef" select="$schemaProper/xsd:simpleType[@name=$std]"/>
       <xsl:text>&gt;</xsl:text>
<br/>
<em><xsl:text>&nbsp;&nbsp;Content: </xsl:text></em>
       <xsl:value-of select="$std"/>
       <xsl:text>&nbsp;:&nbsp;</xsl:text>
       <xsl:apply-templates select="$localDef"/>
       <br/>
       <xsl:text>&lt;/</xsl:text>
 <xsl:call-template name="eltname">
  <xsl:with-param name="name" select="$elt">
  </xsl:with-param>
 </xsl:call-template>
<xsl:text>&gt;</xsl:text>
      </xsl:when>
      <xsl:when test="not($model)">
       <br/><xsl:text>/&gt;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
       <xsl:apply-templates mode="top" select="$model"/>
       <xsl:text>&lt;/</xsl:text>
 <xsl:call-template name="eltname">
  <xsl:with-param name="name" select="$elt">
  </xsl:with-param>
 </xsl:call-template>
<xsl:text>&gt;</xsl:text>
      </xsl:otherwise>
     </xsl:choose>
   </xsl:template>

 <xsl:template name="eltname">
  <xsl:param name="name"/>
  <xsl:choose>
   <xsl:when test="starts-with($name,'!')">
    <xsl:value-of select="substring($name,2)"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$name"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

<xsl:template match="xsd:group|xsd:choice|xsd:all|xsd:sequence" mode="top">
<xsl:text>&gt;</xsl:text>
<br/>
<em><xsl:text>&nbsp;&nbsp;Content: </xsl:text></em>
<xsl:apply-templates select="." mode="model"/>
<br/>
</xsl:template>

<xsl:template match="xsd:group|xsd:choice|xsd:all|xsd:sequence" mode="model">
 <xsl:variable name="needParen" select="not(parent::xsd:group) or @minOccurs!='1' or @maxOccurs!='1'"/>
 <xsl:call-template name="group"/>
<xsl:if test="$needParen"><xsl:text>(</xsl:text></xsl:if>
<xsl:apply-templates mode="model"/>
<xsl:if test="$needParen"><xsl:text>)</xsl:text></xsl:if>
<xsl:call-template name="repeat"/>
</xsl:template>


 <xsl:template match="xsd:element" mode="model">
  <xsl:call-template name="group"/>
  <xsl:choose>
   <xsl:when test="@name">
    <xsl:call-template name="eltref">
     <xsl:with-param name="name" select="@name"/>
     <xsl:with-param name="inside" select="ancestor::xsd:element/@name"/>
     <xsl:with-param name="inModel" select="1"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:call-template name="eltref">
     <xsl:with-param name="name" select="substring-after(@ref,':')"/>
     <xsl:with-param name="inModel" select="1"/>
    </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
<xsl:call-template name="repeat"/>
</xsl:template>

 <xsl:template match="xsd:any" mode="model">
  <xsl:call-template name="group"/>
  <xsl:choose>
   <xsl:when test="@namespace='##any'">
    <em>{any}</em>
   </xsl:when>
   <xsl:otherwise>
    <em>{any with namespace: <xsl:value-of select="@namespace"/>}</em>
   </xsl:otherwise>
  </xsl:choose><xsl:call-template name="repeat"/></xsl:template>
 
 <xsl:template name="eltref">
  <xsl:param name="name"/>
  <xsl:param name="inside"/>
  <xsl:param name="inModel"/>
  <xsl:variable name="ref">
   <xsl:choose>
    <xsl:when test="$inside and $reprelts/@local[.=$inside]"><xsl:value-of select="$inside"/>::<xsl:value-of select="$name"/></xsl:when>
    <xsl:otherwise><xsl:value-of select="$name"/></xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="doc">
   <xsl:if test="not($inside or $name='schema' or $reprelts/@eltname[.=$name])">
    <xsl:value-of select="$datatypeURL"/>
   </xsl:if>
  </xsl:variable>
  <a href="{$doc}#element-{$ref}" class="eltref"><xsl:if test="not($inModel)">&lt;</xsl:if><xsl:value-of select="$name"/><xsl:if test="not($inModel)">></xsl:if></a>
 </xsl:template>
 
 <xsl:template match="eltref">
  <xsl:call-template name="eltref">
   <xsl:with-param name="name" select="@ref"/>
   <xsl:with-param name="inside">
    <xsl:value-of select="@inside"/>
   </xsl:with-param>
  </xsl:call-template>
 </xsl:template>

<xsl:template name="group">
<xsl:if test="position()>1">
<xsl:choose>
<xsl:when test="parent::xsd:sequence"><xsl:text>, </xsl:text></xsl:when>
<xsl:when test="parent::xsd:choice"><xsl:text> | </xsl:text></xsl:when>
<xsl:when test="parent::xsd:all"><xsl:text> &amp; </xsl:text></xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>

<xsl:template name="repeat">
  <xsl:choose>
   <xsl:when test="@minOccurs='1' and @maxOccurs='unbounded'">
    <xsl:text>+</xsl:text>
   </xsl:when>
   <xsl:when test="@minOccurs='0' and @maxOccurs='unbounded'">
    <xsl:text>*</xsl:text>
   </xsl:when>
   <xsl:when test="@minOccurs='0'">
    <xsl:text>?</xsl:text>
   </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template match="xsd:attribute[@use='prohibited']"/>
<xsl:template match="xsd:attribute[not(@use='prohibited')]">
 <xsl:variable name="aname">
  <xsl:choose>
   <xsl:when test="@name">
    <xsl:value-of select="@name"/>
   </xsl:when>
   <xsl:otherwise><xsl:value-of select="@ref"/></xsl:otherwise>
  </xsl:choose>
 </xsl:variable>
<br/>

<xsl:text>&nbsp;&nbsp;</xsl:text>
<xsl:choose>
<xsl:when test="@use='required'">
<b><xsl:value-of select="$aname"/></b>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$aname"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> = </xsl:text>
 <xsl:choose>
  <xsl:when test="@type">
   <xsl:variable name="type" select="@type"/>
 <xsl:variable name="localDef" select="$schemaProper/xsd:simpleType[@name=$type]"/>
 <xsl:choose>
  <xsl:when test="$localDef"><xsl:apply-templates select="$localDef"/></xsl:when>                                
  <xsl:otherwise>
   <xsl:variable name="localDef2" select="$dschemaProper/xsd:simpleType[@name=$type]"/>
   <xsl:choose>
    <xsl:when test="$localDef2/xsd:restriction/xsd:enumeration or $localDef2/xsd:union"><xsl:apply-templates select="$localDef2"/></xsl:when>
    <xsl:otherwise><a href="{$datatypeURL}#{@type}"><xsl:value-of select="$type"/></a></xsl:otherwise>
   </xsl:choose>
  </xsl:otherwise>
 </xsl:choose>
  </xsl:when>
  <xsl:when test="$aname='xml:lang'">
   <a href="{$datatypeURL}#language">language</a>
  </xsl:when>
  <xsl:when test="$aname='xpath'">
   <em>a subset of XPath expression, see below</em>
  </xsl:when>
  <xsl:otherwise>
</xsl:otherwise>
 </xsl:choose>
<xsl:apply-templates/>
 <xsl:if test="@use='default' or @use='fixed'">
  <xsl:text>&nbsp;:&nbsp;</xsl:text>
  <xsl:choose>
   <xsl:when test="@value=&quot;&quot;">
    <xsl:text>''</xsl:text>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="@value"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:if>
</xsl:template>
 
 
<xsl:template match="xsd:anyAttribute">
<br/>

<xsl:text>&nbsp;&nbsp;</xsl:text>
 <em>{any attributes<xsl:choose>
<xsl:when test="@namespace='##any'"></xsl:when>
                    <xsl:when test="@namespace='##other'"><!-- cheat for schemas -->
<xsl:text> with non-schema namespace</xsl:text>
                    </xsl:when>
                    <xsl:otherwise><xsl:text> with namespace: </xsl:text><xsl:value-of select="@namespace"/></xsl:otherwise>
</xsl:choose><xsl:text> . . .}</xsl:text></em>
</xsl:template>
 
 <xsl:template match="xsd:simpleType[xsd:restriction/xsd:enumeration]">
  <xsl:if test="xsd:restriction/xsd:enumeration[2]">(</xsl:if>
  <xsl:apply-templates select="xsd:restriction/xsd:enumeration"/>
  <xsl:if test="xsd:restriction/xsd:enumeration[2]">)</xsl:if>
 </xsl:template>
 
 <xsl:template match="xsd:simpleType[xsd:list]">
  <xsl:apply-templates select="xsd:list"/>
 </xsl:template>
 
 <xsl:template match="xsd:list[@itemType]">
 <xsl:variable name="type">
  <xsl:choose>
   <xsl:when test="starts-with(@itemType,'xs:')">
    <xsl:value-of select="substring-after(@itemType,':')"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="@itemType"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:variable>
 <xsl:variable name="localDef" select="$schemaProper/xsd:simpleType[@name=$type]"/>
  <xsl:text>List of </xsl:text><xsl:choose>
  <xsl:when test="$localDef"><xsl:apply-templates select="$localDef"/></xsl:when>                               
  <xsl:otherwise>
   <xsl:variable name="localDef2" select="$dschemaProper/xsd:simpleType[@name=$type]"/>
   <xsl:choose>
    <xsl:when test="$localDef2/xsd:restriction/xsd:enumeration or $localDef2/xsd:union"><xsl:apply-templates select="$localDef2"/></xsl:when>
    <xsl:otherwise><a href="{$datatypeURL}#{$type}"><xsl:value-of select="$type"/></a></xsl:otherwise>
   </xsl:choose>
  </xsl:otherwise>
 </xsl:choose>
 </xsl:template>
 
 <xsl:template match="xsd:list[xsd:simpleType]">
  <xsl:text>List of </xsl:text>
  <xsl:apply-templates select="xsd:simpleType"/>
 </xsl:template>
 
 <xsl:template match="xsd:simpleType[xsd:union]">
  (<xsl:apply-templates select="xsd:union"/>)
 </xsl:template>
 
 <xsl:template match="xsd:union">
  <xsl:if test="@memberTypes"><xsl:variable name="type" select="substring-after(@memberTypes,':')"/>
 <xsl:variable name="localDef" select="$schemaProper/xsd:simpleType[@name=$type]"/>
  <xsl:choose>
  <xsl:when test="$localDef"><xsl:apply-templates select="$localDef"/></xsl:when>                               
  <xsl:otherwise>
   <xsl:variable name="localDef2" select="$dschemaProper/xsd:simpleType[@name=$type]"/>
   <xsl:choose>
    <xsl:when test="$localDef2/xsd:restriction/xsd:enumeration or $localDef2/xsd:union"><xsl:apply-templates select="$localDef2"/></xsl:when>
    <xsl:otherwise><a href="{$datatypeURL}#{$type}"><xsl:value-of select="$type"/></a></xsl:otherwise>
   </xsl:choose>
  </xsl:otherwise>
 </xsl:choose></xsl:if>
  <xsl:if test="xsd:simpleType and @memberTypes"><xsl:text> | </xsl:text></xsl:if>
  <xsl:apply-templates select="xsd:simpleType[1]"/>
  <xsl:for-each select="xsd:simpleType[position()>1]">
   <xsl:text> | </xsl:text><xsl:apply-templates select="."/>
  </xsl:for-each>
 </xsl:template>
 <xsl:template match="xsd:simpleType[xsd:annotation/xsd:documentation and not(xsd:restriction/xsd:enumeration)]" priority="0.1">
  <!-- This is a hack to cope with utility types with no real definition -->
  <em><xsl:value-of select="xsd:annotation/xsd:documentation[1]"/></em>
 </xsl:template>

<xsl:template match="xsd:enumeration">
<xsl:if test="position()>1"> | </xsl:if>
<var><xsl:value-of select="@value"/></var>
</xsl:template>

<xsl:template match="constant">
<xsl:if test="position()>1"> | </xsl:if>
<xsl:text>"</xsl:text>
<xsl:value-of select="@value"/>
<xsl:text>"</xsl:text>
</xsl:template>

 <xsl:template match="schemaComp">
  <table class="schemaComp" border="1">
   <thead>
    <tr>
     <th><strong><xsl:choose><xsl:when test="@id"><a name="{@id}"><xsl:value-of select="head"/></a></xsl:when><xsl:otherwise><xsl:value-of select="head"/></xsl:otherwise></xsl:choose></strong></th>
    </tr>
   </thead>
   <tbody>
    <tr>
     <td>
      <xsl:apply-templates select="pvlist"/>
     </td>
    </tr>
   </tbody>
  </table>
 </xsl:template>
 
 <xsl:template match="pvlist">
    <table border="0">
       <thead>
        <tr>
         <th align="left">Property</th>
         <th align="left">Value</th>
        </tr>
       </thead>
       <tbody valign="top">
        <xsl:apply-templates select="pvpair"/>
       </tbody>
      </table>
 </xsl:template>
 
 <xsl:template match="pvpair">
  <tr>
   <td><xsl:call-template name="propref">
   <xsl:with-param name="ob">{</xsl:with-param>
   <xsl:with-param name="cb">}</xsl:with-param>
       </xsl:call-template></td>
   <td>
    <xsl:apply-templates/>
   </td>
  </tr>
 </xsl:template>

<xsl:template match="restrictCases">
  <table class="restricts" border="2">
   <thead>
    <tr>
     <th/>
     <th><strong>Base Particle</strong></th>
    </tr>
   </thead>
   <tbody>
    <tr>
     <td>
<strong>Der- ived Part- icle</strong>
     </td>
     <td>
      <table border="1">
       <thead>
        <tr>
         <th/>
         <th>elt</th>
         <th>any</th>
         <th>all</th>
         <th>choice</th>
         <th>sequence</th>
        </tr>
       </thead>
       <tbody><xsl:apply-templates select="restrict"/></tbody>
      </table>
     </td>
    </tr>
   </tbody>
  </table>
 </xsl:template>
 
 <xsl:template match="restrict">
  <tr>
   <th><xsl:value-of select="@case"/></th>
   <td>
    <xsl:call-template name="rcell">
     <xsl:with-param name="val" select="elt"/>
    </xsl:call-template>
   </td>
   <td>
    <xsl:call-template name="rcell">
     <xsl:with-param name="val" select="any"/>
    </xsl:call-template>
   </td>
   <td>
    <xsl:call-template name="rcell">
     <xsl:with-param name="val" select="all"/>
    </xsl:call-template>
   </td>
   <td>
    <xsl:call-template name="rcell">
     <xsl:with-param name="val" select="choice"/>
    </xsl:call-template>
   </td>
   <td>
    <xsl:call-template name="rcell">
     <xsl:with-param name="val" select="seq"/>
    </xsl:call-template>
   </td>
  </tr>
 </xsl:template>
 
 <xsl:template name="rcell">
  <xsl:param name="val"/>
  <xsl:choose>
   <xsl:when test="$val='Forbidden'">
    <xsl:text>Forbidden</xsl:text>
   </xsl:when>
   <xsl:otherwise><a href="#rcase-{$val}"><xsl:value-of select="$val"/></a></xsl:otherwise>
  </xsl:choose>  
 </xsl:template>
<!--* CMSMcQ:  see if I can work on olist here ...
    *-->
<xsl:template match="constraintnote//olist|propmap//olist|olist[.//item[@id]]">
 <xsl:choose>
  <xsl:when test="@role='and'"><b>all</b> of the following must be true:</xsl:when>
  <xsl:when test="@role='andval'"><b>all</b> of the following:</xsl:when>
  <xsl:when test="@role='andtest'"><b>all</b> of the following are true</xsl:when>
  <xsl:when test="@role='And'"><b>All</b> of the following must be true:</xsl:when>
  <xsl:when test="@role='or'"><b>one</b> of the following must be true:</xsl:when>
  <xsl:when test="@role='orval'"><b>one</b> of the following:</xsl:when>
  <xsl:when test="@role='ortest'"><b>one</b> of the following is true</xsl:when>
  <xsl:when test="@role='Or'"><b>One</b> of the following must be true:</xsl:when>
  <xsl:when test="@role='case'">the appropriate <b>case</b> among the following
must be true:</xsl:when>
  <xsl:when test="@role='Case'">The appropriate <b>case</b> among the following
must be true:</xsl:when>
  <xsl:when test="@role='caseval'">the appropriate <b>case</b> among the following:</xsl:when>
  <xsl:when test="@role='Caseval'">The appropriate <b>case</b> among the following:</xsl:when>
 </xsl:choose>
 <div class="constraintlist">
  <xsl:apply-templates/>
 </div>
</xsl:template>

<xsl:template match="constraintnote//olist/item|propmap//olist/item|olist[item[@id]]/item">
 <div class="clnumber">
  <xsl:number level="multiple" count="item" from="constraintnote|propmap|div3|div2" format="1"/>
  <xsl:choose>
        <xsl:when test="@id">
         <a name="{@id}"><xsl:text> </xsl:text></a>
        </xsl:when>
        <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
       </xsl:choose>
  <xsl:apply-templates/>
 </div>
</xsl:template>

 
 <xsl:template match="olist[@role='case' or @role='Case' or @role='caseval' or @role='Caseval']/item">
  <div class="clnumber">
  <xsl:number level="multiple" count="item" from="constraintnote|propmap" format="1"/>
       <xsl:choose>
        <xsl:when test="@id">
         <a name="{@id}"><xsl:text> </xsl:text></a>
        </xsl:when>
        <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
       </xsl:choose>
       
  <xsl:choose>
   <xsl:when test="p[@role='if']"><b>If </b><xsl:for-each select="p[@role='if']">
<xsl:apply-templates/>
</xsl:for-each>, <b>then </b><xsl:for-each select="p[@role='then']">
<xsl:apply-templates/>
</xsl:for-each></xsl:when>
   <xsl:otherwise><b>otherwise </b><xsl:for-each select="p[@role='otherwise']">
<xsl:apply-templates/>
</xsl:for-each>
   </xsl:otherwise>
  </xsl:choose>
 </div> 
 </xsl:template>
 
 <xsl:template match="clauseref">
  <xsl:text>clause </xsl:text>
  <a href="#{@ref}"><xsl:for-each select="id(@ref)"><xsl:number level="multiple" count="item" from="constraintnote|propmap|div3|div2" format="1"/></xsl:for-each></a>
 </xsl:template>
 
 <!-- hack to tabulate outcomes -->
 <xsl:template match="div2[@id='outcome-src']">
  <xsl:apply-templates/>
  <dl>   
  <xsl:for-each select="$cnotes[@type='src']|$dcnotes[@type='src']">
   <xsl:sort select="@id"/>
   <xsl:variable name="id" select="@id"/>
   <dt><xsl:value-of select="@id"/></dt>
   <dd><a>
     <xsl:attribute name="href">
      <xsl:if test="$dcnotes[@id=$id]"><xsl:value-of select="$datatypeURL"/></xsl:if>#<xsl:value-of select="@id"/></xsl:attribute>
     <xsl:value-of select="head"/></a></dd>
  </xsl:for-each>
  </dl>
 </xsl:template>
 
 <xsl:template match="div2[@id='outcome-cos']">
  <xsl:apply-templates/>
  <dl>   
  <xsl:for-each select="$cnotes[@type='cos']|$dcnotes[@type='cos']">
   <xsl:sort select="@id"/>
   <xsl:variable name="id" select="@id"/>
   <dt><xsl:value-of select="@id"/></dt>
   <dd><a>
     <xsl:attribute name="href">
      <xsl:if test="$dcnotes[@id=$id]"><xsl:value-of select="$datatypeURL"/></xsl:if>#<xsl:value-of select="@id"/></xsl:attribute>
     <xsl:value-of select="head"/></a></dd>
  </xsl:for-each>
  </dl>
 </xsl:template>

 <xsl:template match="div2[@id='validation_failures']">
  <xsl:apply-templates/>
  <dl>   
  <xsl:for-each select="$cnotes[@type='cvc']|$dcnotes[@type='cvc']">
   <xsl:sort select="@id"/>
   <xsl:variable name="id" select="@id"/>
   <dt><xsl:value-of select="@id"/></dt>
   <dd><a>
     <xsl:attribute name="href">
      <xsl:if test="$dcnotes[@id=$id]"><xsl:value-of select="$datatypeURL"/></xsl:if>#<xsl:value-of select="@id"/></xsl:attribute>
     <xsl:value-of select="head"/></a></dd>
  </xsl:for-each>   
  </dl>
 </xsl:template>
 
 <xsl:template match="div2[@id='PSVI_contributions']">
  <xsl:apply-templates/>
  <dl>   
  <xsl:for-each select="$cnotes[@type='sic']|$dcnotes[@type='sic']">
   <xsl:sort select="@id"/>
   <xsl:variable name="id" select="@id"/>
   <dt><xsl:value-of select="@id"/></dt>
   <dd><a>
     <xsl:attribute name="href">
      <xsl:if test="$dcnotes[@id=$id]"><xsl:value-of select="$datatypeURL"/></xsl:if>#<xsl:value-of select="@id"/></xsl:attribute>
     <xsl:value-of select="head"/></a></dd>
  </xsl:for-each>   
  </dl>
 </xsl:template>
 
 <xsl:template match="ednote[@role='pf']">
		<blockquote>
		<p><b>Ed. Note: </b><SPAN STYLE="color: red">Priority Feedback Request</SPAN><br/><xsl:apply-templates/></p>
		</blockquote>
	</xsl:template>
 
  <!-- hack to tabulate termdefs -->
 <xsl:template match="ednote[@role='glossary']">
  <dl>   
  <xsl:for-each select="//termdef">
   <xsl:sort select="@term"/>
   <dt>
<a href="#{@id}"><xsl:value-of select="@term"/></a>
</dt>
   <dd>
<xsl:apply-templates/>
</dd>
  </xsl:for-each>
  </dl>
 </xsl:template>
</xsl:stylesheet>
