Difficulty: ★★☆ (medium)
Keywords: title page, cover, recto page, verso page, title page template

Problem

You want to design a title page of your book or article.

Solution

To design your title page there are two ways to do it, regardless if it is a book or an article:

  1. Indirectly. Write a title page template which contains the wanted elements in their respective order.

  2. Directly. Customize the specific named templates.

Both methods are shown below. Although the following descriptions focus on a book title page, the same procedure applies for an article title page as well.

Before we customize the stylesheets, we need to define, what we want to display on our title page(s). Depending on if it is a left or a right page, different elements needs to be shown. For this example, we use the following requisites:

Recto (Right) Page

This is the “main page” and the content appears in the following order:

  • the book title, from /book/title or /book/info/title

  • the book subtitle, from /book/subtitle or /book/info/subtitle

  • the book's author, from /book/info/author

  • the edition, from /book/info/edition

Verso (Left) Page

This usually holds the imprint and the content appears in the following order:

  • the book's title and subtitle in a smaller font size

  • the author, from /book/info/author

  • the edition, from /book/info/edition

  • some legal text (copyright), from /book/info/legalnotice

  • the ISBN, from /book/info/biblioid with class and the value isbn

Using Title Page Templates

To create a title page using a title page template proceed as follows:

  1. Prepare the title page template:

    1. Copy the file fo/titlepage.templates.xml from the DocBook XSL stylesheet distribution to a directory where all your FO customization is stored. Use the filename booktitlepage.xml so we know, it contains only a title page for a book.

    2. Open the file booktitlepage.xml and remove anything except the root and t:titlepage elements with the attribute t:element="book". Your title page template should look like this:

      <!DOCTYPE t:templates [
      <!ENTITY hsize0 "10pt">
      <!ENTITY hsize1 "12pt">
      <!ENTITY hsize2 "14.4pt">
      <!ENTITY hsize3 "17.28pt">
      <!ENTITY hsize4 "20.736pt">
      <!ENTITY hsize5 "24.8832pt">
      <!ENTITY hsize0space "7.5pt"> <!-- 0.75 * hsize0 -->
      <!ENTITY hsize1space "9pt"> <!-- 0.75 * hsize1 -->
      <!ENTITY hsize2space "10.8pt"> <!-- 0.75 * hsize2 -->
      <!ENTITY hsize3space "12.96pt"> <!-- 0.75 * hsize3 -->
      <!ENTITY hsize4space "15.552pt"> <!-- 0.75 * hsize4 -->
      <!ENTITY hsize5space "18.6624pt"> <!-- 0.75 * hsize5 -->
      ]>
      <t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
                   xmlns:param="http://nwalsh.com/docbook/xsl/template/1.0/param"
                   xmlns:fo="http://www.w3.org/1999/XSL/Format"
                   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <t:titlepage t:element="book" t:wrapper="fo:block">
           <!-- Content disabled for better legibility -->
         </t:titlepage>
      </t:templates>
  2. Customize the content of your titlepage and save your changes into the booktitlepage.xml file.

    1. Change the recto page and locate the t:titlepage-content element with its attribute t:side="recto". As definied in Recto (Right) Page, we remove everything what is not needed. Additionally we have to output edition, which we get from an empty <edition/> tag. The content of the t:titlepage-content should look like this:

      <t:titlepage-content t:side="recto">
        <title     t:named-template="division.title"
                   param:node="ancestor-or-self::book[1]"
                   text-align="center"
                   font-size="&hsize5;"
                   space-before="&hsize5space;"
                   font-weight="bold"
                   font-family="{$title.fontset}"/>
        <subtitle  text-align="center"
                   font-size="&hsize4;"
                   space-before="&hsize4space;"
                   font-family="{$title.fontset}"/>
        <author    font-size="&hsize3;"
                   space-before="&hsize2space;"
                   keep-with-next.within-column="always"/>
        <edition   font-size="&hsize3;"/>
      </t:titlepage-content>
    2. Change the verso page and locate the t:titlepage-content element with its attribute t:side="verso". As definied in Verso (Left) Page, again, we remove everything what is not needed. The content of the t:titlepage-content should look like this:

      <t:titlepage-content t:side="verso">
        <title     t:named-template="book.verso.title"
                   font-size="&hsize2;"
                   font-weight="bold"
                   font-family="{$title.fontset}"/>
        <subtitle  t:named-template="book.verso.title"
                   font-size="&hsize2;"
                   font-weight="bold"
                   font-family="{$title.fontset}"/>
        <author/>
        <edition/>
        <legalnotice/>
        <biblioid  t:predicate="[@class = 'isbn']"/>
      </t:titlepage-content>
    3. Leave the other elements (t:titlepage-separator and t:titlepage-before) as they are.

  3. Use the template/titlepage.xsl stylesheet from the DocBook XSL distribution to transform your booktitlepage.xml title page definition to create the booktitlepage.xsl output:

    xsltproc --output booktitlepage.xsl template/titlepage.xsl booktitlepage.xml
  4. Insert the constructed booktitlepage.xsl into your customization layer mybooktitlepage.xsl:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
      <xsl:import href="https://cdn.docbook.org/release/xsl/current/fo/docbook.xsl"/>
      <xsl:include href="booktitlepage.xsl"/>
      <!-- More customizations hidden -->
    </xsl:stylesheet>
  5. Build your book as usual with your customization layer.

