<!DOCTYPE xsl:stylesheet [

<!ENTITY ldquo  "&#x201C;" ><!--=double quotation mark, left-->
<!ENTITY rdquo  "&#x201D;" ><!--=double quotation mark, right-->

]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:preserve-space elements="p title"/>

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

  <xsl:output method="html"/>

  <xsl:variable name="CSS-basic">

    <!-- CSS code -->
    
<![CDATA[

body { background-color: white }

table.footer { padding: 0.25em;
               color: white;
               background-color: darkred;
               font-family: sans-serif;
               font-size: 90%;
               font-style: italic }

span.source { color: darkred;
              font-family: sans-serif;
              font-size: 85%;
              font-weight: bold }

span.target { color: darkgreen;
              font-family: sans-serif;
              font-size: 85%;
              text-decoration: underline }

span.literal { font-family: monospace;
               font-size: 95% }

span.mapped-group { font-weight: bold }

.list-title { font-style: italic;
              margin-top:0em;
              margin-bottom:0em }

p { margin-bottom:0em }

p.first   { margin-top:0em }

p.in-list { margin-top:0em;
            margin-bottom:0em }

p.include-no { color: grey }

p.include-yes { font-weight: bold }

div.common p { margin:0em }

div.includes,
div.includes div,
div.self-note,
div.discussion-note,
div.coding-note,
div.amendment,

div.self-note { background-color: pink }

div.amendment { background-color: lightgreen }

h5 { margin: 0em }
div.parents-list ul,
div.offspring-list ul { margin:0em }

.marker { margin-top:0em;
           margin-bottom:0em;
           font-size: 80%;
           color: midnightblue }

a { text-decoration: none;
    color: midnightblue;
    font-style: normal }

table.buttonbar a { color: white;
                    text-decoration: none }

table.footer a
  { color: lightgrey }

span.label { font-size:80% }


]]>

  </xsl:variable>

  <xsl:variable name="mapped-contexts" select="//mapped/context"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:value-of select="/spec/title"/>
        </title>
        <style type="text/css">
          <xsl:copy-of select="$CSS-basic"/>
        </style>
      </head>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="spec">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="p">
    <p>
      <xsl:if test="not(preceding-sibling::*)">
        <xsl:attribute name="class">first</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
    </p>
  </xsl:template>

  <xsl:template match="item/p">
    <p class="in-list">
      <xsl:apply-templates/>
    </p>
  </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="uri">
    <a href="{.}" target="external">
      <xsl:apply-templates/>
    </a>
  </xsl:template>
  
  <xsl:template match="source | target">
    <span class="{local-name()}">
      <xsl:apply-templates/>
    </span>
    <!--<span class="label"> [<xsl:value-of select="local-name()"/>]</span>-->
  </xsl:template>

  <xsl:template match="lit">
    <xsl:text>&ldquo;</xsl:text>
    <span class="literal">
      <xsl:apply-templates/>
    </span>
    <xsl:text>&rdquo;</xsl:text>
    <span class="label">
      <xsl:text> [literal</xsl:text>
      <xsl:if test="not(@x='none')">
        <xsl:text>: tag as </xsl:text>
        <span class="target">
          <xsl:text>x[@x-type='</xsl:text>
          <xsl:value-of select="@x"/>
          <xsl:if test="not(@x)">archive</xsl:if>
          <!-- defaulting to 'archive' in case DTD isn't being parsed -->
          <xsl:text>']</xsl:text>
        </span>
      </xsl:if>
      <xsl:text>]</xsl:text>
    </span>
  </xsl:template>

  <xsl:template match="file-pointer">
    <a href="{@target}">
      <xsl:apply-templates/>
    </a>
  </xsl:template>

  <xsl:template match="title">
    <h1>
      <xsl:apply-templates/>
    </h1>
  </xsl:template>

  <xsl:template match="section/title" priority="2">
    <h2>
      <xsl:apply-templates/>
    </h2>
  </xsl:template>

  <xsl:template match="section/section/title" priority="3">
    <h3>
      <xsl:apply-templates/>
    </h3>
  </xsl:template>

  <xsl:template match="section/section/section/title" priority="4">
    <h4>
      <xsl:apply-templates/>
    </h4>
  </xsl:template>

  <xsl:template match="codeblock">
    <pre>
    <xsl:apply-templates/>
  </pre>
  </xsl:template>

  <xsl:template match="self-note | discussion-note | coding-note | amendment">
    <xsl:variable name="label">
      <xsl:choose>
        <xsl:when test="self::self-note">Note to self</xsl:when>
        <xsl:when test="self::coding-note">Note to developer</xsl:when>
        <xsl:when test="self::discussion-note">For discussion</xsl:when>
        <xsl:when test="self::amendment">Amendment</xsl:when>
        <xsl:otherwise/>
      </xsl:choose>
    </xsl:variable>
    <div class="{local-name()}">
      <h5 class="marker">[<xsl:value-of select="$label"/>]</h5>
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  
  <xsl:template match="section">
    <div class="section">
      <a name="section-{generate-id()}"/>
      <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="bul-list">
    <ul>
      <xsl:apply-templates/>
    </ul>
  </xsl:template>

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

  <xsl:template match="num-list">
    <ol>
      <xsl:apply-templates/>
    </ol>
  </xsl:template>

  <xsl:template match="def-list">
    <dl>
      <xsl:apply-templates/>
    </dl>
  </xsl:template>

  <xsl:template match="def-list">
    <div class="deflist">
      <xsl:apply-templates select="title"/>
      <table class="deflisttable">
        <xsl:if test="term.head|def.head">
          <tr>
            <th class="termhead">
              <xsl:apply-templates select="term.head"/>
            </th>
            <th class="defhead">
              <xsl:apply-templates select="def.head"/>
            </th>
          </tr>
        </xsl:if>
        <xsl:apply-templates select="def.item"/>
      </table>
    </div>
  </xsl:template>

  <xsl:template match="def-list/title | bul-list/title | num-list/title">
    <h4 class="list-title">
      <xsl:apply-templates/>
    </h4>
  </xsl:template>

  <xsl:template match="term-head">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="def-head">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="def-item">
    <tr class="row{position() mod 2}">
      <xsl:apply-templates/>
    </tr>
  </xsl:template>

  <xsl:template match="term">
    <td class="dterm">
      <p>
        <xsl:apply-templates/>
      </p>
    </td>
  </xsl:template>

  <xsl:template match="def">
    <td class="ddef">
      <xsl:apply-templates/>
    </td>
  </xsl:template>


</xsl:stylesheet>
