Table of Contents
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.
If you just want to customize how your HTML looks, then you can use a CSS stylesheet. See the section “Using CSS to style HTML” for more information.
Some features of HTML processing can be controlled by stylesheet parameters without having to write a customization. See Chapter 6, HTML output options for more information.
Use the methods described in this chapter if neither of the above can meet your needs.
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.
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 name||When it is called|
|Called before standard navigational header.|
|The standard navigational header.|
|Called after standard navigational header but before any other content.|
|Called after the chunk content but before the standard navigational footer.|
|The standard navigational footer.|
|Called after the standard navigational footer.|
<xsl:template name="user.footer.content"> <HR/><P class="copyright">© 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.
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"/> </P> </xsl:template>
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.
The standard navigational headers and footers in chunked output use words such as
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
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.
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
Prev or their icon equivalents.
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
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
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
your own in templates named
user.footer.navigation. If you don't define any new templates, then
completely suppress headers and footers.
|DocBook XSL: The Complete Guide - 3rd Edition||PDF version available|
Copyright © 2002-2005 Sagehill Enterprises