Next / Previous / Contents / NM Tech homepage

11.2. Templates for title elements

The next line includes the generated fo-titlepage.xsl that came from the title page customization process; see Section 13, “fo-titlepage.xml: PDF title page templates”.

zdp_fo.xsl
<!--Use the locally generated title page content-->
<xsl:include href="fo-titlepage.xsl"/>

We want userinput, filename, and several other inlines to have their usual font markup inside the table of contents. This trick is discussed further in Section 7.2, “HTML title page and table of contents”.

zdp_fo.xsl
<!--Let these elements have their usual appearance in the TOC-->
<xsl:template
  match="d:filename|d:sgmltag|d:userinput|d:varname|d:code|d:application"
  mode="no.anchor.mode">
  <xsl:apply-templates select="." />
</xsl:template>

11.2.1. The article.title template

This template is invoked from the article title page; see Section 13.3, “Title page for an article.

To produce the standard title page, we want to set up a table with one row and two columns, with the document's title in the left-hand column and the logo in the right-hand column.

As page 161 of Stayton points out, there are three ways to customize titles. In ascending order by precedence:

  1. Customize the title page specification file; see Section 6, “Title page customization: XSLT that builds XSLT”.

  2. Customize the attribute set named component.title.properties.

  3. Customize the template named component.title.

Although the this style currently uses only one title element (the article element's title element), customizing component.title affects all title elements, so that approach is a bit too brute-force.

Page 162 of Stayton's book gives the procedure for customizing the title of a particular element:

  1. Copy the stock component.title template from fo/component.xsl to your customization layer, and give it a name. Here, we are customizing the title of an article element, so we'll call our copy article.title. For this template, see Section 11, “zdp_fo.xsl: PDF customization layer”.

  2. Modify the new copy to give the desired format.

  3. In the appropriate part of the title page customization file, replace the reference to component.title with a reference to the new name—in this case, article.title.

So, here is the customized article.title template. The template takes these arguments:

node

The context node containing the title.

pagewide

Originally used to specify whether the title should be stretched to the full page width. Not used here.

id

The unique identifier of the title block. If the title element has no unique ID, one will be generated for it.

title

The content of the title.

The following code is taken from the original component.title from fo/component.xsl. Some of it is relatively inscrutable, such as the part that mentions the FoTeX extensions (which might matter if we used the PassiveTeX package to produce PDF output).

zdp_fo.xsl
<!--article.title: Title components--> 
<xsl:template name="article.title">
  <xsl:param name="node" select="."/>
  <xsl:param name="pagewide" select="0"/>
  <xsl:variable name="id">
    <xsl:call-template name="object.id">
      <xsl:with-param name="object" select="$node"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="title">
    <xsl:apply-templates select="$node" mode="object.title.markup">
      <xsl:with-param name="allow-anchors" select="1"/>
    </xsl:apply-templates>
  </xsl:variable>

  <xsl:if test="$passivetex.extensions != 0">
    <fotex:bookmark xmlns:fotex="http://www.tug.org/fotex"
                    fotex-bookmark-level="2"
                    fotex-bookmark-label="{$id}">
      <xsl:value-of select="$title"/>
    </fotex:bookmark>
  </xsl:if>

The entire title content is wrapped in a fo:block container. The keep-with-next attribute stipulates that we would prefer not to break a page or column right after it. The hyphenate attribute discourages hyphenation in the title block.

zdp_fo.xsl
  <fo:block keep-with-next.within-column="always"
            hyphenate="false">

Here we start the table. Support for the various table models may vary, but table-layout="fixed" definitely works. We use a four-inch column for the title and a two-inch column for the graphic (which was sized for that space).

zdp_fo.xsl
    <fo:table table-layout="fixed" padding-bottom="0.2in">
      <fo:table-column column-number="1" column-width="4.5in"/>
      <fo:table-column column-number="2" column-width="2.25in"/>
      <fo:table-body>
        <fo:table-row>

The left-hand column contains the title text, left-justified.

zdp_fo.xsl
          <fo:table-cell>
            <fo:block text-align="left">
              <xsl:copy-of select="$title"/>
            </fo:block>
          </fo:table-cell>

The right-hand column contains the TCC logo graphic; for the definition of pdf.logo, see Section 12, “The fo_params.xsl file: PDF branding”. The padding-left attribute ensures a separation from the title. And that's the end of the template.

zdp_fo.xsl
          <fo:table-cell>
            <fo:block>
              <fo:external-graphic
                padding-left="1pc"
                content-width="2in"
                src="{$pdf.logo}"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </fo:block>
</xsl:template>

Below the table is the revhistory (revision history) element. Rather than using the RCS timestamp from the DocBook source file, we'll just show the current date and time using the EXSLT date package. This template replaces the stock revhistory template that appears in fo/titlepage.xsl.

zdp_fo.xsl
<!--revhistory on the title page-->
<xsl:template match="d:revhistory" mode="titlepage.mode">
  <xsl:call-template name="timestamp.block"/>
</xsl:template>

The timestamp.block template outputs a block containing the current date and time in the format “yyyy-mm-dd HH:MM”.

zdp_fo.xsl
<xsl:template name="timestamp.block">
  <fo:block text-align="center">
    <xsl:call-template name="datetime.format">
      <xsl:with-param name="date" select="date:date-time()"/>
      <xsl:with-param name="format" select="'Y-m-d H:M'"/>
    </xsl:call-template>
  </fo:block>
</xsl:template> <!--timestamp.block-->