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


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

  <xsl:output method="html"
       encoding="ISO-8859-1"
       doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
       doctype-system="http://www.w3.org/TR/html4/loose.dtd"
       indent="no"/>
  
  <!-- bibref: reference to a bibliographic entry -->
  <!-- make a link to the bibl -->
  <!-- if the bibl has a key, put it in square brackets; otherwise use
       the bibl's ID -->
  <xsl:template match="bibref">
    <xsl:text>[</xsl:text>
    <cite><a>
      <xsl:attribute name="href">
        <xsl:call-template name="href.target">
          <xsl:with-param name="target" select="id(@ref)"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:choose>
        <xsl:when test="id(@ref)/@key">
          <xsl:value-of select="id(@ref)/@key"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@ref"/>
        </xsl:otherwise>
      </xsl:choose>
    </a></cite>
    <xsl:text>]</xsl:text>
  </xsl:template>

  <xsl:template match="bibl">
    <dt class="label">
      <xsl:attribute name="class">
	<xsl:choose>
	  <xsl:when test="@diff and $show.diff.markup != 0">
	    <xsl:text>diff-</xsl:text>
	    <xsl:value-of select="@diff"/>
	  </xsl:when>
	  <xsl:otherwise>
  	    <xsl:text>label</xsl:text>
	  </xsl:otherwise>
	</xsl:choose>
      </xsl:attribute>
      <xsl:if test="@id">
	<a name="{@id}"/>
      </xsl:if>
      <xsl:text>[</xsl:text>
      <xsl:choose>
	<xsl:when test="@key">
	  <xsl:value-of select="@key"/>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:value-of select="@id"/>
	</xsl:otherwise>
      </xsl:choose>
      <xsl:text>] </xsl:text>
    </dt>
    <dd>
      <xsl:if test="@diff and $show.diff.markup != 0">
	<xsl:attribute name="class">
  	  <xsl:text>diff-</xsl:text>
  	  <xsl:value-of select="@diff"/>
	</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
      <xsl:if test="not(titleref) and @href">
        <xsl:text>  (See </xsl:text>
        <cite>
	  <a href="{@href}">
	    <xsl:value-of select="@href"/>
	  </a>
	</cite>
        <xsl:text>.)</xsl:text>
      </xsl:if>
    </dd>
  </xsl:template>

  <xsl:template match="titleref">
    <xsl:choose>
      <xsl:when test="../@href">
	<cite>
	  <a href="{../@href}">
            <xsl:apply-templates/>
	  </a>
	</cite>
      </xsl:when>
      <xsl:otherwise>
        <cite>
          <xsl:apply-templates/>
        </cite>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
