<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  xmlns:d     = "http://docbook.org/ns/docbook"
  xmlns:xsl   = "http://www.w3.org/1999/XSL/Transform"
  xmlns:fo    = "http://www.w3.org/1999/XSL/Format"
  version     = "5.0"
  xmlns:l     = "http://docbook.sourceforge.net/xmlns/l10n/1.0">

  <xsl:import
    href    = "../docbook-xsl-1.73.2/fo/docbook.xsl" />

  <!--
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  Page Header
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  -->
  <xsl:param
    name    = "header.rule"
    select  = "1" />

  <xsl:param
    name    = "headers.on.blank.pages"
    select  = "1" />

  <xsl:param
    name    = "header.column.widths">1 2 1</xsl:param>

  <xsl:attribute-set
    name    = "header.content.properties">

    <xsl:attribute
      name    = "font-family">sans-serif</xsl:attribute>
    <xsl:attribute
      name    = "font-size">10pt</xsl:attribute>

  </xsl:attribute-set>

  <!--
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  Header Content

  @param    pageclass   e.g. titlepage
  @param    sequence    e.g. even, odd, first, blank
  @param    position    e.g. left, center, right
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  -->
  <xsl:template name= "header.content">

    <xsl:param
      name    = "pageclass"
      select  = "''" />
    <xsl:param
      name    = "sequence"
      select  = "''" />
    <xsl:param
      name    = "position"
      select  = "''" />
    <xsl:param
      name    = "gentext-key"
      select  = "''" />

    <xsl:variable
      name    = "hdrContent">

      <xsl:choose>
        <!-- Odd pages -->
        <xsl:when
          test="$sequence = 'odd' and $position = 'left'">
          <xsl:text>Odd:Left</xsl:text>
        </xsl:when>

        <xsl:when
            test="$sequence = 'odd' and $position = 'center'">
            <xsl:value-of  select="ancestor-or-self::d:book/d:info/d:title"/>
        </xsl:when>

        <xsl:when
            test="$sequence = 'odd' and $position = 'right'">
            <xsl:value-of  select="ancestor-or-self::d:book/d:info/d:releaseinfo"/>
        </xsl:when>

        <!-- Even pages -->
        <xsl:when
            test="$sequence = 'even' and $position = 'left'">
          <xsl:text>Even:Left</xsl:text>
        </xsl:when>

        <xsl:when
            test="$sequence = 'even' and $position = 'center'">
            <xsl:value-of  select="ancestor-or-self::book/info/title"/>
        </xsl:when>

        <xsl:when
            test= "$sequence = 'even' and $position = 'right'">
            <xsl:value-of  select="/book/info/releaseinfo"/>
        </xsl:when>

        <!-- First pages -->
        <xsl:when
            test= "$sequence = 'first' and $position = 'left'">
          <xsl:text>First:Left</xsl:text>
        </xsl:when>

        <xsl:when
            test= "$sequence = 'first' and $position = 'center'">
            <xsl:text>[</xsl:text><xsl:value-of  select="/book/info/title"/><xsl:text>]</xsl:text>
        </xsl:when>
        
        <xsl:when
            test= "$sequence = 'first' and $position = 'right'">
            <xsl:value-of  select="/d:book/d:info/d:releaseinfo"/>
        </xsl:when>


        <!-- Blank pages -->
        <xsl:when
            test= "$sequence = 'blank' and $position = 'left'">
          <xsl:text>Blank:Left</xsl:text>
        </xsl:when>

        <xsl:when
            test= "$sequence = 'blank' and $position = 'center'">
            <xsl:value-of  select="ancestor-or-self::d:book/d:info/d:title"/>
        </xsl:when>

        <xsl:when
            test= "$sequence = 'blank' and $position = 'right'">
            <xsl:value-of  select="ancestor-or-self::d:book/d:info/d:releaseinfo"/>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    <!--
    ====================================================================
    Is page header turned off at runtime?
    ====================================================================
    -->
    <xsl:choose>
      <xsl:when
          test="$sequence='blank' and $headers.on.blank.pages=0">
      <!-- no output -->
      </xsl:when>

      <xsl:otherwise>
          <xsl:copy-of select= "$hdrContent" />
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

</xsl:stylesheet>
