XML technologies / DocBook / The DocBook XSL stylesheets / Customizing a title page directly / Adding a logo

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

This section shows how to add a logo to an article and transform it to HTML. Proceed as follows:

  1. Customizing your document
    In your article, inside articleinfo or info add an image using mediaobject. For a particular alignment or size, add attributes to imagedata (see Graphics). Replace the logo filename and path if needed:

  • For DocBook 4 documents:

<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd"> 
<article> 
    <articleinfo> 
        <mediaobject> 
            <imageobject role="html"> 
                <imagedata fileref="logo.png"/> 
            </imageobject> 
            <imageobject role="fo"> 
                <imagedata fileref="logo.png"/> 
            </imageobject> 
        </mediaobject> 
    </articleinfo> 
    <!-- Inhalt des Artikels --> 
</article>

  • For DocBook 5 documents:

<article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="de"> 
  <info> 
    <mediaobject> 
      <imageobject role="html"> 
        <imagedata fileref="logo.png"/> 
      </imageobject> 
      <imageobject role="fo"> 
        <imagedata fileref="logo.png"/> 
      </imageobject> 
     </mediaobject> 
  </info> 
  <!-- Inhalt des Artikels --> 
</article>

  1. Where should the logo appear?
    Choose where the logo should appear: before, after or within a title page. In this example, it appears before the title page, so customize the template article.titlepage.before.recto.

  2. Create a customization file
    Create a customization file as shown in Creating a customization file.

  3. Adding templates to the customization file
    Add the following template, choosing the customization file for your DocBook version:

  • For DocBook 4 documents, add:

<xsl:template name="article.titlepage.before.recto"> 
    <xsl:if test="articleinfo/mediaobject"> 
        <div class="logo"> 
            <xsl:apply-templates select="articleinfo/mediaobject"/> 
        </div> 
    </xsl:if> 
</xsl:template>

  • For DocBook 5 documents, add:

<xsl:template name="article.titlepage.before.recto"> 
    <xsl:if test="d:info/d:mediaobject"> 
        <div class="logo"> 
            <xsl:apply-templates select="d:info/d:mediaobject"/> 
        </div> 
    </xsl:if> 
</xsl:template>

  1. Transforming
    Transform the document with the customization file:

xsltproc --output artikel.html XSLT-Stylesheet artikel.xml

These steps also work for XSL-FO. Simply replace the div element from (X)HTML with fo:block from XSL-FO and delete the p element.

If you inserted several images in articleinfo or info all are considered. Whether this is useful depends on your document. If documents always use the same logo, this method is overly flexible. Instead, inside article.titlepage.before.recto include the logo directly. For (X)HTML, add an img element referencing the logo. For XSL-FO, use fo:external-graphic or fo:instream-foreign-object.

  

back to top