You want to design a title page of your book or article.
To design your title page there are two ways to do it, regardless if it is a book or an article:
Indirectly. Write a title page template which contains the wanted elements in their respective order.
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:
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
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
To create a title page using a title page template proceed as follows:
To create a title page directly using named templates proceed as follows:
Open the file
fo/titlepage.templates.xsl
of your
DocBook XSL stylesheet distribution.
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
.
Create a new file, for example
booktitlepage.xsl
. This will contain all our
customizations of our book's title page.
Copy the book.titlepage.recto
and
book.titlepage.verso
templates into
your new file booktitlepage.xsl
.
Customize the template
book.titlepage.recto
according to the
definitions in
Recto (Right) Page:
Leave the two xsl:choose
conditions intact to
select the book's title and subtitle.
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"/>
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"/>
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>
Customize the template
book.titlepage.verso
according to the
definitions in Verso (Left) Page
(note the different mode):
Leave the two xsl:choose
conditions intact to
select the book's title and subtitle.
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"/>
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"/>
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"/>
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']"/>
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>
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>
Build your book as usual with your customization layer.
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.
Project@GitHub | Issue#9 |