<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
        xmlns:xverb="com.nwalsh.xalan.Verbatim"
        xmlns:lxslt="http://xml.apache.org/xslt">

  <!-- xsl:import href="http://docbook.sourceforge.net/release/xsl/1.65.1/fo/docbook.xsl"/ -->
  <xsl:import href="http://docbook.sourceforge.net/release/xsl/1.75.2/fo/docbook.xsl"/>
    
  <xsl:param name="callout.graphics" select="'0'"/>
  <xsl:param name="callout.unicode" select="1"/>
  <!--xsl:param name="callout.defaultcolumn" select="'80'"/-->
  <xsl:param name="draft.mode" select="'no'"/>
  <xsl:param name="ulink.hyphenate" select="'&#xAD;'"/>
  <xsl:param name="use.extensions" select="'1'"/>
  <xsl:param name="xep.extensions" select="1"/>

<!--footnote.mark font size-->

  <xsl:template name="format.footnote.mark">
  <xsl:param name="mark" select="'?'"/>
  <fo:inline font-size="70%">
    <xsl:choose>
      <xsl:when test="$fop.extensions != 0">
        <xsl:attribute name="vertical-align">super</xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="baseline-shift">super</xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:copy-of select="$mark"/>
  </fo:inline>
</xsl:template>

  <xsl:attribute-set name="monospace.properties">
    <xsl:attribute name="font-family">LuxiMono</xsl:attribute>
    <xsl:attribute name="font-size-adjust">0.44</xsl:attribute>
    <xsl:attribute name="hyphenate">false</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="monospace.verbatim.properties" use-attribute-sets="verbatim.properties monospace.properties">
    <xsl:attribute name="text-align">start</xsl:attribute>
    <xsl:attribute name="wrap-option">wrap</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="monospace.verbatim.properties" 
    use-attribute-sets="verbatim.properties monospace.properties">
    <xsl:attribute name="line-stacking-strategy">font-height</xsl:attribute>
  </xsl:attribute-set>

  <xsl:param xmlns:fo="http://www.w3.org/1999/XSL/Format" name="ebnf.assignment">
    <fo:inline xsl:use-attribute-sets="monospace.properties">
      <xsl:text>::=</xsl:text>
    </fo:inline>
  </xsl:param>

  <xsl:attribute-set name="formal.title.properties" use-attribute-sets="normal.para.spacing">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">
      <xsl:value-of select="$body.font.master * 1.2"/>
      <xsl:text>pt</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="text-align">start</xsl:attribute>
    <xsl:attribute name="hyphenate">false</xsl:attribute>
    <xsl:attribute name="space-after.minimum">0.4em</xsl:attribute>
    <xsl:attribute name="space-after.optimum">0.6em</xsl:attribute>
    <xsl:attribute name="space-after.maximum">0.8em</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="section.title.properties">
    <xsl:attribute name="font-family">
      <xsl:value-of select="$title.font.family"/>
    </xsl:attribute>
    <xsl:attribute name="text-align">start</xsl:attribute>
    <xsl:attribute name="hyphenate">false</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <!-- font size is calculated dynamically by section.heading template -->
    <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
    <xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
    <xsl:attribute name="space-before.optimum">1.0em</xsl:attribute>
    <xsl:attribute name="space-before.maximum">1.2em</xsl:attribute>
  </xsl:attribute-set>

    <xsl:attribute-set name="chapter.titlepage.recto.style">
      <xsl:attribute name="text-align">start</xsl:attribute>
      <xsl:attribute name="hyphenate">false</xsl:attribute>
    </xsl:attribute-set>

  <xsl:template name="callout-bug">
    <xsl:param name="conum" select='1'/>
  
    <xsl:choose>
      <xsl:when test="$conum &lt;= $callout.unicode.number.limit">
        <xsl:variable name="comarkup">
          <xsl:choose>
            <xsl:when test="$callout.unicode.start.character = 10102">
              <xsl:choose>
                <xsl:when test="$conum = 1">&#10102;</xsl:when>
                <xsl:when test="$conum = 2">&#10103;</xsl:when>
                <xsl:when test="$conum = 3">&#10104;</xsl:when>
                <xsl:when test="$conum = 4">&#10105;</xsl:when>
                <xsl:when test="$conum = 5">&#10106;</xsl:when>
                <xsl:when test="$conum = 6">&#10107;</xsl:when>
                <xsl:when test="$conum = 7">&#10108;</xsl:when>
                <xsl:when test="$conum = 8">&#10109;</xsl:when>
                <xsl:when test="$conum = 9">&#10110;</xsl:when>
                <xsl:when test="$conum = 10">&#10111;</xsl:when>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:message>
                <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
                <xsl:text>when $callout.unicode.start.character is </xsl:text>
                <xsl:value-of select="$callout.unicode.start.character"/>
              </xsl:message>
              <fo:inline background-color="#404040"
                         color="white"
                         padding-top="0.1em"
                         padding-bottom="0.1em"
                         padding-start="0.2em"
                         padding-end="0.2em"
                         baseline-shift="0.1em"
                         font-family="{$body.fontset}"
                         font-weight="bold"
                         font-size="75%"
                         font-size-adjust="1">
                <xsl:value-of select="$conum"/>
              </fo:inline>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
  
        <xsl:choose>
          <xsl:when test="$callout.unicode.font != ''">
            <fo:inline font-family="{$callout.unicode.font}" font-size-adjust="1">
              <xsl:copy-of select="$comarkup"/>
            </fo:inline>
          </xsl:when>
          <xsl:otherwise>
            <xsl:copy-of select="$comarkup"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
  
      <!-- Most safe: draw a dark gray square with a white number inside -->
      <xsl:otherwise>
        <fo:inline background-color="#404040"
                   color="white"
                   padding-top="0.1em"
                   padding-bottom="0.1em"
                   padding-start="0.2em"
                   padding-end="0.2em"
                   baseline-shift="0.1em"
                   font-family="{$body.fontset}"
                   font-weight="bold"
                   font-size="75%"
                   font-size-adjust="1">
          <xsl:value-of select="$conum"/>
        </fo:inline>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="longest.term">
    <xsl:param name="longest" select="0"/>
    <xsl:param name="terms" select="."/>
    <xsl:param name="maxlength" select="-1"/>

    <xsl:choose>
      <xsl:when test="$longest &gt; $maxlength and $maxlength &gt; 0">
	<xsl:value-of select="$maxlength"/>
      </xsl:when>
      <xsl:when test="not($terms)">
        <xsl:choose>
	  <xsl:when test="$longest &gt; 0">
	    <xsl:value-of select="$longest"/>
          </xsl:when>
	  <xsl:otherwise>
	    <xsl:value-of select="$variablelist.max.termlength div 2"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when test="string-length($terms[1]/node()[not(indexterm)]) &gt; $longest">
	<xsl:call-template name="longest.term">
	  <xsl:with-param name="longest" 
	      select="string-length($terms[1]/node()[not(indexterm)])"/>
	  <xsl:with-param name="maxlength" select="$maxlength"/>
	  <xsl:with-param name="terms" select="$terms[position() &gt; 1]"/>
	</xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
	<xsl:call-template name="longest.term">
	  <xsl:with-param name="longest" select="$longest"/>
	  <xsl:with-param name="maxlength" select="$maxlength"/>
	  <xsl:with-param name="terms" select="$terms[position() &gt; 1]"/>
	</xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  
</xsl:stylesheet>