Customizing Title Pages Directly

To create a title page directly using named templates proceed as follows:

  1. Open the file fo/titlepage.templates.xsl of your DocBook XSL stylesheet distribution.

  2. Search for the correct template name(s). A template name is composed of the following components, wheras ELEMENT and SIDE are placeholders:

    ELEMENT.titlepage.SIDE

    As we want to change the title page of a book for the left (verso) and right (recto) pages, the correct template names are book.titlepage.recto and book.titlepage.verso.

  3. Create a new file, for example booktitlepage.xsl. This will contain all our customizations of our book's title page.

  4. Copy the book.titlepage.recto and book.titlepage.verso templates into your new file booktitlepage.xsl.

  5. Customize the template book.titlepage.recto according to the definitions in Recto (Right) Page:

    1. Leave the two xsl:choose conditions intact to select the book's title and subtitle.

    2. Insert after the last </xsl:choose> the following line to select the book's author from d:info/d:author:

      <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:info/d:author"/>
    3. Insert the following line to select the book's edition from d:info/d:edition:

      <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:info/d:edition"/>
    4. Remove the other xsl:apply-templates elements as we only want to display the title, subtitle, author, and the editor. The template should look like this:

      <xsl:template name="book.titlepage.recto">
        <xsl:choose>
          <xsl:when test="d:bookinfo/d:title">
            <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:bookinfo/d:title"/>
          </xsl:when>
          <xsl:when test="d:info/d:title">
            <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:info/d:title"/>
          </xsl:when>
          <xsl:when test="d:title">
            <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:title"/>
          </xsl:when>
        </xsl:choose>
      
        <xsl:choose>
          <xsl:when test="d:bookinfo/d:subtitle">
            <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:bookinfo/d:subtitle"/>
          </xsl:when>
          <xsl:when test="d:info/d:subtitle">
            <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:info/subtitle"/>
          </xsl:when>
          <xsl:when test="d:subtitle">
            <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:subtitle"/>
          </xsl:when>
        </xsl:choose>
      
        <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:info/d:author"/>
        <xsl:apply-templates mode="book.titlepage.recto.auto.mode" select="d:info/d:edition"/>
      </xsl:template>
  6. Customize the template book.titlepage.verso according to the definitions in Verso (Left) Page (note the different mode):

    1. Leave the two xsl:choose conditions intact to select the book's title and subtitle.

    2. Insert after the last </xsl:choose> the following line to select the book's author from d:info/d:author:

      <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:author"/>
    3. Insert the following line to select the book's edition from d:info/d:edition:

      <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:edition"/>
    4. Insert the following line to select some legal text from d:info/d:legalnotice:

      <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:legalnotice"/>
    5. Insert the following line to select the book's ISBN number from d:info/d:biblioid:

      <xsl:apply-templates mode="book.titlepage.verso.auto.mode"
          select="d:info/d:biblioid[@class='isbn']"/>
    6. Remove the other xsl:apply-templates elements as we only want display the title, subtitle, author, editor, legal text, and the ISBN number. The template should look like this:

      <xsl:template name="book.titlepage.verso">
        <xsl:choose>
          <xsl:when test="d:bookinfo/d:title">
            <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:bookinfo/d:title"/>
          </xsl:when>
          <xsl:when test="d:info/d:title">
            <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:title"/>
          </xsl:when>
          <xsl:when test="d:title">
            <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:title"/>
          </xsl:when>
        </xsl:choose>
      
        <xsl:choose>
          <xsl:when test="d:bookinfo/d:subtitle">
            <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:bookinfo/d:subtitle"/>
          </xsl:when>
          <xsl:when test="d:info/d:subtitle">
            <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:subtitle"/>
          </xsl:when>
          <xsl:when test="d:subtitle">
            <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:subtitle"/>
          </xsl:when>
        </xsl:choose>
      
        <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:author"/>
        <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:editor"/>
        <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:legalnotice"/>
        <xsl:apply-templates mode="book.titlepage.verso.auto.mode" select="d:info/d:biblioid[@class='isbn']"/>
      </xsl:template>
  7. Insert the constructed booktitlepage.xsl into your customization layer mybooktitlepage.xsl:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
      <xsl:import href="https://cdn.docbook.org/release/xsl/current/fo/docbook.xsl"/>
      <xsl:include href="booktitlepage.xsl"/>
      <!-- More customizations hidden -->
    </xsl:stylesheet>
  8. Build your book as usual with your customization layer.

