Custom Stylesheet Templates


By adding an XSL customization layer on top of DB2LaTeX, you can tweak its behaviour to suit your needs. The steps to do this are the following:

  1. Create an XSL file that imports the main DB2LaTeX stylesheet. This is your "driver file" or "customization layer".

  2. Override XSL parameters and templates in your file.

  3. Process your DocBook source document with your favourite XSL processor.

Other customizations include the use of a ‘mapping’ file or LaTeX styles.

Create an XSL file that imports the main DB2LaTeX stylesheet

Create a text file, e.g. mydb2latex.xsl, like this:

<?xml version='1.0'?>


  <xsl:import href=""/>

  <!-- put your customizations here! -->


A simple example

In this first example, we will override DB2LaTeX default LaTeX preamble to output our own:

<?xml version='1.0'?>


  <xsl:import href=""/>
  <xsl:output method="text" encoding="ISO-8859-1" indent="yes"/>

  <xsl:param name="latex.override">
[Warning] Warning

You should not normally need or want to override the entire DB2LaTeX preamble. Normally, it should be sufficient for you to override other parameters.

This simple example demonstrated the ‘driver file’ syntax, including import and override. An excellent reference is Norman Walsh's DocBook XSL stylesheets documentation.

Setting stylesheet parameters

DB2LaTeX contains many parameters that simply indicate ‘yes’ or ‘no’. The unique value ‘1’ is indicative of ‘yes’. All other values (such as ‘0’ or empty) mean ‘no’.

[Note] Note

This is different from Norman Walsh's DocBook XSL stylesheets. The difference exists because “1” seems more resilient against typos and XSL style variations (e.g. resilient against whether the parameter value is a string or number or result tree fragment). Also, the empty string will mean “no”.

An example of this sort of ‘toggle’ parameter is as follows:

<xsl:param name="latex.use.hyperref">1</xsl:param>

You could use any of the following examples to override it:

<xsl:param name="latex.use.hyperref">0</xsl:param>
<xsl:param name="latex.use.hyperref"></xsl:param>
<xsl:param name="latex.use.hyperref"/>
<xsl:param name="latex.use.hyperref" select="0"/>
<xsl:param name="latex.use.hyperref" select="'0'"/>

The parameters for DB2LaTeX are show in the Reference section. Parameters are divided into three categories:

A more complex example

You may as well override any DB2LaTeX XSL template (although a better understanding of the inner works of DB2LaTeX and the XSLT language may be recommended). For example, you may not like the default Bibliography processing. You may require that your BiblioEntries should be numbered using decimal notation, and the authors should appear before the title[1]. This can be achieved by overriding the relevant template. Templates for DocBook elements are listed in Chapter2 of the Reference.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
  <xsl:import href="path/to/db2latex/xsl/docbook.xsl"/>
  <xsl:output method="text" encoding="ISO-8859-1" indent="yes"/>
  <xsl:param name="">1</xsl:param>
  <xsl:param name="latex.use.babel">0</xsl:param>
  <xsl:param name="latex.use.isolatin1">1</xsl:param>
  <xsl:param name="latex.use.hyperref">0</xsl:param>
  <xsl:param name="latex.use.fancyvrb">0</xsl:param>
  <xsl:param name="latex.use.fancyhdr">0</xsl:param>
  <xsl:param name="latex.use.subfigure">0</xsl:param>
  <xsl:param name="latex.use.times">0</xsl:param>
  <xsl:param name="latex.bibwidelabel">000</xsl:param>

  <xsl:template name="biblioentry.output">
    <xsl:param name="biblioentry.tag">
        <xsl:when test="@xreflabel">
          <xsl:value-of select="normalize-space(@xreflabel)"/>
        <xsl:when test="abbrev">
          <xsl:apply-templates select="abbrev" mode="bibliography.mode"/>
        <xsl:when test="@id">
          <xsl:value-of select="normalize-space(@id)"/>
    <xsl:text>% -------------- biblioentry </xsl:text>

    <xsl:value-of select="$biblioentry.tag"/>
    <xsl:apply-templates select="author|authorgroup" mode="bibliography.mode"/>
    <xsl:value-of select="$biblioentry.item.separator"/>
    <xsl:apply-templates select="title" mode="bibliography.mode"/>
    <xsl:for-each select="child::copyright|child::publisher|child::pubdate|child::pagenums|child::isbn">
      <xsl:value-of select="$biblioentry.item.separator"/>
      <xsl:apply-templates select="." mode="bibliography.mode"/>
    <xsl:text>. </xsl:text>
    <xsl:call-template name=""/>

In this case, you just need to override the named template biblioentry.output. The final output might look like this:

% -------------------------------------------
%  Bibliography
% -------------------------------------------
% -------------- biblioentry
\bibitem{AhoSethiUllman96}Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman, \emph{Compilers, Principles, Techniques, and Tools}, Addison-Wesley Publishing Company, Copyright \copyright{} 1996 Bell Telephone Laboratories, Inc., 0-201-10088-6. \label{id2773943}
% -------------- biblioentry
\bibitem{Kites75}Andrea Bahadur and Mark Shwarek, \emph{Kites}, Copyright \copyright{} 1974, 1975 Product Development International Holding N. V., 0-88459-021-6, Plenary Publications International, Inc., 988-999. \label{id2713446}
% -------------- biblioentry
\bibitem{Abbrev}AuthorFirstname AuthorSurname, \emph{A Really Full BiblioEntry}, Copyright \copyright{} 1998 Copyright holder, ISBN, PageNums, PubDate, PubPublisherNameAny StreetAnywhere, XX99999USA. \label{id2713011}
% -------------- biblioentry
\bibitem{Citation}, \emph{A Really Full BiblioEntry}. \label{id2712994}
% -------------- biblioentry
\bibitem{Walsh97}, \emph{}. \label{walsh97}


More Examples

The DB2LaTeX samples have been created with many examples of customisation. You may also wish to review our other customisation guides:

[1] See also $