<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:saxon="http://icl.com/saxon"
                xmlns:lxslt="http://xml.apache.org/xslt"
                xmlns:xalanredirect="org.apache.xalan.xslt.extensions.Redirect"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="saxon xalanredirect lxslt exsl"
                version="1.0">

<!-- $Id: oasis-docbook-html.xsl,v 1.2 2002/06/13 18:50:36 ndw Exp $ -->

<!-- This stylesheet is a customization of the DocBook XSL Stylesheets -->
<!-- See http://sourceforge.net/projects/docbook/ -->
<xsl:import href="http://docbook.sf.net/release/xsl/current/html/docbook.xsl"/>
<xsl:include href="titlepage-html.xsl"/>

<!-- ============================================================ -->
<!-- Parameters -->

<xsl:param name="css.path"
           select="'http://www.oasis-open.org/spectools/css/'"/>

<xsl:param name="css.stylesheet">
  <xsl:choose>
    <xsl:when test="/article/@status='Working Draft'">oasis-wd.css</xsl:when>
    <xsl:when test="/article/@status=&quot;Editor's Draft&quot;">oasis-ed.css</xsl:when>
    <xsl:when test="/article/@status='Committee Draft'">oasis-cd.css</xsl:when>
    <xsl:when test="/article/@status='Committee Specification'">oasis-cs.css</xsl:when>
    <xsl:when test="/article/@status='Standard'">oasis-standard.css</xsl:when>
    <xsl:otherwise>
      <xsl:message>
        <xsl:text>Unrecognized status: '</xsl:text>
        <xsl:value-of select="/article/@status"/>
        <xsl:text>'; styling as Working Draft.</xsl:text>
      </xsl:message>
      <xsl:text>oasis-wd.css</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:param>

<xsl:param name="html.stylesheet">
  <xsl:value-of select="$css.path"/>
  <xsl:value-of select="$css.stylesheet"/>
</xsl:param>

<xsl:param name="section.autolabel" select="'1'"/>

<xsl:param name="generate.component.toc" select="'1'"/>

<xsl:param name="oasis.logo"
           select="'http://www.oasis-open.org/spectools/images/oasis.png'"/>

<xsl:param name="method" select="'html'"/>
<xsl:param name="indent" select="'no'"/>
<xsl:param name="encoding" select="'ISO-8859-1'"/>

<!-- ============================================================ -->
<!-- The document -->
<xsl:template match="/">
  <xsl:variable name="content">
    <xsl:apply-imports/>
  </xsl:variable>

  <xsl:variable name="filename">
    <xsl:value-of select="/article/articleinfo/productname[1]"/>
    <xsl:if test="/article/articleinfo/productnumber">
      <xsl:text>-</xsl:text>
      <xsl:value-of select="/article/articleinfo/productnumber[1]"/>
    </xsl:if>
    <xsl:text>.html</xsl:text>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="element-available('exsl:document')">
      <xsl:message>Writing <xsl:value-of select="$filename"/></xsl:message>
      <exsl:document href="{$filename}"
                     method="{$method}"
                     encoding="{$encoding}"
                     indent="{$indent}">
        <xsl:copy-of select="$content"/>
      </exsl:document>
    </xsl:when>
    <xsl:when test="element-available('saxon:output')">
      <xsl:message>Writing <xsl:value-of select="$filename"/></xsl:message>
      <saxon:output href="{$filename}"
                    method="{$method}"
                    encoding="{$encoding}"
                    indent="{$indent}">
        <xsl:copy-of select="$content"/>
      </saxon:output>
    </xsl:when>
    <xsl:when test="element-available('xalanredirect:write')">
      <!-- Xalan uses xalanredirect -->
      <xsl:message>Writing <xsl:value-of select="$filename"/></xsl:message>
      <xalanredirect:write file="{$filename}">
        <xsl:copy-of select="$content"/>
      </xalanredirect:write>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="$content"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- ============================================================ -->
<!-- HTML META -->

<xsl:template name="user.head.content">
  <xsl:param name="node" select="."/>
  <xsl:apply-templates select="//articleinfo/releaseinfo[@role='meta']"
                       mode="head.meta.content"/>
</xsl:template>

<xsl:template match="releaseinfo" mode="head.meta.content">
  <meta name="cvsinfo">
    <xsl:attribute name="content">
      <xsl:value-of select="substring-before(substring-after(.,'$'),'$')"/>
    </xsl:attribute>
  </meta>
</xsl:template>

<!-- ============================================================ -->
<!-- Titlepage -->

<xsl:template match="pubdate" mode="titlepage.mode">
  <h2>
    <xsl:choose>
      <xsl:when test="/*/@status">
        <xsl:value-of select="/*/@status"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>???Unknown Status???</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:text>&#160;</xsl:text>

    <xsl:if test="../productnumber">
      <xsl:value-of select="../productnumber[1]"/>
      <xsl:text>,&#160;</xsl:text>
    </xsl:if>

    <xsl:apply-templates mode="titlepage.mode"/>
  </h2>
