Next / Previous / Contents / NM Tech homepage

11.3. PDF headers and footers

By default, the header area on each page is set off from the content with a ruled line. Because the TCC style does not use a running head, we turn off header.rule to eliminate this rule.

zdp_fo.xsl
<!--header.rule: Disable a ruled line below the running head-->
<xsl:param name="header.rule" select="0"/>

The stock header.content template is in fo/pagesetup.xsl; this template generates the content of the running head. We replace that here with one that has no content.

zdp_fo.xsl
<!--Content of the running head-->
<xsl:template name="header.content">
  <xsl:param name="pageclass" select="''"/>
  <xsl:param name="sequence" select="''"/>
  <xsl:param name="position" select="''"/>
  <xsl:param name="gentext-key" select="''"/>
</xsl:template>

Footer customization is discussed at length in Chapter 12 of Stayton under the heading “Running headers and footers.”

First we change the appearance of the text in the running footer to make it look different from the body text. This is specified by the footer.content.properties attribute set; the stock version is in fo/param.xsl. The TCC Documentation Plan mandates nine-point italic text.

zdp_fo.xsl
<!--footer.content.properties: Appearance of the running footer-->
<xsl:attribute-set name="footer.content.properties">
  <xsl:attribute name="font-style">italic</xsl:attribute>
  <xsl:attribute name="font-size">9pt</xsl:attribute>

The rest of this attribute set is from the stock version.

zdp_fo.xsl
  <xsl:attribute name="font-family">
    <xsl:value-of select="$body.fontset"/>
  </xsl:attribute>
  <xsl:attribute name="margin-left">
    <xsl:value-of select="$title.margin.left"/>
  </xsl:attribute>
</xsl:attribute-set>

The footer is formatted as a one-row, three-column table. The footer's content depends on two variables:

In our format, the content of the three columns of the footer table is shown by this table. The “Case” column describes which case applies, and the three cells of the footer table are called left, center, and right.

Caseleftcenterright
pageclass is titlepageblankblankblank
Not titlepage, single-sided titlefoliologo
Not titlepage, double-sided, odd/first pages titlefoliologo
Not titlepage, double-sided, even/blank pages titlefoliologo

This layout puts the page number in the center of single-sided pages, the outside of double-sided pages.

So, here's the footer.content template. It is called once for each of the three different footer positions, and returns the content that should go in that position. It takes four parameters: pageclass, sequence, and position are described above. The gentext-key parameter is not used; its function is discussed on p. 195 of Stayton.

zdp_fo.xsl
<!--footer.content: Pieces of the running footer-->
<xsl:template name="footer.content">
  <xsl:param name="pageclass" select="''"/>
  <xsl:param name="sequence" select="''"/>
  <xsl:param name="position" select="''"/>
  <xsl:param name="gentext-key" select="''"/>

The entire footer content is wrapped in a block container.

zdp_fo.xsl
  <fo:block>

First we eliminate the titlepage case: there is no footer on title pages. (The current article style has no separate title page, if you're wondering how come all the TCC documents have a running footer on the first page.)

zdp_fo.xsl
    <xsl:choose>
      <xsl:when test="$pageclass = 'titlepage'">
        <!--no footer on title pages-->
      </xsl:when>

For non-title pages, the next important case is single-sided output.

zdp_fo.xsl
      <xsl:otherwise>       <!--Not a title page-->
        <xsl:choose>
          <xsl:when test="$double.sided = 0">   <!-- Single-sided -->
            <xsl:choose>
              <xsl:when test="$position = 'left'">
                <xsl:apply-templates select="."
                    mode="titleabbrev.markup"/>
              </xsl:when>
              <xsl:when test="$position = 'center'">
                <fo:page-number/>
              </xsl:when>
              <xsl:when test="$position = 'right'">
                <xsl:value-of select="$pdf.org.name"/>
              </xsl:when>
            </xsl:choose>
          </xsl:when>       <!-- Single-sided -->

The titleabbrev.markup mode selects a titleabbrev if there is one, defaulting to the document's title.

The remaining cases are for the two double-sided formats. First, the left position, which is the logo for odd pages and the page number for even pages.

zdp_fo.xsl
          <xsl:otherwise>   <!--Double-sided--> 
            <xsl:choose>
              <xsl:when test="$position = 'left'">
                <xsl:choose>
                  <xsl:when test="$sequence = 'even' or
                                  $sequence = 'blank'">
                    <fo:page-number/>
                  </xsl:when>
                  <xsl:otherwise> <!-- left/odd -->
                    <xsl:value-of select="$pdf.org.name"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>

The center position always contains the running title.

zdp_fo.xsl
              <xsl:when test="$position = 'center'">
                <xsl:apply-templates select="." mode="titleabbrev.markup"/>
              </xsl:when>

The right position on a double-sided page contains the folio on odd pages, the logo on even pages.

zdp_fo.xsl
              <xsl:when test="$position = 'right'">
                <xsl:choose>
                  <xsl:when test="$sequence = 'even' or
                                  $sequence = 'blank'">

                    <xsl:value-of select="$pdf.org.name"/>
                  </xsl:when>
                  <xsl:otherwise> <!-- left/odd -->
                    <fo:page-number/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
            </xsl:choose>
          </xsl:otherwise>  <!-- Double-sided -->
        </xsl:choose>
      </xsl:otherwise>      <!--Not a title page-->
    </xsl:choose>
  </fo:block>
</xsl:template>

11.3.1. Other header/footer options to consider

Why did we decide to have no running head? The principal motivation was aesthetics, and also to reclaim a bit more page for functional content.

However, one annoying property of this layout is that the running title has to fit in a fairly restricted space. If the document title is too long, it will be folded in the footer, which is pretty ugly. The cure for that is to add a titleabbrev element just after the document's title element; the content of that element will be substituted for the full title in the running footer.

Here is a more conventional plan that would get around this problem:

  • Place the running title in the header. It would be left-justified on even pages, right-justified otherwise. To set it off from the body of the page with a ruled line, header.rule should be turned back on.

  • In the running footer, put the folio on the outside and the logo on the inside.