Chapter 11. HTML customizations

Table of Contents

HTML headers and footers
Adding extra lines
Navigational labels or graphics
Brief headers and footers
Replace headers and footers
Server-side includes
Inserting external HTML code
In the page header
In the HEAD element
In the page content
HTML HEAD elements
Adding CSS style rules
Embedding CSS styles
Adding a date timestamp
Removing the HEAD element
BODY attributes
HTML frameset
Chunking customization
Separate legalnotice
Filename of the legalnotice chunk
More than one legalnotice

This chapter describes some of the more commonly used customizations for HTML output. They use the techniques described in Chapter 8, Customization methods. Before you start writing a customization layer for HTML, consider whether you really need one.

Use the methods described in this chapter if neither of the above can meet your needs.

HTML headers and footers

The DocBook XSL stylesheets provide options for controlling HTML headers and footers. First, let's distinguish the two kinds of headers in HTML:

  • Generated content to be displayed at the top of chunked HTML output.

  • HTML elements that should appear in the HEAD of the HTML file. See the section “HTML HEAD elements” for more information on this kind of header.

This section covers just the first kind of header. By default, chunked HTML output gets a couple of lines of navigational links at the top and bottom of each output file. That permits the user to move from file to file to see all the content. If you don't chunk your HTML output, then there is no displayed header or footer in the file.

Adding extra lines

If you want to leave the navigational headers and footers in place, and just add something of your own, such as a copyright line, then you can fill in some no-op templates that are already called by the stylesheets. These are the header and footer templates in the order in which they are called on the page, including four that can be user defined:

Table 11.1. Templates for HTML headers and footers

Template nameWhen it is called
user.header.navigationCalled before standard navigational header.
header.navigationThe standard navigational header.
user.header.contentCalled after standard navigational header but before any other content.
user.footer.contentCalled after the chunk content but before the standard navigational footer.
footer.navigationThe standard navigational footer.
user.footer.navigationCalled after the standard navigational footer.

Inserting a copyright

Here is an example of adding a copyright statement to the bottom of each chunked file, above the standard navigational footer:

<xsl:template name="user.footer.content">
  <HR/><P class="copyright">&#x00A9; 2002  Megacorp, Inc.</P>
</xsl:template>

If you would rather have the copyright appear below the navigational footer, then use the user.footer.navigational template instead. The content of the template can include IMG elements to reference a graphical logo, and any other HTML content that makes sense. If you add class attributes, then you can control the formatting with your CSS stylesheet.

Inserting a CVS identifier

If your DocBook XML file is kept under a content management system such as CVS, you might want to insert the CVS version information on the HTML pages generated from the file. That informs the reader of when the content of the page was last changed.

The XSLT processor cannot directly request the version identifier from the CVS system. But that information can be stored in the XML document itself, where the stylesheet can access it. The trick is to put the CVS identifier string $Id​$ in a releaseinfo element in your document. It can go in the bookinfo element of a book, or the articleinfo element of an article. Each time the file is checked into the CVS system, the identifier string is updated by CVS with the latest information. For example:

<revisioninfo>
  $Id: dbxsl.xml,v 1.49 2005/03/02 18:08:12 bobs Exp $
</revisioninfo

Once this information is in the XML file, it is easy to insert it into the HTML footer:

<xsl:template name="user.footer.content">
  <P class="CVSinfo">
    <xsl:value-of select="//releaseinfo[1]"/>
  </P>
</xsl:template>

The select attribute has an XPath expression that finds the first releaseinfo element in the document, and the xsl:value-of element takes its string value.

Navigational labels or graphics

The standard navigational headers and footers in chunked output use words such as Next, Prev, Up, and Home.

You can replace those words with different words by customizing the generated text. See the section “Customizing generated text” for a description of this method of customization. Here is an example that changes the word Home with Table of Contents for English output:

<xsl:param name="local.l10n.xml" select="document('')" />
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
 <l:l10n language="en">
  <l:gentext key="nav-home" text="Table of Contents"/>
 </l:l10n>
</l:i18n>

See the stylesheet file common/en.xml to see all the l:gentext elements with key names that begin with nav- that specify the navigational labels.

You can also replace the navigational words with graphical icons. See the section “Navigational icons” for the parameters to turn that feature on. You can also supply your own graphics.

Brief headers and footers

The standard navigational headers and footers also show the titles of the other files by default. If you want a very clean presentation without the titles, then you can set the navig.showtitles parameter to zero (it is 1 by default). Then you will see only Next and Prev or their icon equivalents.

Replace headers and footers

If you decide you need to completely replace the navigational headers and footers, then you can either create replacement templates, or you can turn them off and apply the user-defined templates instead.

If you want to retain the navigational features such as Next and Previous, then it is probably easiest to modify the existing templates. Copy the templates named header.navigation and footer.navigation from the html/chunk-common.xsl file to your customization layer for modification. You'll find they are substantial templates that create small tables to format the header and footer. They are passed two parameters named prev and next, which are the XML nodes for those pointers.

If your goal is to completely replace the standard headers and footers, then set the suppress.navigation parameter to 1 to turn them off. You can then define your own in templates named user.header.navigation and user.footer.navigation. If you don't define any new templates, then you will completely suppress headers and footers.