</xsl:template>

<xsl:template match="productname" mode="titlepage.mode">
  <xsl:variable name="pn" select="../productnumber[1]"/>

  <dl>
    <dt><span class="docid-heading">Document identifier:</span></dt>
    <dd>
      <p>
        <xsl:value-of select="."/>
        <xsl:if test="$pn">
          <xsl:text>-</xsl:text>
          <xsl:value-of select="$pn"/>
        </xsl:if>
        <xsl:if test="../releaseinfo[@role='product']">
          <xsl:text> (</xsl:text>
          <xsl:for-each select="../releaseinfo[@role='product']">
            <xsl:if test="position() &gt; 1">, </xsl:if>
            <xsl:apply-templates select="." mode="product.mode"/>
          </xsl:for-each>
          <xsl:text>)</xsl:text>
        </xsl:if>
      </p>
    </dd>
  </dl>
</xsl:template>

<xsl:template match="releaseinfo[@role='product']" mode="titlepage.mode" priority="2">
  <!-- suppress -->
</xsl:template>

<xsl:template match="releaseinfo[@role='product']" mode="product.mode" priority="2">
  <xsl:apply-templates mode="titlepage.mode"/>
</xsl:template>

<xsl:template match="releaseinfo[@role='location']" mode="titlepage.mode" priority="2">
  <dl>
    <dt><span class="loc-heading">Location:</span></dt>
    <dd>
      <p>
        <a href="{.}">
          <xsl:value-of select="."/>
        </a>
      </p>
    </dd>
  </dl>
</xsl:template>

<xsl:template match="authorgroup" mode="titlepage.mode">
  <xsl:variable name="editors" select="editor"/>
  <xsl:variable name="authors" select="author"/>
  <xsl:variable name="contrib" select="othercredit"/>

  <xsl:if test="$editors">
    <dl>
      <dt>
        <span class="editor-heading">
          <xsl:text>Editor</xsl:text>
          <xsl:if test="count($editors) &gt; 1">s</xsl:if>
          <xsl:text>:</xsl:text>
        </span>
      </dt>
      <dd>
        <p>
          <xsl:apply-templates select="$editors" mode="titlepage.mode"/>
        </p>
      </dd>
    </dl>
  </xsl:if>

  <xsl:if test="$authors">
    <dl>
      <dt>
        <span class="author-heading">
          <xsl:text>Author</xsl:text>
          <xsl:if test="count($authors) &gt; 1">s</xsl:if>
          <xsl:text>:</xsl:text>
        </span>
      </dt>
      <dd>
        <p>
          <xsl:apply-templates select="$authors" mode="titlepage.mode"/>
        </p>
      </dd>
    </dl>
  </xsl:if>

  <xsl:if test="$contrib">
    <dl>
      <dt>
        <span class="contrib-heading">
          <xsl:text>Contributor</xsl:text>
          <xsl:if test="count($contrib) &gt; 1">s</xsl:if>
          <xsl:text>:</xsl:text>
        </span>
      </dt>
      <dd>
        <p>
          <xsl:apply-templates select="$contrib" mode="titlepage.mode"/>
        </p>
      </dd>
    </dl>
  </xsl:if>
</xsl:template>

<xsl:template match="ulink" mode="revision-links">
  <xsl:if test="position() = 1"> (</xsl:if>
  <xsl:if test="position() &gt; 1">, </xsl:if>
  <a href="{@url}"><xsl:value-of select="@role"/></a>
  <xsl:if test="position() = last()">)</xsl:if>
</xsl:template>

<xsl:template match="editor|author|othercredit" mode="titlepage.mode">
  <xsl:call-template name="person.name"/>
  <xsl:if test="contrib">
    <xsl:text> (</xsl:text>
    <xsl:apply-templates select="contrib" mode="titlepage.mode"/>
    <xsl:text>)</xsl:text>
  </xsl:if>
  <xsl:if test="affiliation/orgname">
    <xsl:text>, </xsl:text>
    <xsl:apply-templates select="affiliation/orgname" mode="titlepage.mode"/>
  </xsl:if>
  <xsl:apply-templates select="affiliation/address/email"
                       mode="titlepage.mode"/>
  <xsl:if test="position()&lt;last()"><br/></xsl:if>
</xsl:template>

<xsl:template match="email" mode="titlepage.mode">
  <xsl:text>&#160;</xsl:text>
  <xsl:apply-templates select="."/>
</xsl:template>

<xsl:template match="abstract" mode="titlepage.mode">
  <dl>
    <dt>
      <a>
        <xsl:attribute name="name">
          <xsl:call-template name="object.id"/>
        </xsl:attribute>
      </a>
      <span class="abstract-heading">
        <xsl:apply-templates select="." mode="object.title.markup"/>
        <xsl:text>:</xsl:text>
      </span>
    </dt>
    <dd>
      <xsl:apply-templates mode="titlepage.mode"/>
    </dd>
  </dl>
