<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.0//EN" encoding="UTF-16"/>
<!-- XSLT stylesheet for ISO/IEC stdex.dtd -->
<!-- version.0.42 -->

<xsl:template match="/">
  <!-- contents: standard -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="standard">
  <!-- contents: @language tpage body -->
  <html>
    <head>
      <title>ISO/IEC IT --- Ver.0.42 ---</title>
    </head>
    <style>
      h1    { font-size: 24pt ;
          color : white ;
          background-color: blue ;}
      h2    { font-soze: 24pt ;
          color : white ;
          background-color: green ;}
      h3    { font-size: 12pt ;
          color : black ;
          background-color: white ;}
      h4    { font-size: 10pt ;
          color : black ;
          background-color: white ;}
      h5    { font-size: 10pt ;
          color : black ;
          background-color: white ;}
      h6    { font-size: 10pt ;
          color : black ;
          background-color: white ;}
      strong.blue  { color: blue ;
          font-weight: bold ;}
      dt    { font-weight: bold ;}
      ol    { list-style: none outside }
      ul    { list-style: none outside }
      a:link    { color: blue ;}
      a:visit    { }
      a:active  { color: red ;}
      a:hover    { color: green ;}
      p    { margin-top : 0.5em ;
          margin-bottom : 1.5em ;}
      item    { color: blue ;
          font-weight: bold ;}
      fn    { color: blue ;
          font-weight: bold ;}
    </style>
    <body>
      <xsl:call-template name="frontm"/>
      <hr/>
      <xsl:call-template name="toc"/>
      <xsl:call-template name="lof"/>
      <xsl:call-template name="lot"/>
      <hr/>
      <xsl:apply-templates/>
      <xsl:call-template name="backm"/>
    </body>
  </html>
</xsl:template>

<xsl:template name="frontm">
  <!-- front matter -->
  <xsl:apply-templates select='profile/profdoc[@type="FULL"]' mode="frontm"/>
</xsl:template>

<xsl:template match="profdoc" mode="frontm">
  <!-- profdoc for front matter -->
  <xsl:apply-templates select='docprof[@apply="ISO"]' mode="frontm"/>
</xsl:template>

<xsl:template match="docprof" mode="frontm">
  <!-- docprof for front matter -->
  <xsl:variable name="lang" select="language/text()"/>
  <b><font size="5">
    <xsl:call-template name="docstat">
      <xsl:with-param name="status" select="developc/developent[last()]/status"/>
    </xsl:call-template>
    <div align="right">
      <xsl:call-template name="docsource">
        <xsl:with-param name="source" select="sourceod"/>
      </xsl:call-template>
      <xsl:value-of select="refnums/number"/>
      <xsl:if test='refnums/part'>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="refnums/part"/>
      </xsl:if>
      <br/>
      <font size="2">
        <xsl:value-of select="edition"/>
        <xsl:text> edition</xsl:text>
      </font>
      <br/>
      <font size="1">
        <xsl:value-of select="developc/developent[last()]/scdate"/>
      </font>
    </div>
    <xsl:apply-templates select="titles/titleent[@langcode=$lang]" mode="frontm"/>
  </font></b>
  <font size="3">
    <xsl:apply-templates select="titles/titleent[@langcode!=$lang]" mode="frontm"/>
  </font>
  <div align="right">
    <font size="2">
      <xsl:text>Reference number</xsl:text><br/>
      <xsl:call-template name="refnum"/>
    </font>
  </div>
</xsl:template>

<xsl:template name="docstat">
  <xsl:param name="status"/>
  <xsl:choose>
    <xsl:when test='$status="IS"'>
      <xsl:text>INTERNATIONAL STANDARD</xsl:text>
    </xsl:when>
    <xsl:when test='$status="TR"'>
      <xsl:text>TECHNICAL REPORT</xsl:text>
    </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template name="docsource">
  <xsl:param name="source"/>
  <xsl:choose>
    <xsl:when test='$source="ISOIEC"'>
      <xsl:text>ISO/IEC </xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>ISO </xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="titleent" mode="frontm">
  <xsl:for-each select="mtitle/tline">
    <xsl:apply-templates/><br/>
  </xsl:for-each>
  <xsl:if test='ptitle'>
    <xsl:call-template name="part">
      <xsl:with-param name="lang" select="@langcode"/>
    </xsl:call-template>
    <xsl:value-of select="../../refnums/part"/>
    <xsl:text>:</xsl:text><br/>
    <xsl:for-each select="ptitle/ptline">
      <xsl:apply-templates/><br/>
    </xsl:for-each>
  </xsl:if>
