<!DOCTYPE xsl:stylesheet>
<!-- This customization of the docbook xsls -->
<!-- (http://docbook.sourceforge.net/) adds a full page -->
<!-- cover to a pdf using an image as a background image. -->
<!-- eps images work best for this kind of thing and will -->
<!-- fill the entire page. If you are using xep, you can use a bitmap -->
<!-- and an xep extension scales it to the right -->
<!-- size. The extension is only used if xep.extensions is -->
<!-- set to 1.  -->
<!-- To use this, just change the xsl:import to point to a -->
<!-- local version of the docbook xsls and put in a valid -->
<!-- value for the cover.path parameter (or pass it in from -->
<!-- the command line.  -->
<!-- I have only tested this with XEP. If it works with -->
<!-- other renderers or if it works, but only with some -->
<!-- changes, let me know: dcramer@broadjump.com -->
<!-- This can and probably be made to work with the -->
<!-- titlepage template system, so that you let the template -->
<!-- system control the text that appears on the -->
<!-- cover. Likewise, you can adapt it to give you full page -->
<!-- cover images on part titlepages. -->
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:rx="http://www.renderx.com/XSL/Extensions"
  version='1.0'>
<!-- Adjust this to point to your docbook distribution. I've -->
<!-- tested it with 1.55.0, but it probably works with other -->
<!-- versions. -->
<xsl:import href="/net/monolith/homes/dcramer/work.head/docmodules/doctools/1.0/DocBookXSL/1.60.1/fo/docbook.xsl"/>
<!-- This is stuff I needed to have for my environment. Delete or -->
<!-- change as you wish.  -->
<xsl:param name="draft.watermark.image" select="'../common/draft.png'"/>
<xsl:param name='admon.graphics.path' select="'../common/'"/>
<xsl:param name="callout.graphics.path" select="'../common/'"/>
<!-- End of stuff I needed to have for my env.  -->
<!-- Define the path to your cover here. You might also so -->
<!-- something like:
  <xsl:param name="cover.path"><xsl:value-of 
  select="normalize-space(//bookinfo//imagedata/@fileref)"/></xsl:param>
  Assuming that you've got an image defined in your bookinfo.
 -->
<xsl:param name="cover.path">../common/motivecover.jpg</xsl:param>
<xsl:param name="xep.extensions" select="0"/>
<xsl:param name="fop.extensions" select="0"/>

  <xsl:template name="user.pagemasters">
<fo:simple-page-master
  margin-right="0in" 
  margin-left="0in" 
  margin-bottom="0in" 
  margin-top="0in"
  page-height="{$page.height}" 
  page-width="{$page.width}" 
  master-name="cover">
  <fo:region-body
margin-bottom="0in"
margin-top="0in"
margin-left="0in"
margin-right="0in"
background-repeat="no-repeat"
background-image="{$cover.path}">
<!-- This _should_ work :) If the filename of the
cover doesn't end in eps and you're using XEP, then
use XEP's extensions to side the cover image to 8.5
x 11.  -->
<xsl:if 
  test="not(substring(translate($cover.path, 
  'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  'abcdefghijklmnopqrstuvwxyz'),
  (string-length(normalize-space($cover.path)) - 2), 3) = 'eps') and
  $xep.extensions != '0'">
  <xsl:attribute name="rx:background-content-width">
<xsl:value-of select="$page.width"/>
  </xsl:attribute>
  <xsl:attribute name="rx:background-content-height">
<xsl:value-of select="$page.height"/>
  </xsl:attribute>
</xsl:if>
  </fo:region-body>
  <fo:region-before 
extent="0pt"
display-align="after"
region-name="xsl-region-before-first"/>
  <fo:region-after 
extent="0pt"
display-align="after"
region-name="xsl-region-after-first"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="coversequence">
  <fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference 
master-reference="cover" page-position="first"/>
  <fo:conditional-page-master-reference 
  master-reference="blank" blank-or-not-blank="blank"/>
  </fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
  </xsl:template>
<!-- This overrides a template in fo/docbook.xsl  -->
<xsl:template match="/">
  <xsl:message>
    <xsl:text>Making </xsl:text>
    <xsl:value-of select="$page.orientation"/>
    <xsl:text> pages on </xsl:text>
    <xsl:value-of select="$paper.type"/>
    <xsl:text> paper (</xsl:text>
    <xsl:value-of select="$page.width"/>
    <xsl:text>x</xsl:text>
    <xsl:value-of select="$page.height"/>
    <xsl:text>)</xsl:text>
  </xsl:message>
  <xsl:variable name="document.element" select="*[1]"/>
  <xsl:variable name="title">
    <xsl:choose>
      <xsl:when test="$document.element/title[1]">
        <xsl:value-of select="$document.element/title[1]"/>
      </xsl:when>
      <xsl:otherwise>[could not find document title]</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <fo:root font-family="{$body.font.family}"
           font-size="{$body.font.size}"
           text-align="{$alignment}">
    <xsl:if test="$xep.extensions != 0">
      <xsl:call-template name="xep-document-information"/>
    </xsl:if>
    <xsl:call-template name="setup.pagemasters"/>
    <xsl:choose>
      <xsl:when test="$rootid != ''">
        <xsl:choose>
          <xsl:when test="count(id($rootid)) = 0">
            <xsl:message terminate="yes">
              <xsl:text>ID '</xsl:text>
              <xsl:value-of select="$rootid"/>
              <xsl:text>' not found in document.</xsl:text>
            </xsl:message>
          </xsl:when>
          <xsl:otherwise>
            <xsl:if test="$fop.extensions != 0">
              <xsl:apply-templates select="id($rootid)" mode="outline"/>
            </xsl:if>
            <xsl:if test="$xep.extensions != 0">
              <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
                <xsl:apply-templates select="id($rootid)" mode="xep.outline"/>
              </rx:outline>
            </xsl:if>
            <xsl:apply-templates select="id($rootid)"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="$fop.extensions != 0">
          <xsl:apply-templates mode="outline"/>
        </xsl:if>
        <xsl:if test="$xep.extensions != 0">
          <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
            <xsl:apply-templates mode="xep.outline"/>
          </rx:outline>
        </xsl:if>
  <fo:page-sequence master-reference="coversequence">
<!-- Use no-force to prevent a blank page after the
cover. -->
<xsl:attribute
  name="force-page-count">even</xsl:attribute>
<fo:flow flow-name="xsl-region-body">
  
  <!-- Put whatever fo you want here. Note that if
  you don't put at least _something_ on the
  cover, the page isn't generated. So if you
  have a cover graphic that already has the
  title on it, you need to put some kind of
  invisible character here, like a . that's 1pt.
  The markup below just puts the doc title there.-->
<fo:block
  margin-top="3in"
  margin-left="{$page.margin.inner}"
  margin-right="{$page.margin.outer}"
  text-align="center" 
  color="black" 
  font-weight="bold"
  font-family="{$title.font.family}" 
  font-size="30pt">
  <xsl:value-of select="$title"/>
  </fo:block>
 
</fo:flow>
  </fo:page-sequence>
  
  
  <xsl:apply-templates/>
</xsl:otherwise>
  </xsl:choose>
  
</fo:root>
  </xsl:template>
</xsl:stylesheet>