</xsl:template>

<xsl:template match="legalnotice[@role='status']" mode="titlepage.mode">
  <dl>
    <dt>
      <a>
        <xsl:attribute name="name">
          <xsl:call-template name="object.id"/>
        </xsl:attribute>
      </a>
      <span class="status-heading">
        <xsl:apply-templates select="." mode="object.title.markup"/>
        <xsl:text>:</xsl:text>
      </span>
    </dt>
    <dd>
      <xsl:apply-templates mode="titlepage.mode"/>
    </dd>
  </dl>
</xsl:template>

<xsl:template match="legalnotice/title" mode="titlepage.mode">
  <!-- nop -->
</xsl:template>

<xsl:template match="releaseinfo" mode="titlepage.mode">
  <xsl:comment>
    <xsl:text> </xsl:text>
    <xsl:apply-templates/>
    <xsl:text> </xsl:text>
  </xsl:comment>
</xsl:template>

<xsl:template match="jobtitle|shortaffil|orgname|contrib"
              mode="titlepage.mode">
  <xsl:apply-templates/>
</xsl:template>

<!-- ============================================================ -->
<!-- Component TOC -->

<xsl:template name="component.toc">
  <xsl:if test="$generate.component.toc != 0">
    <xsl:variable name="nodes" select="section|sect1"/>
    <xsl:variable name="apps" select="bibliography|glossary|appendix"/>

    <xsl:if test="$nodes">
      <div class="toc">
        <h2>
          <xsl:call-template name="gentext">
            <xsl:with-param name="key">TableofContents</xsl:with-param>
          </xsl:call-template>
        </h2>

        <xsl:if test="$nodes">
          <xsl:element name="{$toc.list.type}">
            <xsl:apply-templates select="$nodes" mode="toc"/>
          </xsl:element>
        </xsl:if>

        <xsl:if test="$apps">
          <h3>Appendixes</h3>

          <xsl:element name="{$toc.list.type}">
            <xsl:apply-templates select="$apps" mode="toc"/>
          </xsl:element>
        </xsl:if>
      </div>
      <hr/>
    </xsl:if>
  </xsl:if>
</xsl:template>

<!-- ================================================================= -->

<!-- support role='non-normative' -->
<xsl:template match="preface|chapter|appendix" mode="title.markup">
  <xsl:param name="allow-anchors" select="'0'"/>
  <xsl:variable name="title" select="(docinfo/title
                                      |prefaceinfo/title
                                      |chapterinfo/title
                                      |appendixinfo/title
                                      |title)[1]"/>
  <xsl:apply-templates select="$title" mode="title.markup">
    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  </xsl:apply-templates>
  <xsl:if test="@role='non-normative'">
    <xsl:text> (Non-Normative)</xsl:text>
  </xsl:if>
</xsl:template>

<!-- support role='non-normative' -->
<xsl:template match="section
                     |sect1|sect2|sect3|sect4|sect5
                     |refsect1|refsect2|refsect3
                     |simplesect"
              mode="title.markup">
  <xsl:param name="allow-anchors" select="'0'"/>
  <xsl:variable name="title" select="(sectioninfo/title
                                      |sect1info/title
                                      |sect2info/title
                                      |sect3info/title
                                      |sect4info/title
                                      |sect5info/title
                                      |refsect1info/title
                                      |refsect2info/title
                                      |refsect3info/title
                                      |title)[1]"/>

  <xsl:apply-templates select="$title" mode="title.markup">
    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  </xsl:apply-templates>
  <xsl:if test="@role='non-normative'">
    <xsl:text> (Non-Normative)</xsl:text>
  </xsl:if>
</xsl:template>

<!-- ============================================================ -->
<!-- Formatting changes for OASIS look&amp;feel -->

<xsl:template match="quote">
  <xsl:variable name="depth">
    <xsl:call-template name="dot.count">
      <xsl:with-param name="string">
        <xsl:number level="multiple"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$depth mod 2 = 0">
      <xsl:text>"</xsl:text>
      <xsl:call-template name="inline.charseq"/>
      <xsl:text>"</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>'</xsl:text>
      <xsl:call-template name="inline.charseq"/>
      <xsl:text>'</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="filename">
  <b>
    <xsl:apply-templates/>
  </b>
</xsl:template>

<!-- ============================================================ -->

<xsl:template match="para/revhistory">
  <xsl:variable name="numcols">
    <xsl:choose>
      <xsl:when test="//authorinitials">3</xsl:when>
      <xsl:otherwise>2</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <div class="{name(.)}">
    <table border="1" width="100%" summary="Revision history">
      <xsl:apply-templates mode="titlepage.mode">
        <xsl:with-param name="numcols" select="$numcols"/>
      </xsl:apply-templates>
    </table>
  </div>
</xsl:template>

<!-- ============================================================ -->

<xsl:template match="processing-instruction('lb')">
  <br/>
</xsl:template>

<!-- ============================================================ -->

</xsl:stylesheet>