</xsl:template>

<xsl:template name="part">
  <xsl:param name="lang"/>
  <xsl:choose>
    <xsl:when test='$lang="EN"'>
      <xsl:text>Part</xsl:text>
    </xsl:when>
    <xsl:when test='$lang="FR"'>
      <xsl:text>Partie</xsl:text>
    </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template name="refnum">
  <xsl:call-template name="docsource">
    <xsl:with-param name="source" select="sourceod"/>
  </xsl:call-template>
  <xsl:value-of select="refnums/number"/>
  <xsl:if test='refnums/part'>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="refnums/part"/>
  </xsl:if>
  <xsl:text>:</xsl:text>
  <xsl:variable name="date" select="developc/developent[last()]/scdate"/>
  <xsl:value-of select="substring($date, 0, 5)"/>
  <xsl:text>(</xsl:text>
  <xsl:call-template name="langid">
    <xsl:with-param name="lang" select="language"/>
  </xsl:call-template>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template name="langid">
  <xsl:param name="lang"/>
  <xsl:choose>
    <xsl:when test='$lang="EN"'>
      <xsl:text>E</xsl:text>
    </xsl:when>
    <xsl:when test='$lang="FR"'>
      <xsl:text>F</xsl:text>
    </xsl:when>
  </xsl:choose>  
</xsl:template>

<xsl:template name="toc">
  <h1>Contents</h1>
  <ul>
    <xsl:for-each select="foreword|body/scope|body/refs|body/defs|//h1|//h2|//h3|//h4|//h5|//h6|annexi|index">
      <xsl:call-template name="toc-ent"/>
    </xsl:for-each>
  </ul>
</xsl:template>

<xsl:template name="toc-ent">
  <li>
    <xsl:element name="a">
      <xsl:choose>
        <xsl:when test='self::index'>
          <xsl:attribute name="href">
            <xsl:text>#in</xsl:text>
            <xsl:number level="any" count="index"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test='self::foreword'>
          <xsl:attribute name="href">
            <xsl:text>#fo</xsl:text>
            <xsl:number level="any" count="foreword"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test='ancestor::body'>
          <xsl:attribute name="href">
            <xsl:text>#bo</xsl:text>
            <xsl:number level="multiple" count="scope|refs|defs|h1|h2|h3|h4|h5|h6" from="body"/>
          </xsl:attribute>
          <xsl:number level="multiple" count="scope|refs|defs|h1|h2|h3|h4|h5|h6" from="body" format="1.1 "/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="href">
            <xsl:text>#an</xsl:text>
            <xsl:number level="multiple" count="annexi|h1|h2|h3|h4|h5|h6"/>
          </xsl:attribute>
          <xsl:if test='self::annexi'>
            <xsl:text>Annex </xsl:text>
          </xsl:if>
          <xsl:number level="multiple" count="annexi|h1|h2|h3|h4|h5|h6" format="A.1 "/>
          <xsl:if test='self::annexi'>
            <xsl:text>(</xsl:text>
            <xsl:value-of select="@status"/>
            <xsl:text>) </xsl:text>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:value-of select="ht"/>
    </xsl:element>
  </li>
</xsl:template>

<xsl:template name="lof">
  <xsl:if test='//figure'>
    <h2>Figures</h2>
    <ul>
      <xsl:for-each select="//figure">
        <xsl:call-template name="lof-ent"/>
      </xsl:for-each>
    </ul>
  </xsl:if>
</xsl:template>

<xsl:template name="lof-ent">
  <li>
    <xsl:element name="a">
      <xsl:choose>
        <xsl:when test='ancestor::body'>
          <xsl:attribute name="href">
            <xsl:text>#bof</xsl:text>
            <xsl:number level="any" count="figure" from="body"/>
          </xsl:attribute>
          <xsl:text>Figure </xsl:text>
          <xsl:number level="any" count="figure" from="body"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="href">
            <xsl:text>#anf</xsl:text>
            <xsl:number level="multiple" count="annexi|figure"/>
          </xsl:attribute>
          <xsl:text>Figure </xsl:text>
          <xsl:number level="multiple" count="annexi|figure" format="A.1 "/>
        </xsl:otherwise>
      </xsl:choose>
      &#8211;
      <xsl:value-of select="figtitle"/>
    </xsl:element>
  </li>
</xsl:template> 

<xsl:template name="lot">
  <xsl:if test='//table'>
    <h2>Tables</h2>
    <ul>
      <xsl:for-each select="//table">
        <xsl:call-template name="lot-ent"/>
      </xsl:for-each>
    </ul>
  </xsl:if>
</xsl:template>

<xsl:template name="lot-ent">
  <li>
    <xsl:element name="a">
      <xsl:choose>
        <xsl:when test='ancestor::body'>
          <xsl:attribute name="href">
            <xsl:text>#bot</xsl:text>
            <xsl:number level="any" count="table" from="body"/>
          </xsl:attribute>
          <xsl:text>Table </xsl:text>
          <xsl:number level="any" count="table" from="body"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="href">
            <xsl:text>#ant</xsl:text>
            <xsl:number level="multiple" count="annexi|table"/>
          </xsl:attribute>
          <xsl:text>Table </xsl:text>
          <xsl:number level="multiple" count="annexi|table" format="A.1 "/>
        </xsl:otherwise>
      </xsl:choose>
      &#8211;
      <xsl:value-of select="tabtitle"/>
    </xsl:element>
  </li>
</xsl:template> 

<xsl:template name="backm">
  <!-- back matter -->
  <hr/>
  <xsl:apply-templates select='profile/profdoc[@type="FULL"]' mode="backm"/>
</xsl:template>

<xsl:template match="profdoc" mode="backm">
  <xsl:apply-templates select='docprof[@apply="ISO"]' mode="backm"/>
</xsl:template>

<xsl:template match="docprof" mode="backm">
  <b><font size="3">
    <xsl:text>UDC </xsl:text>
    <xsl:for-each select="classifn">
      <xsl:call-template name="listel">
        <xsl:with-param name="delimchar">:</xsl:with-param>
        <xsl:with-param name="termchar"/>
      </xsl:call-template>
    </xsl:for-each>
  </font></b><br/>
  <font size="1">
    <b><xsl:text>Descripters: </xsl:text></b>
    <xsl:for-each select="keyword">
      <xsl:call-template name="listel">
        <xsl:with-param name="delimchar">, </xsl:with-param>
        <xsl:with-param name="termchar">.</xsl:with-param>
      </xsl:call-template>
    </xsl:for-each>
  </font>
  <hr/>
</xsl:template>

<xsl:template name="listel">
  <xsl:param name="delimchar"/>
  <xsl:param name="termchar"/>
  <xsl:apply-templates/>
  <xsl:choose>
    <xsl:when test='position()=last()'>
      <xsl:value-of select="$termchar"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$delimchar"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="profile">
  <!-- contents: profdoc -->
</xsl:template>

<xsl:template match="tpage">
  <!-- contents: text() -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="foreword">
  <!-- contents: ht p -->
  <xsl:apply-templates/>
  <hr/>
</xsl:template>

<xsl:template match="foreword/ht">
  <!-- contents: text() -->
  <h1>
    <xsl:element name="a">
      <xsl:attribute name="name">
        <xsl:text>fo</xsl:text>
        <xsl:number level="any" count="foreword"/>
      </xsl:attribute>
      <xsl:value-of select="."/>
    </xsl:element>
  </h1>
</xsl:template>

<xsl:template match="p">
  <!-- contents: text() -->
  <p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="warning">
  <!-- contents: text() -->
  <p><xsl:text>WARNING-</xsl:text><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="body">
  <!-- contents: scope refs defs h1 -->
  <xsl:call-template name="btop"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template name="btop">
  <!-- top of body -->
  <xsl:apply-templates select='../profile/profdoc[@type="FULL"]' mode="btop"/>
</xsl:template>

<xsl:template match="profdoc" mode="btop">
  <xsl:apply-templates select='docprof[@apply="ISO"]' mode="btop"/>
</xsl:template>

<xsl:template match="docprof" mode="btop">
  <b><font size="4">
    <xsl:variable name="lang" select="language/text()"/>
    <xsl:apply-templates select="titles/titleent[@langcode=$lang]" mode="frontm"/>
  </font></b>
</xsl:template>

<xsl:template match="scope">
  <!-- contents: ht p -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="refs">
  <!-- contents: ht p -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="defs">
  <!-- contents: ht p tl -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="scope/ht|refs/ht|defs/ht">
  <!-- contents: text() -->
  <h1>
    <xsl:call-template name="anchor-text"/>
  </h1>
</xsl:template>

<xsl:template name="anchor-text">
  <xsl:element name="a">
    <xsl:choose>
      <xsl:when test='ancestor::body'>
        <xsl:attribute name="name">
          <xsl:text>bo</xsl:text>
          <xsl:number level="multiple" count="scope|refs|defs|h1|h2|h3|h4|h5|h6" from="body"/>
        </xsl:attribute>
        <xsl:number level="multiple" count="scope|refs|defs|h1|h2|h3|h4|h5|h6" from="body" format="1.1 "/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="name">
          <xsl:text>an</xsl:text>
          <xsl:number level="multiple" count="annexi|h1|h2|h3|h4|h5|h6"/>
        </xsl:attribute>
        <xsl:if test="parent::annexi">
          <xsl:text>Annex </xsl:text>
        </xsl:if>
        <xsl:number level="multiple" count="annexi|h1|h2|h3|h4|h5|h6" format="A.1 "/>
        <xsl:if test="parent::annexi">
          <xsl:text>(</xsl:text>
          <xsl:value-of select="../@status"/>
          <xsl:text>) </xsl:text>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test='self::ht'>
      <xsl:value-of select="."/>
    </xsl:if>
  </xsl:element>
</xsl:template>

<xsl:template match="tl">
  <!-- contents: c1* cc1* -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="c1">
  <!-- contents: @gtext termdef termdes note p c2 -->
  <dl>
    <xsl:apply-templates/>
  </dl>
</xsl:template>

<xsl:template match="termdef">
  <!-- contents: text() -->
  <dt><xsl:value-of select="../@gtext"/><xsl:text> </xsl:text>
    <xsl:apply-templates/></dt>
</xsl:template>

<xsl:template match="termdes">
  <!-- contents: text() -->
  <dd><xsl:apply-templates/></dd>
</xsl:template>

<xsl:template match="note">
  <!-- contents: text() -->
  <p><xsl:text>NOTE </xsl:text>
    <xsl:choose>
      <xsl:when test='@number="nonum"'/>
      <xsl:otherwise>
        <xsl:if test='count(../note) &gt; 1'>
          <xsl:number level="single" count="note" format="1 "/>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="xmp">
  <!-- contents: text() -->
  <p><xsl:text>EXAMPLE </xsl:text>
    <xsl:choose>
      <xsl:when test='@number="nonum"'/>
      <xsl:otherwise>
        <xsl:if test='count(../xmp) &gt; 1'>
          <xsl:number level="single" count="xmp" format="1 "/>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="c2">
  <!-- contents: @gtext termdef termdes note p -->
  <dl>
    <xsl:apply-templates/>
  </dl>
</xsl:template>

<xsl:template match="cc1">
  <!-- contents: @gtext hc c2* -->
  <dl>
    <xsl:apply-templates/>
  </dl>
</xsl:template>

<xsl:template match="hc">
  <!-- contents: text() -->
  <dt><xsl:value-of select="../@gtext"/><xsl:text> </xsl:text>
    <xsl:apply-templates/></dt>
</xsl:template>

<xsl:template match="fn">
  <!-- contents: text() -->
  <xsl:element name="a">
    <xsl:attribute name="onClick">
      <xsl:text>alert('</xsl:text>
      <xsl:call-template name="fn-mark"/>
      <xsl:apply-templates/>
      <xsl:text>')</xsl:text>
    </xsl:attribute>
    <sup>
      <xsl:call-template name="fn-mark"/>
    </sup>
  </xsl:element>
</xsl:template>

<xsl:template name="fn-mark">
  <xsl:choose>
    <xsl:when test='ancestor::figure'>
      <xsl:number level="single" count="fn" format="a) "/>
    </xsl:when>
    <xsl:when test='ancestor::table'>
      <xsl:number level="single" count="fn" format="a) "/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:number value="count(preceding::fn)-count(preceding::fn[ancestor::figure or ancestor::table])+1" format="1) "/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="h1">
  <!-- contents: ht h2 p2 -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body/h1/ht">
  <!-- contents: text() -->
  <h1>
    <xsl:call-template name="anchor-text"/>
  </h1>
</xsl:template>

<xsl:template match="h2">
  <!-- contents: ht p note h3 -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body//h2/ht">
  <!-- contents: text() -->
  <h2>
    <xsl:call-template name="anchor-text"/>
  </h2>
</xsl:template>

<xsl:template match="h3">
  <!-- contents: ht p note h4 -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body//h3/ht">
  <!-- contents: text() -->
  <h3>
    <xsl:call-template name="anchor-text"/>
  </h3>
</xsl:template>

<xsl:template match="h4">
  <!-- contents: ht p note h5 -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body//h4/ht">
  <!-- contents: text() -->
  <h4>
    <xsl:call-template name="anchor-text"/>
  </h4>
</xsl:template>

<xsl:template match="h5">
  <!-- contents: ht p note h6 -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body//h5/ht">
  <!-- contents: text() -->
  <h5>
    <xsl:call-template name="anchor-text"/>
  </h5>
</xsl:template>

<xsl:template match="h6">
  <!-- contents: ht p note -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body//h6/ht">
  <!-- contents: text() -->
  <h6>
    <xsl:call-template name="anchor-text"/>
  </h6>
</xsl:template>

<xsl:template name="anchor-text2">
  <xsl:choose>
    <xsl:when test='ancestor::body'>
      <b><xsl:number level="multiple" count="scope|refs|defs|h1|h2|h3|h4|h5|h6|p2|p3|p4|p5|p6" from="body" format="1.1 "/></b>
    </xsl:when>
    <xsl:otherwise>
      <b><xsl:number level="multiple" count="annexi|h1|h2|h3|h4|h5|h6|p2|p3|p4|p5|p6" format="A.1 "/></b>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="p2">
  <!-- contents: p note p3 -->
  <xsl:call-template name="anchor-text2"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="p2/p|p3/p|p4/p|p5/p|p6/p">
  <xsl:choose>
    <xsl:when test='position()=1'>
      <xsl:apply-templates/><br/>
    </xsl:when>
    <xsl:otherwise>
      <p><xsl:apply-templates/></p>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="p3">
  <!-- contents: p note p4 -->
  <xsl:call-template name="anchor-text2"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="p4">
  <!-- contents: p note p5 -->
  <xsl:call-template name="anchor-text2"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="p5">
  <!-- contents: p note p6 -->
  <xsl:call-template name="anchor-text2"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="p6">
  <!-- contents: p note -->
  <xsl:call-template name="anchor-text2"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="ul">
  <!-- contents: @format[NULL bullet emdash sl] li ul -->
  <ul><xsl:apply-templates/></ul>
</xsl:template>

<xsl:template match="ol">
  <!-- contents: @format[NULL alpha arabic roman arabicn] li ol -->
  <ol><xsl:apply-templates/></ol>
</xsl:template>

<xsl:template match="ul/li">
  <!-- contents: -->
  <xsl:variable name="format" select="../@format"/>
  <xsl:choose>
    <xsl:when test='$format="bullet"'>
      <li>&#183; <xsl:apply-templates/></li>
    </xsl:when>
    <xsl:when test='$format="emdash"'>
      <li>- <xsl:apply-templates/></li>
    </xsl:when>
    <xsl:when test='$format="sl"'>
      <li><xsl:apply-templates/></li>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="level" select="count(ancestor::ul)"/>
      <xsl:choose>
        <xsl:when test='$level=2'>
          <li>&#183; <xsl:apply-templates/></li>
        </xsl:when>
        <xsl:otherwise>
          <li>- <xsl:apply-templates/></li>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="ol/li">
  <!-- contents: -->
  <xsl:variable name="format" select="../@format"/>
  <xsl:choose>
    <xsl:when test='$format="alpha"'>
      <li><xsl:number format="a) "/><xsl:apply-templates/></li>
    </xsl:when>
    <xsl:when test='$format="arabic"'>
      <li><xsl:number format="1) "/><xsl:apply-templates/></li>
    </xsl:when>
    <xsl:when test='$format="roman"'>
      <li><xsl:number format="i) "/><xsl:apply-templates/></li>
    </xsl:when>
    <xsl:when test='$format="arabicn"'>
      <li><xsl:number format="1 "/><xsl:apply-templates/></li>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="level" select="count(ancestor::ol) mod 3"/>
      <xsl:choose>
        <xsl:when test='$level=1'>
          <li><xsl:number format="a) "/><xsl:apply-templates/></li>
        </xsl:when>
        <xsl:when test='$level=2'>
          <li><xsl:number format="1) "/><xsl:apply-templates/></li>
        </xsl:when>
        <xsl:otherwise>
          <li><xsl:number format="i) "/><xsl:apply-templates/></li>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="dl">
  <!-- contents: @format[NULL ul ol syml varl] dlentry -->
  <xsl:choose>
    <xsl:when test='@format="ul"'>
      <ul><xsl:apply-templates/></ul>
    </xsl:when>
    <xsl:when test='@format="ol"'>
      <ol><xsl:apply-templates/></ol>
    </xsl:when>
    <xsl:otherwise>
      <dl compact="1"><xsl:apply-templates/></dl>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="dlentry">
  <!-- contents: dt dd -->
  <xsl:variable name="format" select="../@format"/>
  <xsl:choose>
    <xsl:when test='$format="ul"'>
      <li><xsl:value-of select="dt"/><xsl:text> </xsl:text>
        <xsl:value-of select="dd"/></li>
    </xsl:when>
    <xsl:when test='$format="ol"'>
      <li><xsl:value-of select="dt"/><xsl:text> </xsl:text>
        <xsl:value-of select="dd"/></li>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="dt">
  <!-- contents: text() -->
  <dt><xsl:apply-templates/></dt>
</xsl:template>

<xsl:template match="dd">
  <!-- contents: text() -->
  <dd><xsl:apply-templates/></dd>
</xsl:template>

<xsl:template match="rl">
  <dl><xsl:apply-templates/></dl>
</xsl:template>

<xsl:template match="rlentry">
 <dd><xsl:apply-templates/></dd>
</xsl:template>

<xsl:template match="hp">
  <!-- contents: @format[none bold italic boldit uline oline code hide ] text() -->
  <xsl:choose>
    <xsl:when test='@format="bold"'>
      <b><xsl:apply-templates/></b>
    </xsl:when>
    <xsl:when test='@format="italic"'>
      <i><xsl:apply-templates/></i>
    </xsl:when>
    <xsl:when test='@format="boldit"'>
      <i><b><xsl:apply-templates/></b></i>
    </xsl:when>
    <xsl:when test='@format="uline"'>
      <u><xsl:apply-templates/></u>
    </xsl:when>
    <xsl:when test='@format="oline"'>
      <span style="text-decoration: overline"><xsl:apply-templates/></span>
    </xsl:when>
    <xsl:when test='@format="code"'>
      <code><xsl:apply-templates/></code>
    </xsl:when>
    <xsl:when test='@format="hide"'>
      <font color="white"><xsl:apply-templates/></font>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="superscript">
  <!-- contents: text() -->
  <sup><xsl:apply-templates/></sup>
</xsl:template>

<xsl:template match="subscript">
  <!-- contents: text() -->
  <sub><xsl:apply-templates/></sub>
</xsl:template>

<xsl:template match="annexi">
  <!-- contents: ht h1 -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="annexi/ht">
  <!-- contents: text() -->
  <h1>
    <xsl:call-template name="anchor-text"/>
  </h1>
</xsl:template>

<xsl:template match="annexi/h1/ht">
  <!-- contents: text() -->
  <h2>
    <xsl:call-template name="anchor-text"/>
  </h2>
</xsl:template>

<xsl:template match="annexi//h2/ht">
  <!-- contents: text() -->
  <h3>
    <xsl:call-template name="anchor-text"/>
  </h3>
</xsl:template>

<xsl:template match="annexi//h3/ht">
  <!-- contents: text() -->
  <h4>
    <xsl:call-template name="anchor-text"/>
  </h4>
</xsl:template>

<xsl:template match="annexi//h4/ht">
  <!-- contents: text() -->
  <h5>
    <xsl:call-template name="anchor-text"/>
  </h5>
</xsl:template>

<xsl:template match="annexi//h5/ht">
  <!-- contents: text() -->
  <h6>
    <xsl:call-template name="anchor-text"/>
  </h6>
</xsl:template>

<xsl:template match="annexi//h6/ht">
  <!-- contents: text() -->
  <p>
    <xsl:call-template name="anchor-text"/>
  </p>
</xsl:template>

<xsl:template match="annexi//p2">
  <!-- contents: p note p3 -->
  <h3>
    <xsl:call-template name="anchor-text"/>
  </h3>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="annexi//p3">
  <!-- contents: p note p4 -->
  <h4>
    <xsl:call-template name="anchor-text"/>
  </h4>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="annexi//p4">
  <!-- contents: p note p5 -->
  <h5>
    <xsl:call-template name="anchor-text"/>
  </h5>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="annexi//p5">
  <!-- contents: p note p6 -->
  <h6>
    <xsl:call-template name="anchor-text"/>
  </h6>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="annexi//p6">
  <!-- contents: p note -->
  <p>
    <xsl:call-template name="anchor-text"/>
  </p>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="table">
  <table>
    <xsl:choose>
      <xsl:when test='@frame="none"'/>
      <xsl:otherwise>
        <xsl:attribute name="border"/>
      </xsl:otherwise>      
    </xsl:choose>
    <xsl:apply-templates/>
  </table>
</xsl:template>

<xsl:template match="tabtitle">
  <caption>
    <b>
      <xsl:element name="a">
        <xsl:choose>
          <xsl:when test='ancestor::body'>
            <xsl:attribute name="name">
              <xsl:text>#bot</xsl:text>
              <xsl:number level="any" count="table" from="body"/>
            </xsl:attribute>
            <xsl:text>Table </xsl:text>
            <xsl:number level="any" count="table" from="body"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name="name">
              <xsl:text>#ant</xsl:text>
              <xsl:number level="multiple" count="annexi|table"/>
            </xsl:attribute>
            <xsl:text>Table </xsl:text>
            <xsl:number level="multiple" count="annexi|table" format="A.1 "/>
          </xsl:otherwise>
        </xsl:choose>
        &#8211;
        <xsl:value-of select="."/>
      </xsl:element>
    </b>
  </caption>
</xsl:template>

<xsl:template match="tgroup">
  <xsl:apply-templates select="colspec"/>
  <xsl:apply-templates select="thead"/>
  <xsl:apply-templates select="tbody"/>
  <xsl:apply-templates select="tfoot"/>
  <tr>
    <td colspan="100">
      <xsl:apply-templates select=".//tabnote" mode="note"/>
    </td>
  </tr>
</xsl:template>

<xsl:template match="colspec">
</xsl:template>

<xsl:template match="thead">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="tbody">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="tfoot">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="row">
  <tr>
    <xsl:choose>
      <xsl:when test='parent::thead or parent::tfoot'>
        <xsl:attribute name="bgcolor">#d0d0d0</xsl:attribute>
      </xsl:when>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test='@valign'>
        <xsl:attribute name="valign">
          <xsl:value-of select="@valign"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:when test='parent::*[@valign]'>
        <xsl:attribute name="valign">
          <xsl:value-of select="parent::*[@valign]"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:when test='parent::thead'>
        <xsl:attribute name="valign">bottom</xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="valign">top</xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
  </tr>
</xsl:template>

<xsl:template match="entry">
  <xsl:choose>
    <xsl:when test='ancestor::thead'>
      <xsl:call-template name="ent">
        <xsl:with-param name="tag">th</xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="ent">
        <xsl:with-param name="tag">td</xsl:with-param>
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="ent">
  <xsl:param name="tag"/>
  <xsl:element name="{$tag}">
    <xsl:if test='@valign'>
      <xsl:attribute name="valign">
        <xsl:value-of select="@valign"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test='@align'>
      <xsl:attribute name="align">
        <xsl:value-of select="@align"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test='@morerows'>
      <xsl:attribute name="rowspan">
        <xsl:value-of select="@morerows + 1"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test='@namest and @nameend'>
      <xsl:call-template name="colspan">
        <xsl:with-param name="namest" select="@namest"/>
        <xsl:with-param name="nameend" select="@nameend"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

<xsl:template name="colspan">
  <xsl:param name="namest"/>
  <xsl:param name="nameend"/>
  <xsl:call-template name="colspan-sub">
    <xsl:with-param name="numst">
      <xsl:choose>
        <xsl:when test='parent::row/preceding-sibling::colspec[@colname=$namest]'>
          <xsl:value-of select="count(parent::row/preceding-sibling::colspec[@colname=$namest]/preceding-sibling::colspec)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="count(ancestor::tgroup/child::colspec[@colname=$namest]/preceding-sibling::colspec)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:with-param>
    <xsl:with-param name="numend">
      <xsl:choose>
        <xsl:when test='parent::row/preceding-sibling::colspec[@colname=$nameend]'>
          <xsl:value-of select="count(parent::row/preceding-sibling::colspec[@colname=$nameend]/preceding-sibling::colspec)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="count(ancestor::tgroup/child::colspec[@colname=$nameend]/preceding-sibling::colspec)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template name="colspan-sub">
  <xsl:param name="numst"/>
  <xsl:param name="numend"/>
  <xsl:attribute name="colspan">
    <xsl:value-of select="$numend - $numst + 1"/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="tabnote">
</xsl:template>

<xsl:template match="tabnote" mode="note">
  <!-- contents: text() -->
  <xsl:text>NOTE </xsl:text>
  <xsl:choose>
    <xsl:when test='@number="nonum"'/>
    <xsl:otherwise>
      <xsl:if test='count(ancestor::table//tabnote) &gt; 1'>
        <xsl:number level="any" count="tabnote" from="table" format="1 "/>
      </xsl:if>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates/>
  <br/>
</xsl:template>

<xsl:template match="figure">
  <div>
    <xsl:apply-templates/>
    <xsl:apply-templates select=".//fignote" mode="note"/>
  </div>
</xsl:template>

<xsl:template match="figtitle">
  <div align="center">
    <b>
      <xsl:element name="a">
        <xsl:choose>
          <xsl:when test='ancestor::body'>
            <xsl:attribute name="name">
              <xsl:text>#bof</xsl:text>
              <xsl:number level="any" count="figure" from="body"/>
            </xsl:attribute>
            <xsl:text>Figure </xsl:text>
            <xsl:number level="any" count="figure" from="body"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name="name">
              <xsl:text>#anf</xsl:text>
              <xsl:number level="multiple" count="annexi|figure"/>
            </xsl:attribute>
            <xsl:text>Figure </xsl:text>
            <xsl:number level="multiple" count="annexi|figure" format="A.1 "/>
          </xsl:otherwise>
        </xsl:choose>
        &#8211;
        <xsl:value-of select="."/>
      </xsl:element>
    </b>
  </div>
</xsl:template>

<xsl:template match="fignote">
</xsl:template>

<xsl:template match="fignote" mode="note">
  <!-- contents: text() -->
  <xsl:text>NOTE </xsl:text>
  <xsl:choose>
    <xsl:when test='@number="nonum"'/>
    <xsl:otherwise>
      <xsl:if test='count(ancestor::figure//fignote) &gt; 1'>
        <xsl:number level="any" count="fignote" from="figure" format="1 "/>
      </xsl:if>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates/>
  <br/>
</xsl:template>

<xsl:template match="xref">
  <xsl:for-each select="id(@refid)">
    <xsl:call-template name="xref-one"/>
  </xsl:for-each>
</xsl:template>

<xsl:template name="xref-one">
  <xsl:choose>
    <xsl:when test='self::tabtitle'>
      <xsl:number level="any" count="table"/>
    </xsl:when>
    <xsl:when test='ancestor::body'>
      <xsl:number level="multiple" count="scope|refs|defs|h1|h2|h3|h4|h5|h6|p2|p3|p4|p5|p6" from="body" format="1.1 "/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:number level="multiple" count="annexi|h1|h2|h3|h4|h5|h6|p2|p3|p4|p5|p6" format="A.1 "/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="inf">
  <sub><xsl:apply-templates/></sub>
</xsl:template>

<xsl:template match="formula">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="dformula">
  <dl><dd><xsl:apply-templates/></dd></dl>
</xsl:template>

<xsl:template match="fence">
  <xsl:value-of select="@lpost"/>
  <xsl:apply-templates/>
  <xsl:value-of select="@rpost"/>
</xsl:template>

</xsl:stylesheet>
