<?xml version='1.0' encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>

<!-- We want the TOC links in the titles, and in blue. -->
<xsl:param name="latex.hyperparam">colorlinks,linkcolor=blue,pdfstartview=FitH</xsl:param>

<!-- Put the dblatex logo -->
<xsl:param name="doc.publisher.show">1</xsl:param>

<!-- Show the list of examples too -->
<xsl:param name="doc.lot.show">figure,table,example</xsl:param>

<!-- DocBook like description -->
<xsl:param name="term.breakline">1</xsl:param>

<!-- Use graphics in equations -->
<xsl:param name="tex.math.in.alt">0</xsl:param>

<!-- No hyperlink in example captions -->
<xsl:template match="sgmltag[ancestor::example]">
  <xsl:apply-imports/>
</xsl:template>

<!-- How to handle the tag linking. Avoids hyphenation in the link,
     and prevents from putting too much thing in the margin (\sloppy)
-->
<xsl:template match="book|article" mode="preamble">
  <xsl:param name="lang"/>
  <xsl:text>\def\hyperlunk#1#2{</xsl:text>
  <xsl:text>\hyperlink{#1}{\texttt{#2}}</xsl:text>
  <xsl:text>}&#10;</xsl:text>
  <xsl:text>\def\hypertag#1#2{</xsl:text>
  <xsl:text>\sloppy\hyperlink{#1}{\texttt{#2}}</xsl:text>
  <xsl:text>}&#10;</xsl:text>
  <xsl:apply-imports />
</xsl:template>

<!-- Hot links to element references -->
<xsl:template match="sgmltag">
  <xsl:variable name="class">
    <xsl:choose>
      <xsl:when test="@class">
        <xsl:value-of select="@class"/>
      </xsl:when>
      <xsl:otherwise>element</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="elem">
    <xsl:value-of select="translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                      'abcdefghijklmnopqrstuvwxyz')"/>
  </xsl:variable>

  <xsl:variable name="elemidval">
    <xsl:value-of select="$elem"/>
    <xsl:text>.element</xsl:text>
  </xsl:variable>

  <xsl:variable name="peidval">
    <xsl:value-of select="$elem"/>
    <xsl:text>.parament</xsl:text>
  </xsl:variable>

  <xsl:variable name="elemtext">
    <xsl:call-template name="sgmltag.hyphenate">
      <xsl:with-param name="text" select="$elem"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:message><xsl:value-of select="$elemtext"/></xsl:message>

  <!-- The macro to use depends on context -->
  <xsl:variable name="hypertag">
    <xsl:choose>
    <xsl:when test="ancestor::entry">
      <xsl:value-of select="'\hyperlunk'"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="'\hypertag'"/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="$class = 'element' and count(id($elemidval)) &gt; 0">
      <xsl:variable name="targets" select="id($elemidval)"/>
      <xsl:variable name="target" select="$targets[1]"/>
      <xsl:value-of select="$hypertag"/>
      <xsl:text>{</xsl:text>
      <xsl:value-of select="$elemidval"/> 
      <xsl:text>}{</xsl:text>
      <xsl:value-of select="$elem"/>
      <xsl:text>}</xsl:text>
    </xsl:when>
    <xsl:when test="$class = 'paramentity' and count(id($peidval)) &gt; 0">
      <xsl:variable name="targets" select="id($peidval)"/>
      <xsl:variable name="target" select="$targets[1]"/>
      <xsl:value-of select="$hypertag"/>
      <xsl:text>{</xsl:text>
      <xsl:value-of select="$peidval"/> 
      <xsl:text>}{</xsl:text>
      <xsl:value-of select="concat('\%',$elem,';')"/>
      <xsl:text>}</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-imports/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
