<?xml version='1.0'?>
<!-- spec.xsl 19990506 HST -->
<!-- Style Sheet for the XML Schema Working Drafts -->
<!-- Original written by Eduardo Gutentag -->
<!-- Modified by Paul Biron, Henry Thompson, Murray Maloney -->
<!-- **** NOTE THIS VERSION IS FOR XSL per January WD, NOT April WD -->
<!DOCTYPE xsl:stylesheet [

<!ENTITY lt     "<"> 
<!ENTITY gt     ">"> 
<!ENTITY xmlpio "'&lt;?xml'">
<!ENTITY pic    "'?>'">
<!ENTITY br     "\n">
<!ENTITY cellback '#c0d9c0'>
<!ENTITY mdash  "--"> <!-- &#x2014, but nsgmls doesn't grok hex -->
<!ENTITY copy   "&#169;">
<!ENTITY nbsp   "&#160;">
]>
<!-- XSL Style sheet, DTD omitted -->
<xsl:stylesheet xmlns:xsl='http://www.w3.org/TR/WD-xsl' xmlns='http://www.w3.org/TR/REC-html40' result-ns=''>

<xsl:id attribute='id'/>

<!-- **************************************************************** -->
<!-- Inclusions -->
<!-- **************************************************************** -->

<!-- **************************************************************** -->
<!-- Basic framework to format the XML Schema spec -->
<!-- **************************************************************** -->
        <xsl:template match='spec'>
                <html>
                  <head>
                    <title><xsl:value-of select='header/title'/></title>
                    <style type='text/css'>
                        BODY {  margin: 2em 1em 2em 70px;  
                                font-family: Arial, sans-serif;    
                                color: black;    
                                background-color: white;    
                                background-image: url(http://www.w3.org/StyleSheets/TR/WD.gif);
                                background-position: top left;    
                                background-attachment: fixed;    
                                background-repeat: no-repeat;}
                        H1, H2, H3 {      
                                text-align: left;    
                                font-family: Tahoma, Verdana, "Myriad Web", Syntax, sans-serif;
                                font-weight: normal;    
                                color: #0050B2; }
                        P {     margin-top: 0.6em;      
                                margin-bottom: 0.6em;}
                        PRE {   font-family: monospace 
                                margin-left: 2em }  
                        DT, DD { margin-top: 0; margin-bottom: 0 }
                        DT {    font-weight: bold }  
                        A:hover { background: #FFA }    
                        .termdef {color: rgb(133,0,033)}
                    </style>
                  </head>

                  <body bgcolor='#ffffff'>
                    <div class="head">
                    <p>
                    <a href="http://www.w3.org/">
                    <img src='http://www.w3.org/pub/WWW/Icons/WWW/w3c_home' 
                         alt='W3C Logo' border='0' align='left' height="48" width="72" 
                         style="float: left; border: none"/></a></p>

                    <p class='w3c-designation' align='right' style="text-align:right">
                        <strong>
                        <xsl:value-of select='header/w3c-designation'/>
                        </strong>
                    </p>
                    <p class="hide"><br clear="left" /></p>
                    <h1 class='title' align='center'>
                        <xsl:value-of select='header/title'/>
                    </h1>
                    <p class="hide"><br clear="left" /></p>
                    <h3 class='w3c-doctype' align='center'>
                        <xsl:value-of select='header/w3c-doctype'/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select='header/pubdate/day'/>
                        <xsl:text>-</xsl:text>
                        <xsl:value-of select='header/pubdate/month'/>
                        <xsl:text>-</xsl:text>
                        <xsl:value-of select='header/pubdate/year'/>
                    </h3>
                    </div>
                    <xsl:apply-templates/>

                  </body>

                </html>

        </xsl:template>

<!-- **************************************************************** -->
<!-- Prologue -->
<!-- **************************************************************** -->
        <xsl:template match='notice'>
          <blockquote class='notice'>
            <xsl:apply-templates/>
          </blockquote>
        </xsl:template>
  
<!-- **************************************************************** -->
        <xsl:template match='publoc'>
            <div class='publoc'>
                <h4>This version</h4>
                <p><xsl:apply-templates/></p>
            </div>
        </xsl:template>
  
        <xsl:template match='latestloc'>
            <div class='publoc'>
                <h4>Latest version:</h4>
                <p><xsl:apply-templates/></p>
            </div>
        </xsl:template>

        <xsl:template match='prevlocs'>
            <div class='publoc'>
                <h4>Previous version:</h4>
                <p><xsl:apply-templates/></p>
            </div>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='authlist'>
             <div class='authlist'>
                <h4>Editors:</h4>
                <p><xsl:apply-templates/></p>
             </div>
             <xsl:invoke macro='copyright'></xsl:invoke>
        </xsl:template>

        <xsl:template match='author'>
                <xsl:apply-templates/>
                <xsl:if test='@part'>
                        [<xsl:value-of select='@part'/>]
                </xsl:if>
                <br/>
        </xsl:template>

        <xsl:template match='author/name'>
                <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='author/affiliation'>
                <xsl:text> (</xsl:text>
                        <xsl:apply-templates/>
                <xsl:text>) </xsl:text>
        </xsl:template>

        <xsl:template match='author/email'>
                <a href='{@href}'>
                        <xsl:text>&lt;</xsl:text>
                                <xsl:apply-templates/>
                        <xsl:text>&gt;</xsl:text>
                </a>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='abstract'>
             <div class='abstract'>
               <h2><xsl:text>Abstract</xsl:text></h2>
               <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='status'>
             <div class='status'>
                <h2><xsl:text>Status of this Document</xsl:text></h2>
                <xsl:apply-templates/>
             </div>
        </xsl:template>
                
<!-- **************************************************************** -->
<!-- Real body work -->
<!-- **************************************************************** -->
  
        <xsl:template match='body'>
             <div class='toc'>
               <h2><xsl:text>Table of Contents</xsl:text></h2>
               <xsl:invoke macro='toc'><br/></xsl:invoke>
             </div>
             <div class='chapters'>
               <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='back'>
             <hr/>
             <div class='appendices'>
               <h1><xsl:text>Appendices</xsl:text></h1>
               <xsl:apply-templates/>
             </div>
             <div class='issues'>
               <xsl:invoke macro='open_issues'/>
             </div>
        </xsl:template>

<!-- **************************************************************** -->
<!-- This is a rather perverse way of dealing with the divs (should
     apply-templates in the div, then have a template rule for each
     div/head) but it's a good way of playing with modes... -->

        <xsl:template match='div1|inform-div1'>
             <div class='div1'>
                <h2>
                  <xsl:invoke macro='insertID'></xsl:invoke>
                  <xsl:choose>
                      <xsl:when test='ancestor(body)'>
                          <xsl:number format='1. '/>
                      </xsl:when>
                      <xsl:when test='ancestor(back)'>
                          <xsl:number format='A. ' count='div1|inform-div1'/>
                      </xsl:when>
                  </xsl:choose>
                  <xsl:apply-templates select='head' mode='header'/>
                </h2>
                <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='div2'>
             <div class='div2'>
                <h3>
                  <xsl:invoke macro='insertID'></xsl:invoke>
                  <xsl:choose>
                      <xsl:when test='ancestor(back)'>
                        <xsl:number level='multi' count='div1|div2' format='A.1 '/>
                      </xsl:when>
                      <xsl:when test='ancestor(body)'>
                        <xsl:number level='multi' count='div1|div2' format='1.1 '/>
                      </xsl:when>
                  </xsl:choose>
                  <xsl:apply-templates select='head' mode='header'/>
                </h3>
                <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='div3'>
             <div class='div3'>
                <h4>
                  <xsl:invoke macro='insertID'></xsl:invoke>
                  <xsl:choose>
                      <xsl:when test='ancestor(back)'>
                        <xsl:number level='multi' count='div1|div2|div3' format='A.1 '/>
                      </xsl:when>
                      <xsl:when test='ancestor(body)'>
                        <xsl:number level='multi' count='div1|div2|div3' format='1.1 '/>
                      </xsl:when>
                  </xsl:choose>
                  <xsl:apply-templates select='head' mode='header'/>
                </h4>
                <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='div4'>
             <div class='div4'>
                <h5>
                  <xsl:invoke macro='insertID'></xsl:invoke>
                  <xsl:choose>
                      <xsl:when test='ancestor(back)'>
                        <xsl:number level='multi' count='div1|div2|div3|div4' format='A.1.1 '/>
                      </xsl:when>
                      <xsl:when test='ancestor(body)'>
                        <xsl:number level='multi' count='div1|div2|div3|div4' format='1.1.1 '/>
                      </xsl:when>
                  </xsl:choose>
                  <xsl:apply-templates select='head' mode='header'/>
                </h5>
                <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='head' priority='1'></xsl:template>

        <xsl:template match='head' mode='header'>
             <xsl:apply-templates/>
        </xsl:template>


<!-- **************************************************************** -->
<!-- Blocks -->
<!-- **************************************************************** -->
        <xsl:template match='p'>
                <p><xsl:apply-templates/></p>
        </xsl:template>

        <xsl:template match='constraintnote/p'>
                <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='issue/p'>
            <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='item/p' priority='1'>
                <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='note/p'>
            <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='notice/p[first-of-type()]'>
            <p>
            <B><xsl:text>Notice:&nbsp;&nbsp;</xsl:text></B>
            <xsl:apply-templates/>
            </p>
        </xsl:template>
  
        <xsl:template match='quote'>
                <blockquote>
                        <xsl:apply-templates/>
                </blockquote>
        </xsl:template>

<!-- **************************************************************** -->
<!-- Lists -->
<!-- **************************************************************** -->
        <xsl:template match='blist'>
          <dl class='blist'>
            <xsl:apply-templates/>
          </dl>
        </xsl:template>

        <xsl:template match='blist'>
             <xsl:for-each select='bibl'>
               <xsl:sort select='@key'/>
                 <dt><a name='{@id}'><xsl:value-of select='@key'/></a></dt>
                 <dd><table><tr><td><xsl:apply-templates/></td></tr></table></dd>
                </xsl:for-each>
        </xsl:template>

        <xsl:template match='glist'>
             <dl class='glist'>
               <xsl:apply-templates/>
             </dl>
        </xsl:template>

        <xsl:template match='olist'>
             <ol>
               <xsl:apply-templates/>
             </ol>
        </xsl:template>

        <xsl:template match='orglist'>
             <ul class='orglist'>
               <xsl:apply-templates/>
             </ul>
        </xsl:template>

        <xsl:template match='slist'>
             <ul class='slist'>
               <xsl:apply-templates/>
             </ul>
        </xsl:template>

        <xsl:template match='ulist'>
             <ul>
               <xsl:apply-templates/>
             </ul>
        </xsl:template>

<!-- **************************************************************** -->
<!-- Lists members -->
<!-- **************************************************************** -->
<!-- **************************************************************** -->
        <xsl:template match='def'>
           <dd class='def'>
              <xsl:apply-templates mode='tight'/>
           </dd>
        </xsl:template>

        <xsl:template match='item'>
             <li>
                <xsl:apply-templates/>
             </li>
        </xsl:template>

        <xsl:template match='label'>
             <dt class='label'>
                <xsl:apply-templates/>
             </dt>
        </xsl:template>

        <xsl:template match='orglist/member'>
             <li class='member'><xsl:apply-templates/></li>
        </xsl:template>
        
        <xsl:template match='sitem'>
              <li>
                <xsl:apply-templates/>
              </li>
        </xsl:template>

<!-- **************************************************************** -->

        <xsl:template match='*' mode='tight'>
          <xsl:apply-templates select='.'/>
        </xsl:template>
    
        <xsl:template match='p[first-of-any()]' mode='tight'>
          <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='p[not(first-of-any())]' mode='tight'>
          <p/>
          <xsl:apply-templates/>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='ednote'>
             <blockquote class='ednote'>
             <p><b>Ed. Note: </b><xsl:apply-templates/></p>
             </blockquote>
        </xsl:template>

        <xsl:template match='edtext'>
             <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='ednote/name'>
             <em class='name'>
               <xsl:text>(</xsl:text>
               <xsl:apply-templates/>
               <xsl:text>)</xsl:text>
             </em>
        </xsl:template>

        <xsl:template match='ednote/date'>
             <em class='date'>
               <xsl:apply-templates/>
               <xsl:text>): </xsl:text>
             </em>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='issue'>
             <xsl:invoke macro='insertID'></xsl:invoke>
             <blockquote class='issue'>
               <p>
                 <b>Issue (<xsl:value-of select='@id'/>): </b>
                 <xsl:apply-templates/>
               </p>
             </blockquote>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='note'>
        <blockquote class='note'>
                <b>NOTE: </b>
                <xsl:apply-templates/>
        </blockquote>
        </xsl:template>

<!-- **************************************************************** -->
<!-- 'Choose' cases for XML Schema Part 1 spec  -->
        <xsl:template match='constraintnote'>
             <div class='constraintnote'>
               <a name='{@id}'></a>
               <p><b>
                 <xsl:choose>
                      <xsl:when test='.[@type=&apos;cos&apos;]'>
                          <xsl:text>Constraint on Schemas:  </xsl:text>
                      </xsl:when>
                      <xsl:when test='.[@type=&apos;svc&apos;]'>
                          <xsl:text>Schema-validity Constraint:  </xsl:text>
                      </xsl:when>
                      <xsl:when test='.[@type=&apos;sic&apos;]'>
                          <xsl:text>Schema Information Set Contribution:  </xsl:text>
                      </xsl:when>
                      <xsl:otherwise>Constraint:  </xsl:otherwise>
                 </xsl:choose>
               <xsl:value-of select='head'/>
               </b><br/>
               <xsl:apply-templates/>
               </p>
             </div>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='vcnote'>
            <div class='vcnote'>
                <a name='{@id}'></a>
                <p><b><xsl:text>Validity Constraint: </xsl:text>
                      <xsl:value-of select='head'/></b></p>
                <xsl:apply-templates/>
            </div>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='wfcnote'>
            <div class='wfcnote'>
                <a name='{@id}'></a>
                <p><b>Well Formedness Constraint: <xsl:value-of select='head'/></b></p>
                <xsl:apply-templates/>
            </div>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='eg'>
        <div class='eg'>
        <table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'>
        <tr><td>
              <xsl:choose>
                <xsl:when test='.[@role=&apos;error&apos;]'>
                  <pre style='color: red'>
                    <xsl:apply-templates/>
                  </pre>
                </xsl:when>
                <xsl:otherwise>
                  <pre>
                     <xsl:apply-templates/>
                  </pre>
                </xsl:otherwise>
              </xsl:choose>
        </td></tr>
        </table>
        </div>
        </xsl:template>

<!-- HST: special treatment for special common case:  eg inside note -->
        <xsl:template match='note[@role="example"]|note[eg]'>
          <blockquote class='example'>
           <table border='1'>
                  <tbody>
                    <tr align='left'>
                      <td><strong><font color='blue'>Example</font></strong></td>
                    </tr>
                    <tr>
                      <td>
                        <table border='0'>
                          <tbody><xsl:apply-templates/></tbody>
                        </table>
                      </td>
                    </tr>
                 </tbody>
             </table>
           </blockquote>
         </xsl:template>

<!-- **************************************************************** -->
<!-- Inlines -->
<!-- **************************************************************** -->
        <xsl:template match='B'>
                <b><xsl:apply-templates/></b>
        </xsl:template>
 
        <xsl:template match='code'>
             <code>
               <xsl:apply-templates/>
             </code>
        </xsl:template>

        <xsl:template match='emph'>
                <i><xsl:apply-templates/></i>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='orglist/member/name'>
             <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match='orglist/member/role'>
             <xsl:text> (</xsl:text>
             <xsl:apply-templates/>
             <xsl:text>)</xsl:text>
        </xsl:template>

        <xsl:template match='orglist/member/affiliation'>
             <xsl:text> -- </xsl:text>
             <xsl:apply-templates/>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='kw'>
             <span class='kw'>
               <a name='{@id}'><xsl:apply-templates/></a>
             </span>
        </xsl:template>
        
        <xsl:template match='termdef'>
             <span class='termdef'>
               <a name='{@id}'>[Definition: ] </a>
               <xsl:apply-templates/>
             </span>
        </xsl:template>
        
        <xsl:template match='term'>
             <b class='term'><xsl:apply-templates/></b>
        </xsl:template>

<!-- **************************************************************** -->
<!-- References -->
<!-- **************************************************************** -->
        <xsl:template match='p/loc' priority='1'>
                <a class='loc' href='{@href}'><xsl:apply-templates/></a>
        </xsl:template>

        <xsl:template match='loc'>
                <a class='loc' href='{@href}'><xsl:apply-templates/></a>
                <br/>
        </xsl:template>

       <xsl:template match='publoc/loc|latestloc/loc|prevlocs/loc'>
                <a class='loc' href='{@href}'><xsl:apply-templates/></a>
                <br/>
        </xsl:template>
 
        <xsl:template match='bibref'>
                <a class='bibref' href='#{@ref}'>
                <xsl:text>[</xsl:text>
                <xsl:value-of select='id(@ref)/@key'/>
                <xsl:apply-templates/>
                <xsl:text>]</xsl:text>
                </a>
        </xsl:template>

        <xsl:template match='specref'>
                <a class='specref' href='#{@ref}'>
                <xsl:value-of select='id(@ref)/head'/>
                <xsl:apply-templates/>
                </a>
        </xsl:template>

        <xsl:template match='termref'>
                <a class='termref' href='#{@def}'>
                <xsl:apply-templates/>
                </a>
        </xsl:template>

        <xsl:template match='titleref'>
                <a class='titleref' href='#{@href}'>
                <xsl:apply-templates/>
                </a>
        </xsl:template>

        <xsl:template match='xnt'>
                <a class='xnt' href='{@href}'><xsl:apply-templates/></a>
        </xsl:template>

        <xsl:template match='xspecref'>
                <a class='xspcref' href='{@href}'><xsl:apply-templates/></a>
        </xsl:template>

        <xsl:template match='xtermref'>
                <a class='xtermref' href='{@href}'><xsl:apply-templates/></a>
        </xsl:template>

<!-- **************************************************************** -->
<!-- Tables -->
<!-- **************************************************************** -->
        <xsl:template match='table'>
          <table>
           <xsl:if test='@border'>
            <xsl:attribute name='border'><xsl:value-of select='@border'/></xsl:attribute>
           </xsl:if>
           <xsl:if test='@cellpadding'>
            <xsl:attribute name='cellpadding'><xsl:value-of select='@cellpadding'/></xsl:attribute>
           </xsl:if>
           <xsl:if test='@align'>
            <xsl:attribute name='align'><xsl:value-of select='@align'/></xsl:attribute>
           </xsl:if>
                 <xsl:apply-templates/>
          </table>
        </xsl:template>

        <xsl:template match='thead'>
             <thead><xsl:apply-templates/></thead>
        </xsl:template>

        <xsl:template match='tbody'>
             <tbody><xsl:apply-templates/></tbody>
        </xsl:template>

        <xsl:template match='col'>
            <xsl:element name='col'>
              <xsl:if test='@align'>
                <xsl:attribute name='align'>
                    <xsl:value-of select='@align'/>
                </xsl:attribute>
              </xsl:if>
            </xsl:element>
        </xsl:template>

        <xsl:template match='tr'>
             <tr>
              <xsl:if test='@align'>
               <xsl:attribute name='align'><xsl:value-of select='@align'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@valign'>
               <xsl:attribute name='valign'><xsl:value-of select='@valign'/></xsl:attribute>
              </xsl:if>
                 <xsl:apply-templates/>
             </tr>
        </xsl:template>

        <xsl:template match='th'>
            <th>
              <xsl:if test='@bgcolor'>
               <xsl:attribute name='bgcolor'><xsl:value-of select='@bgcolor'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@rowspan'>
               <xsl:attribute name='rowspan'><xsl:value-of select='@rowspan'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@colspan'>
               <xsl:attribute name='colspan'><xsl:value-of select='@colspan'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@align'>
               <xsl:attribute name='align'><xsl:value-of select='@align'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@valign'>
               <xsl:attribute name='valign'><xsl:value-of select='@valign'/></xsl:attribute>
              </xsl:if>
                <xsl:apply-templates/>
            </th>
        </xsl:template>

        <xsl:template match='td'>
             <td>
              <xsl:if test='@bgcolor'>
               <xsl:attribute name='bgcolor'><xsl:value-of select='@bgcolor'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@rowspan'>
               <xsl:attribute name='rowspan'><xsl:value-of select='@rowspan'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@colspan'>
               <xsl:attribute name='colspan'><xsl:value-of select='@colspan'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@align'>
               <xsl:attribute name='align'><xsl:value-of select='@align'/></xsl:attribute>
              </xsl:if>
              <xsl:if test='@valign'>
               <xsl:attribute name='valign'><xsl:value-of select='@valign'/></xsl:attribute>
              </xsl:if>
                 <xsl:apply-templates/>
             </td>
        </xsl:template>


<!-- **************************************************************** -->
<!-- Productions -->
<!-- **************************************************************** -->
        <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/></tbody>
                      </table>
                    </td>
                  </tr>
                </tbody>
              </table>
              </div>
        </xsl:template>

        <xsl:template match='prodgroup'>
             <div class='prodgroup'>
                <xsl:apply-templates/>
             </div>
        </xsl:template>

        <xsl:template match='prod'>
         <tr valign='top' align='right'>
          <xsl:apply-templates/>
         </tr>
        </xsl:template>

        <xsl:template match='lhs'>
             <td align='right' valign='top'>
              <a class='prod' name='{ancestor(prod)/@id}'/>
                 <xsl:choose>
                 <!-- Conditional on not being inside recap/prefig: HST-->
                   <xsl:when test='ancestor(prod[not(@role="prefig")])'>
                        <code>
                          <xsl:number from='body' level='any' format='[1] ' count='lhs[ancestor(prod[not(@role="prefig")])]'/>
                         </code>
                   </xsl:when>
                 </xsl:choose>
              </td>
              <td align='right'>
                <code>
                  <xsl:apply-templates/>
                </code>
              </td>
              <td align='right' valign='top'>
                <code>
                  <xsl:text> ::= </xsl:text>
                </code>
              </td>
        </xsl:template>

        <xsl:template match='rhs[first-of-type()]'>
                <xsl:invoke macro='rhs'>
                </xsl:invoke>
        </xsl:template>

        <xsl:template match='rhs[not(first-of-type())]'>
        <tr>
                <td></td><td></td><td></td>
                        <xsl:choose>
                        <xsl:when test='next-element(vc)'>
                                <xsl:invoke macro='rhs_next_vc'/>
                        </xsl:when>
                        <xsl:when test='next-element(wfc)'>
                                <xsl:invoke macro='rhs_next_wfc'/>
                        </xsl:when>
                        <xsl:when test='next-element(constraint)'>
                                <xsl:invoke macro='rhs_next_c'/>
                        </xsl:when>
                        <xsl:otherwise>
                                        <xsl:invoke macro='rhs'/>
                        </xsl:otherwise>
                        </xsl:choose>
                </tr>
        </xsl:template>


<!-- **************************************************************** -->
<!-- Pre-terminals for abstract productions -->
<!-- **************************************************************** -->
         <xsl:template match='pt'>
           <i><xsl:apply-templates/></i>
         </xsl:template>

<!-- Allow content to sub for 'def' -->
        <xsl:template match='nt'>
              <xsl:choose>
                <xsl:when test='@def'>
                     <a class='nt' href='#{@def}'><xsl:apply-templates/></a> 
                </xsl:when>
                <xsl:otherwise>
                   <a class='nt'>
                     <xsl:attribute name='href'>#nt-<xsl:value-of select='.'/></xsl:attribute>
                     <xsl:apply-templates/>
                   </a>
                </xsl:otherwise>
             </xsl:choose>
        </xsl:template>


<!-- com on RHS added for XML Schema -->
        <xsl:template match='rhs/com'>
             <i class='com'><xsl:apply-templates/></i>
        </xsl:template>

        <xsl:template match='prod/com'>
             <td align='left'>
               <code class='com'>
                 <xsl:text>/*</xsl:text>
                 <xsl:apply-templates/>
                 <xsl:text>*/</xsl:text>
               </code></td>
        </xsl:template>

<!-- **************************************************************** -->
<!-- **************************************************************** -->
        <xsl:template match='vc' mode='next'>
          <td></td>
          <td align='left'>
              <code class='vc'>
                <xsl:text>[&nbsp;VC:&nbsp;</xsl:text>
                <a href='#{@def}'>
                        <xsl:value-of select='id(@def)/head'/>
                </a>
                <xsl:text>&nbsp;]</xsl:text>
              </code>
          </td>
        </xsl:template>
                
<!-- **************************************************************** -->
        <xsl:template match='vc'>
        <xsl:choose>
          <xsl:when test='previous-element(rhs[first-of-type()])'>
            <td align='left'>
                <code class='vc'>
                <xsl:text>[&nbsp;VC:&nbsp;</xsl:text>
                <a href='#{@def}'>
                        <xsl:value-of select='id(@def)/head'/>
                </a>
                <xsl:text>&nbsp;]</xsl:text>
                </code>
            </td>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test='previous-element(rhs[first-of-type()])'>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align='left'>
                  <code class='vc'>
                    <xsl:text>[&nbsp;VC:&nbsp;</xsl:text>
                    <a href='#{@def}'>
                       <xsl:value-of select='id(@def)/head'/>
                    </a>
                    <xsl:text>&nbsp;]</xsl:text>
                  </code>
                  <xsl:apply-templates/>
                </td>
              </xsl:when>
              <xsl:when test='previous-element(rhs[not(first-of-type())])'>
                <!-- this is processed through a select in match="rhs" -->
              </xsl:when>
              <xsl:otherwise>
                <tr>
                   <td></td><td></td><td></td><td></td>
                   <td align='left'>
                     <code class='vc'>
                       <xsl:text>[&nbsp;VC:&nbsp;</xsl:text>
                       <a href='#{@def}'>
                         <xsl:value-of select='id(@def)/head'/>
                       </a>
                       <xsl:text>&nbsp;]</xsl:text>
                      </code>
                      <xsl:apply-templates/>
                    </td>
                  </tr>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>

<!-- **************************************************************** -->
<!-- **************************************************************** -->
        <xsl:template match='wfc' mode='next'>
          <td></td>
          <td align='left'>
              <code class='wfc'>
                <xsl:text>[&nbsp;WFC:&nbsp;</xsl:text>
                <a href='#{@def}'>
                        <xsl:value-of select='id(@def)/head'/>
                </a>
                <xsl:text>&nbsp;]</xsl:text>
              </code>
          </td>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='wfc'>
        <xsl:choose>
        <xsl:when test='previous-element(rhs[first-of-type()])'>
        <td align='left'>
                <code class='wfc'>
                <xsl:text>[&nbsp;WFC:&nbsp;</xsl:text>
                <a href='#{@def}'>
                        <xsl:value-of select='id(@def)/head'/>
                </a>
                <xsl:text>&nbsp;]</xsl:text>
                </code>
        </td>
        </xsl:when>
        <xsl:otherwise>
                <xsl:choose>
                <xsl:when test='previous-element(rhs[first-of-type()])'>
                <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
                <td align='left'>
                        <code class='wfc'>
                        <xsl:text>[&nbsp;WFC:&nbsp;</xsl:text>
                        <a href='#{@def}'>
                                <xsl:value-of select='id(@def)/head'/>
                        </a>
                        <xsl:text>&nbsp;]</xsl:text>
                        </code>
                        <xsl:apply-templates/>
                </td>
                </xsl:when>
                <xsl:when test='previous-element(rhs[not(first-of-type())])'>
                        <!-- this is processed through a select in match="rhs" -->
                </xsl:when>
                <xsl:otherwise>
                <tr><td></td><td></td><td></td><td></td>
                <td align='left'>
                        <code class='wfc'>
                        <xsl:text>[&nbsp;WFC:&nbsp;</xsl:text>
                        <a href='#{@def}'>
                                <xsl:value-of select='id(@def)/head'/>
                        </a>
                        <xsl:text>&nbsp;]</xsl:text>
                        </code>
                        <xsl:apply-templates/>
                </td>
                </tr>
                </xsl:otherwise>
                </xsl:choose>
        </xsl:otherwise>
        </xsl:choose>
        </xsl:template>



<!-- **************************************************************** -->
<!-- Empty templates -->
<!-- **************************************************************** -->
        <xsl:template match='w3c-designation'></xsl:template>
        <xsl:template match='w3c-doctype'></xsl:template>
        <xsl:template match='header/pubdate'></xsl:template>
        <xsl:template match='spec/header/title'></xsl:template>
        <xsl:template match='revisiondesc'></xsl:template>   
        <xsl:template match='pubstmt'></xsl:template>
        <xsl:template match='sourcedesc'></xsl:template>
        <xsl:template match='langusage'></xsl:template>
        <xsl:template match='version'></xsl:template>

<!-- **************************************************************** -->
<!-- Macros -->
<!-- **************************************************************** -->
        <xsl:macro name='copyright'>
            <p class='copyright'>
              <small>
                <a href='http://www.w3.org/Consortium/Legal/ipr-notice.html#Copyright'>
                Copyright</a> &nbsp;&copy;&nbsp; 1999 <a href='http://www.w3.org'>W3C</a>
                (<a href='http://www.lcs.mit.edu'>MIT</a>,
                <a href='http://www.inria.fr/'>INRIA</a>,
                <a href='http://www.keio.ac.jp/'>Keio</a> ), 
                All Rights Reserved. W3C
                <a href='http://www.w3.org/Consortium/Legal/ipr-notice.html#Legal Disclaimer'>
                liability</a>, 
                <a href='http://www.w3.org/Consortium/Legal/ipr-notice.html#W3C Trademarks'>
                trademark</a>, 
                <a href='http://www.w3.org/Consortium/Legal/copyright-documents.html'>
                document use</a> and 
                <a href='http://www.w3.org/Consortium/Legal/copyright-software.html'>
                software licensing</a> rules apply.
              </small>
            </p>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='toc'>
             <xsl:for-each select='/spec/body/div1'>
                 <xsl:number format='1. '/>
                 <xsl:invoke macro='makeref'></xsl:invoke>
                 <br/>

                 <xsl:for-each select='div2'>
                     <xsl:text>&nbsp;&nbsp;&nbsp;&nbsp;</xsl:text>
                     <xsl:number level='multi' count='div1|div2' format='1.1 '/>
                     <xsl:invoke macro='makeref'></xsl:invoke>
                     <br/>

                     <xsl:for-each select='div3'>
                         <xsl:text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</xsl:text>
                         <xsl:number level='multi' count='div1|div2|div3' format='1.1 '/>
                         <xsl:invoke macro='makeref'></xsl:invoke>
                         <br/>
                     </xsl:for-each>
                </xsl:for-each>
           </xsl:for-each>

           <h3>Appendices</h3>

           <xsl:for-each select='/spec/back/div1 | /spec/back/inform-div1'>
               <xsl:number format='A. ' count='div1|inform-div1'/>
               <xsl:invoke macro='makeref'></xsl:invoke>
               <br/>

               <xsl:for-each select='div2'>
                   <xsl:text>&nbsp;&nbsp;&nbsp;&nbsp;</xsl:text>
                   <xsl:number level='multi' count='div1|div2' format='A.1 '/>
                   <xsl:invoke macro='makeref'></xsl:invoke>
                   <br/>

                   <xsl:for-each select='div3'>
                       <xsl:text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</xsl:text>
                       <xsl:number level='multi' count='div1|div2|div3' format='A.1 '/>
                       <xsl:invoke macro='makeref'></xsl:invoke>
                       <br/>
                   </xsl:for-each>
                </xsl:for-each>
            </xsl:for-each>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='rhs'>
             <td align='left'>
               <code class='rhs'>
                 <xsl:apply-templates/>
               </code>
             </td>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='rhs_next_vc'>
             <td align='left'>
               <code>
                 <xsl:apply-templates/>
                 <xsl:apply-templates select='next-element(vc)' mode='next'/>
               </code>
             </td>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='rhs_next_wfc'>
             <td align='left'>
               <code>
                 <xsl:apply-templates/>
                 <xsl:apply-templates select='next-element(wfc)' mode='next'/>
               </code>
             </td>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='rhs_next_c'>
             <td align='left'>
               <code>
                 <xsl:apply-templates/>
                 <xsl:apply-templates select='next-element(constraint)' mode='next'/>
               </code>
             </td>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='insertID'>
            <xsl:choose>
                <xsl:when test='.[@id]'>
                    <a name='{@id}'></a>
                </xsl:when>
                <xsl:otherwise>
                    <a name='{head}'></a>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='makeref'>
            <xsl:choose>
                <xsl:when test='.[@id]'>
                    <a href='#{@id}'>
                      <xsl:value-of select='head'/>
                    </a>
                </xsl:when>
                <xsl:otherwise>
                    <a href='#{head}'>
                      <xsl:value-of select='head'/>
                    </a>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:macro>

<!-- **************************************************************** -->
        <xsl:macro name='open_issues'>
            <xsl:for-each select='//issue'>
                 <a class='issue' href='#{@id}'>
                   <xsl:value-of select='@id'/>
                 </a>
                 <br/>
            </xsl:for-each>
        </xsl:macro>


<!-- **************************************************************** -->
        <xsl:template match='constraint'>
             <xsl:choose>
                  <xsl:when test='previous-element(rhs[first-of-type()])'>
                       <td align='left'>
                         <code class='constraint'>
                           <xsl:text>[&nbsp;Constraint:&nbsp;</xsl:text>
                           <a href='#{@def}'>
                             <xsl:value-of select='id(@def)/head'/>
                           </a>
                           <xsl:text>&nbsp;]</xsl:text>
                          </code>
                         </td>
                    </xsl:when>
                    <xsl:otherwise>
                         <xsl:choose>
                              <xsl:when test='previous-element(rhs[first-of-type()])'>
                                   <td>&nbsp;</td>
                                   <td>&nbsp;</td>
                                   <td>&nbsp;</td>
                                   <td>&nbsp;</td>
                                   <td align='left'>
                                     <code class='constraint'>
                                       <xsl:text>[&nbsp;Constraint:&nbsp;</xsl:text>
                                       <a href='#{@def}'>
                                         <xsl:value-of select='id(@def)/head'/>
                                       </a>
                                       <xsl:text>&nbsp;]</xsl:text>
                                     </code>
                                     <xsl:apply-templates/>
                                   </td>
                              </xsl:when>
                              <xsl:when test='previous-element(rhs[not(first-of-type())])'>
                                   <!-- this is processed through a select in match="rhs" -->
                              </xsl:when>
                              <xsl:otherwise>
                                <tr><td></td><td></td><td></td><td></td>
                                  <td align='left'>
                                    <code class='constraint'>
                                      <xsl:text>[&nbsp;Constraint:&nbsp;</xsl:text>
                                      <a href='#{@def}'>
                                        <xsl:value-of select='id(@def)/head'/>
                                      </a>
                                      <xsl:text>&nbsp;]</xsl:text>
                                    </code>
                                    <xsl:apply-templates/>
                                   </td>
                                 </tr>
                               </xsl:otherwise>
                          </xsl:choose>
                     </xsl:otherwise>
                </xsl:choose>
        </xsl:template>

<!-- **************************************************************** -->
        <xsl:template match='constraint' mode='next'>
        <td></td>
        <td align='left'>
                <code class='constraint'>
                <xsl:text>[&nbsp;Constraint:&nbsp;</xsl:text>
                <a href='#{@def}'>
                        <xsl:value-of select='id(@def)/head'/>
                </a>
                <xsl:text>&nbsp;]</xsl:text>
                </code>
        </td>
        </xsl:template>

</xsl:stylesheet>
