Suggestions
Search:

Custom Stylesheet Templates

Introduction

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:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:import href="http://db2latex.sourceforge.net/xsl/docbook.xsl"/>

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

</xsl:stylesheet>

A simple example

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

<?xml version='1.0'?>

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:import href="http://db2latex.sourceforge.net/xsl/docbook.xsl"/>
  <xsl:output method="text" encoding="ISO-8859-1" indent="yes"/>

  <xsl:param name="latex.override">
    <xsl:text>\documentclass[pdftex,english,a4paper,10pt]{article}&#10;</xsl:text>
    <xsl:text>\usepackage[pdftex,bookmarksnumbered,colorlinks,</xsl:text>
    <xsl:text>backref,bookmarks,breaklinks,linktocpage]{hyperref}&#10;</xsl:text>
    <xsl:text>\usepackage[pdftex]{graphicx}&#10;</xsl:text>
    <xsl:text>\usepackage{isolatin1}&#10;</xsl:text>
    <xsl:text>\pdfcompresslevel=9&#10;</xsl:text>
  </xsl:param>
</xsl:stylesheet>
[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="http://www.w3.org/1999/XSL/Transform" 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="latex.math.support">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:choose>
        <xsl:when test="@xreflabel">
          <xsl:value-of select="normalize-space(@xreflabel)"/>
        </xsl:when>
        <xsl:when test="abbrev">
          <xsl:apply-templates select="abbrev" mode="bibliography.mode"/>
        </xsl:when>
        <xsl:when test="@id">
          <xsl:value-of select="normalize-space(@id)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>UNKNOWN</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:param>
    <xsl:text>% -------------- biblioentry </xsl:text>

    <xsl:text>\bibitem</xsl:text>
    <xsl:text>{</xsl:text>
    <xsl:value-of select="$biblioentry.tag"/>
    <xsl:text>}</xsl:text>
    <xsl:apply-templates select="author|authorgroup" mode="bibliography.mode"/>
    <xsl:value-of select="$biblioentry.item.separator"/>
    <xsl:text>\emph{</xsl:text>
    <xsl:apply-templates select="title" mode="bibliography.mode"/>
    <xsl:text>}</xsl:text>
    <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:for-each>
    <xsl:text>. </xsl:text>
    <xsl:call-template name="label.id"/>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>
</xsl:stylesheet>

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

% -------------------------------------------
%
%  Bibliography
%
% -------------------------------------------
\bibliography{''}
\begin{thebibliography}{000}
% -------------- 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}

\end{thebibliography}

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 $latex.biblioentry.style.