Discussion

There are several reasons to customize a title page:

  • You want a different order of the default elements

  • You want to show or hide elements

  • You want to insert corporate logos, links, or other graphical illustrations

  • You want to distinguish between a document in draft or in final state.

All these requirements can be done, either with the direct or indirect method. Apart from your own preferences, use the direct method if you have more complicated conditions which can not be expressed by simple title page definitions. Sometimes it is faster to just add the respective named template instead of going through the indirect method.

Regardless which method you prefer, it ends up with the same named templates. For a book title page, the named templates are called in the following order, starting with book.titlepage:

book.titlepage
  book.titlepage.before.recto
  book.titlepage.recto
  book.titlepage.before.verso
  book.titlepage.verso
  book.titlepage.separator

Usually, the book.titlepage template is only customized in rare cases. For example, if you want to revamp the previous schema completely and add additional pages like half titles. Each of the templates in book.titlepage are responsible for a different setup of a title page. We discussed the book.titlepage.recto and book.titlepage.verso templates already. The templates book.titlepage.separator and book.titlepage.before.verso contain page breaks, whereas book.titlepage.before.recto is empty.

Note, all of the above templates process title page elements in a special mode. As you have seen in the section called “Customizing Title Pages Directly”, elements for a recto page are processed in the book.titlepage.recto.auto.mode mode. The same principle applies for a verso page and its mode book.titlepage.verso.auto.mode. However, not all elements have a template with such modes as not all elements can (and should) appear on a title page. Look into the file fo/titlepage.templates.xsl to see which are definied. Assume title and subtitle have already templates for recto and verso pages as well as all the elements which are listed in the original book.titlepage.verso and book.titlepage.recto.

For example, the edition element has certainly no templates for a recto and verso book title page. If you do not have definied one, a fallback mechanism takes place. For this reason, if you call a element in book.titlepage.verso and book.titlepage.recto, you need also to define the respective templates:

<xsl:template match="d:edition" mode="book.titlepage.recto.auto.mode">
   <!-- Add your code for a recto page -->
</xsl:template>

<xsl:template match="d:edition" mode="book.titlepage.verso.auto.mode">
   <!-- Add your code for a verso page -->
</xsl:template>

Usually, you want to display the edition on a recto page different than on a verso page.

See Also


Project@GitHubIssue#9