The DocBook XSLT 1.0 stylesheets support a templating mechanism for customising the title page, table of contents, and section titles. The template file is XML, of course. A template file is transformed into an XSLT module that is included when the DocBook source is transformed into XSL-FO. The template file is a mix of:
Elements and attributes specific to the template mechanism
Elements corresponding to the DocBook elements to be handled at that point
Attribute values corresponding to XSL Formatting Objects to generate
Literal XSL property attributes to generate in the output XSL-FO.
The templating mechanism does save a lot of work maintaining XSLT templates, but there is a learning curve to understanding the roles of the different elements and how they work together.
This is the beginning of the template for the front matter of an article:
<t:titlepage t:element="article" t:wrapper="fo:block-container" span="all" font-family="{$title.fontset}" padding-bottom="1lh"> <t:titlepage-content t:side="recto" start-indent="0pt" text-align="left"> <t:wrapper t:wrapper="fo:block" background-color="{$muk.background}" axf:border-radius="{$muk.border-radius}" margin-top="20mm" margin-left="-150pt" padding-left="150pt" margin-right="0" padding="{$muk.border-radius}" padding-bottom="0.25mm" axf:hanging-punctuation="start allow-end" color="{$muk.blue}"> <title t:named-template="component.title" param:node="ancestor-or-self::article[1]" keep-with-next.within-column="always" font-weight="normal" font-size="30pt"/> <subtitle font-size="20pt"/> </t:wrapper> <productname param:node="ancestor-or-self::article[1]" keep-with-next.within-column="always" font-size="30pt" font-weight="bold"/> <corpauthor space-before="0.5em" font-size="{$author.font-size}"/> <authorgroup space-before="0.5em" font-size="{$author.font-size}"/> <author space-before="0.5em" font-size="{$author.font-size}"/>
Elements and attributes with the t
namespace prefix, such as t:titlepage
, are specific to the templating mechanism. The template.xsl
stylesheet in the DocBook XSLT 1.0 distribution uses those to generate a stylesheet that can be included in the customisation. See Chapter 11, Title page customization, in DocBook XSL: The Complete Guide [DOCBOOK-XSL] for further information. Note that the t:wrapper
element to wrap the definitions for other elements is an Antenna House extension that has only just been submitted as a pull request for the XSLT 1.0 stylesheets.
Elements in the default namespace have no namespace URI. These elements correspond to DocBook elements. Depending on a setting in the template file, the elements are processed either in the order shown in the template or in document order as they appear in the DocBook document.
The generated stylesheet includes an xsl:template
for each of these elements. That template generates the element specified by the t:wrapper
attribute of the t:titlepage
element. Unprefixed attributes of the template element are copied as literal attributes on the wrapper element in the generated XSLT. The attribute values are not evaluated when the attributes are copied to the generated stylesheet, but they are evaluated when the generated stylesheet is used as part of a customisation, at which point any attribute value templates are evaluated. The generated stylesheet uses a sophisticated (or confusing, depending on your familiarity with it) arrangement of attribute sets and mode names to make it possible to influence the processing of particular elements in specific or less specific contexts.
This is the template generated for author
in the previous example:
<xsl:template match="author" mode="article.titlepage.recto.auto.mode"> <fo:block-container xmlns:fo="http://www.w3.org/1999/XSL/Format" xsl:use-attribute-sets="article.titlepage.recto.style" space-before="0.5em" font-size="{$author.font-size}"> <xsl:apply-templates select="." mode="article.titlepage.recto.mode"/> </fo:block-container> </xsl:template>
When t:named-template
is present, the generated template calls the named template instead of finding a matching template for the current element. Parameters to be passed to the named template are defined using attributes with the param
prefix; for example, param:node="ancestor-or-self::article[1]"
.
This is the template generated for title
in the previous example:
<xsl:template match="title" mode="article.titlepage.recto.auto.mode"> <fo:block-container xmlns:fo="http://www.w3.org/1999/XSL/Format" xsl:use-attribute-sets="article.titlepage.recto.style" keep-with-next.within-column="always" font-weight="normal" font-size="30pt"> <xsl:call-template name="component.title"> <xsl:with-param name="node" select="ancestor-or-self::article[1]"/> </xsl:call-template> </fo:block-container> </xsl:template>