Docbook Customisation

1. Customisation documentation
2. Documentation on customsing docbook
3. How it works
4. Customisation documentation
5. Is there a line seperation parameter?
6. What are the parameters that I can change?
7. How do I alter the text that is generated for cross references?
8. How do I change the way chapter titles are presented?
9. How do I change or turn off numbering of Table, Figure, or Example titles?
10. How do I control the depth of sections listed in my tables of contents?
11. Controlling section numbering.
12. Customizing title pages[1].
13. How do I customize the format of my title pages?
14. Controlling headers and footers in print. (within the limits of fop? )
15. Customization for both chunk and nonchunk output.
16. Profiling to handle conditional text.
17. Generating an index.
18. Tables of content, or toc's.
19. Controlling numbering.
20. Customising mrking up for functions.
21. Working with DTD's, some reading
22. Glossee as links
23. Adding a date footer
24. Setting default font for PDF output.
25. Changing column width for glossary
26. Customising titles
27. Table of contents generation
28. Making a glossterm bold in print output
29. Numering qanda sets
30. Processing instructions (PHP)
31. Customising the para template (or import precedence lesson)
32. Changing the callout markup in html output
33. program listing, line numbers
34. customising para element
35. Label seperation in HTML
36. Cals Table customisation
37. Customising with language specific text
38. Customising title chapters
39. Image scaling
40. Adding the date and time.
41. Customising authorgroup
42. Custom footer for print output
43. Draft mode
44. Docbook customisation for jsp [no html, head, body tags]
45. Customising figure captions
46. Shade the background of the note element in XSL-FO
47. Change from one to two columns on each chapter
48. Font size change for programlisting
49. Remove preface numbering
50. Customizing index layout
51. Move figure title to below image
52. Convert footnotes to endnotes
1.

Customisation documentation

Jirka Kosek



>   would it be possible to re-structure the param.xsl file?
> or is it in alphabetical order because it's automatically generated?

docbook at Sourceforge is not enough for you? Parameters here are grouped together by their nature.

2.

Documentation on customsing docbook

Mike Smith


> I'm thinking of using DocBook for our XML print documentation needs. 
> However, we already have DTDs that are internal and use unique 
> elements. I would like to use the content that has been structured by 
> these DTDs and have them available for re-use in DocBook. This would 
> mean validating new and unique elements in DocBook.
> > The best solution is to use catalog files within your XML/SGML system.
> One way how to add them to Saxon is described in
> http://www.kosek.cz/xml/saxon/. Other way is to use XML resolver classes
> from Norm, I didn't URL in my hand, try Google or search archives.

  I have put some explanations on-line too and a specific page for
xsltproc users. This is becoming a real FAQ as we are deploying
catalogs on Linux/Unix to handle the DocBook docs of the Gnome project
    http://xmlsoft.org/catalog.html
    http://xmlsoft.org/XSLT/docbook.html

Daniel

-- 
Daniel Veillard 
> Can this be done? Does it cause problems? I suppose the short 
> question really is - how easy is DocBook to manipulate to suit your 
> own ends?

The way you'd want to add your elements is through a "customization layer" to DocBook, not by making any direct changes to the DocBook DTD itself. For instructions on creating DocBook customization layers, you'll need to read chapter 5, "Customizing DocBook", of "DocBook: The Definitive Guide":

I think you'll be happy to find out that DocBook is designed to be customized. The DTD contains many parameter-entity hooks that are to there to make it easier for DTD implementors like you to make changes.

But before you do any customizing, I also recommend that you read at least Part III, "Development" of Eve Maler and Jeanne El Andaloussi's book "Developing SGML DTDs: From Text to Model to Markup", especially chapter 10, "Techniques for Reuse and Modification":

And so that you can post questions and get answers if you run into problems, you'll probably also want to subscribe to the docbook@lists.oasis-open.org mailing list:

Also, there a few free tools for looking at DTDs that I think will help you a lot when working with the DocBook DTD and assessing/ debugging your customizations:

Bob Stayton's LiveDTD creates hyperlinked HTML versions of DTDs http://www.sagehill.net/livedtd/index.html

Norm Walsh's DTDParse generates human-readable DTD documentation (hyperlinked HTML) http://dtdparse.sourceforge.net

Earl Hood's perlSGML generates human-readable DTD documentation (hyperlinked HTML) also contains dtddiff for generating diffs of two DTDs and dtdview for interactively navigating a DTD http://www.oac.uci.edu/indiv/ehood/perlSGML.html

Ian Graham's modified version of perlSGML includes dtd2html-table, which generates more readable DTD documentation than Earl Hood's original dtd2html http://www.java.utoronto.ca/DTDs/perlSGML.1996Aug20-Ian.tar.gz

One thing you need to remember is that if you add elements in a customization layer DTD and want to use the standard DocBook stylesheets to process documents authored with that DTD, you'll also need to create a stylesheet customization layer.

And maybe the very first thing you should do is make an assessment of whether any of the elements you want to add are just different names for elements that already exist in DocBook. (DocBook has more than 350 elements, so there's a pretty good chance that some of your elements have direct equivalents in DocBook). It's probably best to spend some time getting really familiar with DocBook before you decide to make any changes.

3.

How it works

DaveP

From the top then. Assuming you have an installed set of docbook XSL stylesheets, which works.

From the command line, rather than calling up the main docbook stylesheets provided by Norm and friends, call up an intermediate xsl file, which in turn calls up the main stylesheet, docbook/xsl/html/docbook.html. This intermediate file is called a driver file. In order to understand how it works, you need to understand that by importing the docbook.xsl file, any templates that you add will take precedence over Norms templates. This way, you can override the main stylesheet templates, and hence your changes will affect the overall styling of your document.

Another option is to control how the main stylesheets do their job by setting some of the parameters available to you. This can be done two ways, firstly via the command line, as a parameter, or, for more permanent changes, you can define these parameters in your driver file. Again your definitions of the parameters value takes precedence over the main stylesheet default values.

A third reason for not changing the actual main stylesheets is that the group of enthusiasts who maintain them change them quite frequently, so using this driver file rather than modifying the actual stylesheets allows you to update the main stylesheets from Sourceforge and retain your own set of preferences. I became quite cross with Norm. I would 'tweak' the stylesheets, he would update them to add features I decided I wanted, and I had to start all over again. That was my motive for finding out how the customisation worked, I'm just lazy!

A simple example driver file is shown below, which simply changes two parameters, and then imports the main stylesheet.


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                version="1.0">
 
<xsl:import href="/sgml/nw/docbook/xsl144/html/chunk.xsl"/> 

<!-- CSS Stylesheet -->
<xsl:param name="html.stylesheet" select="'xslfo.css'" />

<xsl:template match="revhistory"/>
</xsl:stylesheet>

The import statement must come first. The next line identifies that I have a CSS stylesheet that I want to use, and names it. The last line overrides the standard processing of revision history. That's all I wanted to do. So my command line when I style a docbook stylesheet calls up this file instead of the main docbook stylesheet.

Simple really, isn't it!

4.

Customisation documentation

Jirka Kosek



> Is there any documentation on the
> switches that can be used for customization? 

See sourceforge

5.

Is there a line seperation parameter?

Norm Walsh

| I could not find the parameter for setting the line separation
| in normal text. Can anyone instruct me on that topic. 
| BTW, normal.para.spacing does not seem to do the job.

I added a line-height parameter today.

6.

What are the parameters that I can change?

DaveP

There are a few... OK there are lots. These derive from the fact that people want lots of different things from the styling that docbook provides via the main stylesheets. The files in which they are found start at param.xweb (I'm referring to version 1.46 of the xslt stylesheets, for html). From that file, others are pulled in using entities, defined in param.ent (also in the same directory). These entities refer to a whole list of files in the params directory, where the detail is to be found. To make it easy, I've included an html version of the file (all entities included) which should be a little easier to follow. Since there is no need to modify any of these files, they are there primarily to let you know which parameters are available for modification. The readable version of this file is here as param.xweb.html. Take a quick look at it, and you will see the range of parameters that are available for personalising your presentation. This file is for the HTML output, a similar one is presented for the xsl-fo stylesheets. That would work in exactly the same way. If you are interested, the parameter changed above looks like this


<xsl:param name="html.stylesheet" select="''" doc:type='string'/>

<doc:param name="html.stylesheet" xmlns="">
<refpurpose>Name of the stylesheet to use in the generated HTML</refpurpose>
<refdescription>
<para>The name of the stylesheet to place in the HTML <sgmltag>LINK</sgmltag>
tag, or the empty string to suppress the stylesheet <sgmltag>LINK</sgmltag>.
</para>
</refdescription>
</doc:param>

The parameter is defined first, with a name of html.stylesheet, and a default value of an empty string. My driver file overrides this, using xslfo.css as the filename. The purpose and description of the parameter is also provided. The doc namespace is used for self documentation. This particular parameter is described here.

The parameters range from specifying how a titlepage should be styled, through to whether to use unicode characters or small graphics for callouts. This will be described seperately, at the moment just realise its quite an extensive list.

So, how to describe the parameters. Let's start with some gross generalisations.

  1. Admonitions (graphics to be used, and how to style them)

  2. Callouts (graphics, numbering)

  3. EBNF (Colours and borders)

  4. Table of contents (tables and indexes). Where and when to generate them and how to present them.

  5. Extensions. Whether to use them, which ones to use.

  6. Automatic labelling. Which containers do you want numbering?

  7. HTML related. Stylesheets (CSS), what to use as filenames, chunking, how to name chunked files.

  8. Functions and refentry styling

  9. Tables

  10. Question and Answer styling

  11. Link styling

  12. Bibliography styling

  13. Chunking (what extension to use, what to chunk, encodings etc)

  14. Various miscellaneous items.

Even with this skimpy outline, its clear to see that there is a fair scope for customisation. Read for yourselves in the linked toc at param.xweb.html.

The rest of this file answers specific questions that have come up on the list. I hope you have enough to give you an idea of where to start.

7.

How do I alter the text that is generated for cross references?

Bob Stayton

For example, when you use xref to refer to a figure, the generated text says “Figure 3”, but perhaps you would rather it say “Fig 3: My figure title”. The generated text is controlled by text templates defined in common/en.xml or other language file in that directory. But rather than modify those files, you can change individual text templates in your stylesheet driver file. Here is how it is done for this example:

<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:context name="xref">
      <l:template name="figure" text="Fig %n: %t"/>
    </l:context>
  </l:l10n>
</l:i18n>                                                                       

    You may need to provide similar changes for other contexts, 
such as "title-numbered",and others defined in the common/en.xml file. 
For example:

  <l:i18n xmlns:l=http://docbook.sourceforge.net/xmlns/l10n/1.0">
    <l:l10n language="en">
    <l:context name="title">
        <l:template name="chapter" text="%n. %t"/>
      </l:context>
      <l:context name="title-numbered">
        <l:template name="chapter" text="%n. %t"/>
      </l:context>
    </l:l10n>
  </l:i18n>





In the text templates, %n inserts the number and %t inserts the title. The l:context element indicates this is for generated xref text, and the l:template's name attribute identifies which target element it is applied to.

The special trick here is the select="document('') attribute. This special syntax reads the current document (the stylesheet file) into the local.l10n.xml parameter. When the stylesheet goes to generate text, the stylesheet first scans that parameter for a match before going to the standard language files.

8.

How do I change the way chapter titles are presented?

By default, chapter titles are presented as “Chapter 3. My Chapter Title”, but perhaps you would rather print just the title. The generated text is controlled by text templates defined in common/en.xml or other language file in that directory. But rather than modify those files, you can change individual text templates in your stylesheet driver file. Here is how it is done for this example:

<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:context name="title">
      <l:template name="chapter" text="%t"/>
    </l:context>
  </l:l10n>
</l:i18n>                                                                       

The original text template was Chapter %n. %t. In the text templates, %n inserts the number and %t inserts the title. Replacing the original template with just %t generates just the title of the chapter.

9.

How do I change or turn off numbering of Table, Figure, or Example titles?

By default, table titles and such are presented as “Table 3. My Table Title”. Changing this format involves changing a text template similar to that for chapter titles. See the answer for changing chapter titles.

10.

How do I control the depth of sections listed in my tables of contents?

Bob Stayton

There are two section table of contents parameters. The generate.section.toc.level parameter controls which section levels will have a toc list generated at the top of the section. In other words, "the section levels in which to generate a section toc listing". If it is set to "2", then you'll see a Table of Contents listing at the top of each sect1 and sect2 (and equivalent nested section elements). The default is set to "10", so essentially all sections will have their own TOC by default.

The toc.section.depth parameter, on the other hand, controls the depth of nested sections that are included in a given toc, counting from the top. For example, if it is set to "2", then the chapter-level TOC will list its sect1 and sect2 titles, and the sect1-level TOC will list its sect2 titles. If generate.section.toc.level is greater than toc.section.depth, then tocs of further depth show only one level, their own children sections. That is to prevent showing an empty toc.

11.

Controlling section numbering.

DaveP

See param.xweb.html and the following items. Control is available over the following containers.

  1. chapter, defaults to yes

  2. appendix

  3. part, defaults to yes

  4. preface, defaults to no

  5. qandadiv, defaults to yes

  6. section, defaults to no

Apart from these aspects, there are two other parameters which are usable. Firstly, label.from.part, should chapters be re-numbered seperately within each part? Defaults to no. and section.label.includes.component.label. Should section labels be included in the component label? Defaults to no.

To set any one of them on, set the parameter to 1. To turn numbering off, set it to 0.

12.

Customizing title pages[1].

DaveP.

Messy this one. It would appear that this is one of the favourite areas for customisation, so the actual contents of a styled document without any customisation is minimal. This operates in a slightly different way to other parameters. Rather than setting a parameter in the driver file, a seperate step is needed prior to styling your document. In the xsl distribution, you will find a directory called template. In there is a file called testtemplate.xml, and a matching stylesheet called titlepage.xsl. Running this stylesheet against testtemplate.xml produces another stylesheet, which is actually used on your document to produce the titlepage.

Having modified the testtemplate.xml, run the stylesheet to create, say mytitlepage.xsl, this resultant file is included into the driver file with a line like


 <xsl:include href="/sgml/xsl/book/mytitlepage.xsl"/> 

Then the main stylesheet includes this styling, which styles your document to produce the titlepage that you want. Let me re-cap.

Modify testtemplate.xml to suite your needs for a titlepage, save this file as, say mytitlepage.xml
Apply titlepage.xsl to mytitlepage.xml, to produce mytitlepage.xsl
Add a line in your driver file to include mytitlepage.xsl
Run your driver file against your document to style it, with the styling of mytitlepage.xsl

Right. Lets look a little more closely at what controls it all, the file testtemplate.xml


<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
             base-stylesheet="../html/docbook.xsl">

<t:variable name="section.autonumber" select="true()"/>
<t:variable name="html.stylesheet">docbook.css</t:variable>

Leave these unless you wish to modify the stylesheet used.


<t:titlepage element="article" side="recto">

The t:titlepage element has three attributes:

element The name of the source document element for which these templates apply. In other words, to make a title page for the article element, set the element attribute to article. This attribute is required.

wrapper The entire title page can be wrapped with an element. This attribute identifies that element. Not used in the example above, could be fo:block for xsl-fo, or a simple div for an html output.

class If the class attribute is set, a class attribute with this value will be added to the wrapper element that surrounds the entire title page. This would be useful if additional html styling is done by a CSS stylesheet.


  <title predicate="[1]"/>
  <subtitle predicate="[1]"/>
  <corpauthor/>
  <author/>
  <authorgroup>
    <t:or>
      <corpauthor/>
      <author/>
      <editor/>
    </t:or>
  </authorgroup>
  <editor/>
  <releaseinfo/>
  <copyright/>
  <pubdate/>
  <revision/>
  <revhistory/>
  <abstract/>
</t:titlepage>

This apparent random collection of tags specifies the content of the recto side of the print page (OK not in html, but you get the idea). What it is saying is that for this article, include these elements in the titlepage. The indentation implies second level terms to be included, etc. So, simply list the elements that are in your document that you want included and a stylesheet will be generated which includes this.

A little detail here. Each element may have a single attribute: predicate. The value of this attribute is used as a predicate for the expression that matches the element on which it occurs. In other words, to put only the first three authors on the recto-side of a title page, you could specify:

  <t:titlepage-contents side="recto">
    <!-- other titlepage elements -->
    <author predicate="[count(previous-sibling::author)<2]"/>
    <!-- other titlepage elements -->
  </t:titlepage-contents>

This would be specified using

 author predicate="[3]" 

in the template file.


<t:biblioentry>
  <abbrev/>
  <title/>
  <t:or>
    <authorgroup/>
    <author/>
  </t:or>
  <biblioset/>
</t:biblioentry>  

</t:templates>

The remainder of this example provides other candidates. Note that the content must follow the docbook DTD (otherwise it wouldn't be much good would it). Other than that, try adding the elements you want, from your frontmatter. Good luck.

13.

How do I customize the format of my title pages?

If you want to change which elements appears on your title page, see the question on changing the content of title pages. . This answer describes how to format the elements that are included.

By default, an element on a title page is styled using the templates defined in titlepage.xsl. Those templates use the generic titlepage.mode. For example, the default template for the pubdate element looks like this:

<xsl:template match="pubdate" mode="titlepage.mode">
  <p class="{name(.)}">
    <xsl:apply-templates mode="titlepage.mode"/>
  </p>
</xsl:template>

You can customize how an element is processed by defining a template for it using a more specific mode, such as book.titlepage.recto.mode. This particular mode is called when processing in the context of a book titlepage, for the front (recto) side of the title page. This is the one used for HTML since it doesn't have page sides.

For example, if you want to add boldface to a book's pubdate, you create a new template in your customization layer like this:

<xsl:template match="pubdate" mode="book.titlepage.recto.mode">
   <p class="{name(.)}">
     <B>
       <xsl:apply-templates mode="titlepage.mode"/>
     </B>
   </p>
</xsl:template>

You should pass along the titlepage.mode in the <xsl:apply-templates> tag because modes do not automatically pass down to children. If you want to customize child elements, then pass along the more specific book.titlepage.recto.mode instead so your custom templates are used. Any children that don't have that mode defined will fall back to the default titlepage.mode, so nothing will get lost.

If you are customizing for print output, then the recto part is significant. It refers to the front side of the title page, while verso refers to the back side of the page.

14.

Controlling headers and footers in print. (within the limits of fop? )



15.

Customization for both chunk and nonchunk output.

DaveP

Docbook XSL stylesheets provide two primary files. If you have a look in your distribution, in the html directory, you will find a number of files which appear to relate to chunking.

Just in case, a very quick aside. Chunking is the word which has become fairly common parlance for producing multiple output files from one stylesheet. For instance, in a large book, each chapter may be needed as a seperate file, to allow a reasonable download time. Norm describes possible chunks as:

appendix
article
bibliography in article or book
book
chapter
colophon
glossary in article or book
index in article or book
part
preface
refentry
reference
sect1 if position()>1
section if position()>1 && parent != section
set
setindex

So you have quite a choice as to where you want your chunks. As usual, you'll find the parameters to set to achieve this in the params section.

Note that this information is slightly premature, since it is based on 1.46 stylesheets which as of today are still experimental. (November 2001)

In alphabetical order, these are:

calc-chunks.xsl - Calculates chunks, includes chunker.xsl
chunk.xsl - the main entry stylesheet for all processors
chunker.xsl - Creates the filenames used for output
chunk-experimental - like all names with experimental in it, leave it alone, it will change
expchunk.xsl- simply includes the experimental file and chunker.xsl
oldchunker.xsl - xslt processor dependent file writes.
onechunk.xsl - includes chunk-common and chunker.xsl

Confused? I can see why. I'm writing this with the 1.46 version in front of me. If you take a look at (or are using) 1.45, same directory, you'll find one addition, xtchunk.xsl. As of 1.46, Docbook support for xt has been removed, to allow use of all the features that are missing from XT.

So, if you want to chunk your output into multiple files, there are a couple of steps needed:

  1. Let the stylesheets know that you want chunking to occur by setting the parameter 'using.chunker' to 1.

  2. Set the element at which you want to chunk, say sections. Use chunk.sections.

  3. You may also want to name the primary output file. Use root.filename, say set to index.html.

  4. Finally, lets choose to use the id value of the section as the filename, presuming its slightly more sensible than an auto generated one! Set use.id.as.filename to 1.

Create your driver file with these parameters set as above, and run that driver against your docbook file. Hey presto, you have your multiple output files.

16.

Profiling to handle conditional text.


[Substeps in a procedure could be numbered 1.1, 1.2, or a, b, or
i, ii, etc. Profiling is a term Jirka first used to describe the
process of selecting conditional text from a document
that used role or other attributes.  I think he already
has some doc that we could point to.]

17.

Generating an index.



18.

Tables of content, or toc's.

DaveP

Docbook stylesheets can produce table of contents, lists of tables, and many more types of tables of content (toc's), and can produce them in great profusion. Some like 'em everywhere, some don't. You choose. As an approach I'd suggest you write a basic driver file, have a look at the output, and see if it suits your tastes. When yu see too many toc's, start to remove them!

There is a whole list of elements for which toc's can be generated. Look in param.xweb.html, and search for generate.X.toc, where X is the element you want a toc in. Set that parameter to 0 to stop a toc being generated, or 1 to to enable its creation.

To create toc's (or not) in some, but not all, sections, use generate.section.toc.level. If set to 2, then for sections up to and including depth of 2, a toc will be created. For deeper nested sections, no toc will be created. For recursive sections, a seperate parameter is used, toc.section.depth. This defaults to 2, and can be set to whatever matches your needs.

Finally, there are a whole host of ancilliary attributes which can be set for toc's. Examples of these are toc.list.type which determines what type of list is used (in html) for the toc. The default is a display list (DL). Another is the separator used between labels and titles in a toc. Use autotoc.label.separator.

Finally, a silly one (it must be, since I was caught out by it :-). Its fine setting the toc related parameters, its equally nice to be able to say where in your document you want them. Use the toc element in your document (empty element), where you want the toc to appear.

19.

Controlling numbering.

DaveP

Otherwise known as Automatic labelling. All the related parameters are prefixed autolabel.X

The following variations are catered for.

  1. chapter.autolabel - enumerated chapters? Default yes (1)

  2. appendix.autolabel- enumerated appendices? Default yes (1)

  3. part.autolabel - enumerated parts? Default yes (1)

  4. preface.autolabel - enumerated preface? Default no (0)

  5. qandadiv.autolabel - enumerated QAndASets? Default yes (1)

  6. section.autolabel - enumerated sections? Default no (0)

  7. label.from.part - Renumber chapters in each part? Default no (0)

If label.from.part is non-zero, components (chapters, appendixes, etc.) will be numbered from 1 in each part. Otherwise, they will be numbered monotonically throughout each book.

So each of these can be turned on and off by setting any one of these parameters in your driver file.

A slightly different one, qanda.inherit.numeration - Does enumeration of QandASet components inherit the numeration of parent elements? If true (non-zero), numbered QandADiv elements and Questions and Answers inherit the numeration of the ancestors of the QandASet. So if you have a QandASet inside a chapter numbered 3, then the numbering of qanda entries will take up that numbering, commencing from 3.something, dependent on where they are relative to the chapter structure.

20.

Customising mrking up for functions.

Norm Walsh





| In PHP semantic I have declaration:
| string MyFunction(string param1, string param2[, int number]);

| and I don't know how to type it in DocBook =(
| When I use what I see in examples like:

| <!DOCTYPE funcsynopsis PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
|    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
| <funcsynopsis>
|  <funcprototype>
|    <funcdef>string <function>MyFunction</function>
|    <paramdef>string <parameter>param1</parameter></paramdef>
|    <paramdef>string <parameter>param2</parameter></paramdef>
|    <paramdef>int <parameter>number</parameter></paramdef>
|    </funcdef>
|  </funcprototype>
| </funcsynopsis>

| I receive:
| string MyFunction (param1, param2, number);
| string param1;
| string param2;
| int number

There's a switch in the stylesheets to select between K&amp;R style and ANSI style function synopses. If you turn that switch to 'ansi', I think you'll get something closer to what you want.

21.

Working with DTD's, some reading

Mike Smith



> I'm thinking of using DocBook for our XML print documentation needs. 
> However, we already have DTDs that are internal and use unique 
> elements. I would like to use the content that has been structured by 
> these DTDs and have them available for re-use in DocBook. This would 
> mean validating new and unique elements in DocBook.

> Can this be done? Does it cause problems? I suppose the short 
> question really is - how easy is DocBook to manipulate to suit your 
> own ends?

The way you'd want to add your elements is through a "customization layer" to DocBook, not by making any direct changes to the DocBook DTD itself. For instructions on creating DocBook customization layers, you'll need to read chapter 5, , of "DocBook: The Definitive Guide": "Customizing DocBook"

I think you'll be happy to find out that DocBook is designed to be customized. The DTD contains many parameter-entity hooks that are to there to make it easier for DTD implementors like you to make changes.

But before you do any customizing, I also recommend that you read at least Part III, "Development" of Eve Maler and Jeanne El Andaloussi's book "Developing SGML DTDs: From Text to Model to Markup", especially chapter 10, "Techniques for Reuse and Modification":

And so that you can post questions and get answers if you run into problems, you'll probably also want to subscribe to the docbook@lists.oasis-open.org mailing list:

Also, there a few free tools for looking at DTDs that I think will help you a lot when working with the DocBook DTD and assessing/ debugging your customizations:

  Bob Stayton's LiveDTD
  creates hyperlinked HTML versions of DTDs
  http://www.sagehill.net/livedtd/index.html

  Norm Walsh's DTDParse 
  generates human-readable DTD documentation (hyperlinked HTML)
  http://dtdparse.sourceforge.net

  Earl Hood's perlSGML
  generates human-readable DTD documentation (hyperlinked HTML)
  also contains dtddiff for generating diffs of two DTDs
  and dtdview for interactively navigating a DTD
  http://www.oac.uci.edu/indiv/ehood/perlSGML.html
  
  Ian Graham's modified version of perlSGML
  includes dtd2html-table, which generates more readable DTD
  documentation than Earl Hood's original dtd2html
  http://www.java.utoronto.ca/DTDs/perlSGML.1996Aug20-Ian.tar.gz

One thing you need to remember is that if you add elements in a customization layer DTD and want to use the standard DocBook stylesheets to process documents authored with that DTD, you'll also need to create a stylesheet customization layer.

And maybe the very first thing you should do is make an assessment of whether any of the elements you want to add are just different names for elements that already exist in DocBook. (DocBook has more than 350 elements, so there's a pretty good chance that some of your elements have direct equivalents in DocBook). It's probably best to spend some time getting really familiar with DocBook before you decide to make any changes.

22.

Glossee as links

Jirka Kosek





Using a glossary, I want to link to see and seealso terms.
<glossentry id="infinite.loop">
<glossterm>Infinite Loop</glossterm>
<glosssee>Loop, Infinite</glosssee>
</glossentry>

it's a shame that there's no way to make the see and 
seealso terms proper links. 

There are two ways how to do it, which can be sufficent enough I think.

1. You can add otherterm attribute to glosssee with ID of referenced term. This will create link for you.

<glosssee 
otherterm="loop-infinite">Loop, Infinite</glosssee>

2. If you don't want deal with IDs for terms, you can surround term name inside of glosssee with glossterm:

<glosssee><glossterm>Loop, 
Infinite</glossterm></glosssee>

If you call stylesheet with param glossterm.auto.link=1, links will be created from each <glossterm/> to place of its definition.

23.

Adding a date footer

Bob Stayton



> How can I put into every chunk (into footer) date, 
> which I have already defined in <bookinfo> of document? 

For the specifics on customizing the footer, see: styling If you follow that FAQ, you'll create a template named 'user.footer.content', which would look something like this:

<xsl:template name="user.footer.content">
  <div class="footer.date">
    <xsl:value-of select="//bookinfo/date" />
  </div>
</xsl:template>
24.

Setting default font for PDF output.

Norm Walsh



| I'm working on installing a new font for Fop and need to know how/if it's
| possible to setup a new font as the FO stylesheet default.

Set the body.font.family parameter.

25.

Changing column width for glossary

Bob Stayton




> how can I change
> the column widths for the glossary?

There is a glossary stylesheet global variable 'glossterm-width' that should probably be promoted to a parameter and added to the params list with documentation. Setting this in your stylesheet customization file will do the trick:

<xsl:variable name="glossterm-width">1in</xsl:variable>

26.

Customising titles

Bob Stayton


> I'm working in XML, with the 1.50.0 XSL.

> I've been trying to satisfy a customer who wants the word Appendix to
> appear in each appendix title as well as in the TOC of an article. I
> managed to get the appendix title the way they wanted by moving the
>       <xsl:template match="appendix" mode="object.title.template">
>       ...
>       </xsl:template>

> from common/gentext.xsl into my driver file. Anybody have a cleaner way to
> do this?

Yes, the title in the appendix itself can be altered with a text template customization because appendixes use the 'title-numbered' context in the templates. Put something like this in your customization file:

<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:context name="title-numbered">
      <l:template name="appendix" text="Appendix %n: %t"/>
    </l:context>
  </l:l10n>
</l:i18n>

This change only applies to the English version, of course. More entries for other languages.

> I haven't been able to figure out how to change the TOC, though. Anyone
> know how to do this?

This is harder. There is little opportunity to customize individual lines in the TOC. The toc lists are generated using the 'subtoc' template in autotoc.xsl. It is used recursively, to get nesting, but it doesn't vary per element type. These lines in subtoc show the problem:

  <xsl:element name="{$toc.listitem.type}">
    <xsl:variable name="label">
      <xsl:apply-templates select="." mode="label.markup"/>
    </xsl:variable>
    <xsl:copy-of select="$label"/>

The first line starts the <dt> element (in html output) and the rest output the appendix number (called a label in the stylesheets). If you want the word Appendix, then it has to be inserted between them. Something like this:

  <xsl:element name="{$toc.listitem.type}">
  <xsl:if test="local-name(.) = 'appendix'">
     <xsl:text>Appendix </xsl:text>
  </xsl:if>
    <xsl:variable name="label">
      <xsl:apply-templates select="." mode="label.markup"/>
    </xsl:variable>
    <xsl:copy-of select="$label"/>

Unfortunately, to get this in there you have to copy the entire subtoc template to your customization file.

If you plan to localize, you should replace the xsl:text element with a call to a gentext template to get the word "Appendix" in the correct language.

27.

Table of contents generation

Jirka Kosek


> 1) Right after each chapter heading in the javahelp html, I get the text 
> "Table of Contents". I realize that in a regular docbook html, that a table 
> of contents goes after the chapter heading, however this seems pretty 
> meaningless in javahelp. Am I doing something wrong and how do I get rid of 
> it?

You can control ToC creation by parameter generate.toc. To get rid off all ToCs, you can use something like:

<xsl:param name="generate.toc">
appendix  nop
article   nop
book      nop
chapter   nop
...
</xsl:param>

in your customization layer.

28.

Making a glossterm bold in print output

David Carlisle

> I'm using DocBook/XML with the stylesheets provided with the 
> Selfdocbook
> XML Edition. I highlighted some terms as <glossterm>, but they do not
> render the way I want them to. In the HTML they render as 
> italics, while
> in the PDF they are in a regulat text. I'd like them to be bold.

In file fo/inline.xsl find the template

<xsl:template match="glossterm" name="glossterm">. 

Copy this template into your customization layer and change


<xsl:call-template name="inline.charseq"/> 

to

<xsl:call-template name="inline.boldseq"/>.
29.

Numering qanda sets

Bob Stayton



> I would like my Q&A entries to be numbered:

> Q1

> A

> Q2

> A

> and for this numbering to continue across chapters. I would like to do
> this with both dsssl and xml docbook. Any suggestions welcome.

I assume when you say "xml docbook" you mean the XSL stylesheets?

For XSL, if you are willing to forego all the options for controlling the QandA labels and just want to hardwire your style, then add these templates to your XSL customization layer:

<xsl:template match="question" mode="label.markup">
    <xsl:text>Q</xsl:text>
    <xsl:number level="any" count="qandaentry" format="1"/>
</xsl:template>

<xsl:template match="answer" mode="label.markup">
    <xsl:text>A</xsl:text>
</xsl:template>

The <xsl:number> with level="any" counts all instances of qandaentry elements in your document, and doesn't reset.

But if you localize your doc (so 'Q' and 'A' might not be appropriate), or want the option to change labeling for a given qandaset, then you should copy the whole template from common/labels.xsl:

<xsl:template match="question|answer" mode="label.markup">

to your customization layer and make similar changes.

30.

Processing instructions (PHP)

Jeff Beal


Is there a way to get processing instructions passed through from
the xml source into html (using xsl)?

example:

...can be found in <ulink url="../tutorials/WHG/wsh.pdf">
   Syntax Highlighting in WinEdt</ulink>
   [pdf; <?php show_size("..tutorials/WHG/wsh.pdf"); ?>  KB]
...

Yes, add this template to your driver

<xsl:template match="processing-instruction('php')">
 <xsl:processing-instruction name="php">
  <xsl:value-of select="."/>
 </xsl:processing-instruction>
</xsl:template>
31.

Customising the para template (or import precedence lesson)

Bob Stayton


> I seem to have stumbled upon an odd bug.  I wanted to override the
> default <para> match rule, but in certain contexts, I get invalid HTML
> (extra '</p>' end tags).  I then pared it down to the simplest test
> case, and it turns out that even copying the *identical* para match
> rule from "block.xsl" into a customization layer causes the problem.
> Somehow the "unwrap.p" named-template gets defeated, causing invalid
> HTML.


> Here is the customization layer, "test.xsl" (note this simply a
> cut-n-paste of the template from block.xsl):

> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
>                 version='1.0'>
>  
>   <xsl:import
>   href="http://docbook.sourceforge.net/release/xsl/1.52.2/html/docbook.xsl"/>

>  <xsl:output method="html" encoding="ISO-8859-1"
>   doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
>   doctype-system="http://www.w3.org/TR/html4/loose.dtd" indent="no"/>

>  <xsl:template match="para">
>   <xsl:variable name="p">
>    <p>
>     <xsl:if test="position() = 1 and parent::listitem">
>      <xsl:call-template name="anchor">
>       <xsl:with-param name="node" select="parent::listitem"/>
>      </xsl:call-template>
>     </xsl:if>
>     
>     <xsl:call-template name="anchor"/>
>     <xsl:apply-templates/>
>    </p>
>   </xsl:variable>
>   
>   <xsl:choose>
>    <xsl:when test="$html.cleanup != 0">
>     <xsl:call-template name="unwrap.p">
>      <xsl:with-param name="p" select="$p"/>
>     </xsl:call-template>
>    </xsl:when>
>    <xsl:otherwise>
>     <xsl:copy-of select="$p"/>
>    </xsl:otherwise>
>   </xsl:choose>
>  </xsl:template>

> </xsl:stylesheet>

Actually, this isn't a bug, it is an expression of the behavior of XSLT import precedence that shows up when you use formalpara/para.

Here is what is going on. The stock <xsl:template match="para"> template wraps its content in <p> </p>, except when its unwrap process kicks in to avoid <p> tags where HTML doesn't like them.

But the block.xsl file also has a template <xsl:template match="formalpara/para">. This template does not output <p> </p> at all, because it knows the wrapper formalpara element's template has already done that, so that the title and para are inside the <p> </p>. Because this template's match pattern is more specific, it has a higher priority that the "para" template.

Now copy the "para" template to your customization layer and import docbook.xsl. The rules of import precedence state that the importing file's templates take precedence over the imported file's templates. In general, that's how customized templates override the stock ones.

But what isn't obvious is that import precedence is stronger than priority selection. So your custom "para" template is used inside formalpara. The "formalpara/para" template has higher priority inside the stock docbook stylesheet, but not in the importing stylesheet. So you end up with nested <p> elements, which is not legal HTML.

The solution is to add another template to your customization layer:

<xsl:template match="formalpara/para">
  <xsl:apply-imports/>
</xsl:template>

Now this template has higher priority than your custom "para" template in the importing stylesheet. Its effect is to use the imported stock "formalpara/para" template, which is what you want in order to avoid the extra <p> elements.

A quick scan of the stylesheets also shows a template in footnote.xsl: <xsl:template match=""footnote/para[1]|footnote/simpara[1]" priority="2"> To avoid problems with footnote paras, you should probably add an apply-imports template for this one too.

32.

Changing the callout markup in html output

Bob Stayton



> How can we get square brackets instead of round brackets in 
> textual callouts using the XSL sheets?


> e.g.

> A portable[1] program...

> ...

> [1] both in terms of compiler and platform!

This will require customizing an XSL template. See the FAQ for how to create a customization layer. The template you are looking for is <xsl:template name="callout-bug"> in html/callout.xsl.

You need to change <xsl:text>(</xsl:text> to <xsl:text>[</xsl:text> (and the closing brace too).

33.

program listing, line numbers

Jeff Beal


>  I'm just about to go through the docbook elements carefully so
>I may run across the answer myself, but I'm trying to figure out
>how to mark up program code with line annotations so that the
>annotations are left-aligned, for aesthetics.

If you're using Saxon or Xalan, Norm has provided an extension function for doing exactly what you want to do:

1) In the programlisting you want to be numbered, set the "linenumbering" attribute to "numbered"
2) Add the appropriate extension jar file for your processor (distributed with the XSL stylesheets) to your CLASSPATH
3) Set the use.extensions parameter to '1'

There are a few more extensions that control the appearance of linenumbering:

(from the HTML Parameter reference)
    linenumbering.everyNth - Indicate which lines should be numbered
    linenumbering.extension - Enable the line numbering extension
    linenumbering.separator - Specify a separator between line numbers and
         lines
    linenumbering.width - Indicates the width of line numbers

34.

customising para element

Bob Stayton



> I seem to have stumbled upon an odd bug.  I wanted to override the
> default <para> match rule, but in certain contexts, I get invalid HTML
> (extra '</p>' end tags).  I then pared it down to the simplest test
> case, and it turns out that even copying the *identical* para match
> rule from "block.xsl" into a customization layer causes the problem.
> Somehow the "unwrap.p" named-template gets defeated, causing invalid
> HTML.


> Here is the test case, "test.xml":

> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
>    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
> <article condition="main">
>  <title>test</title>

>  <itemizedlist>
>   <listitem>
>    <formalpara>
>     <title>title</title>
>    <para>Some problem</para>
>    </formalpara>
>   </listitem> 
>  </itemizedlist>

> </article>

Actually, this isn't a bug, it is an expression of the behavior of XSLT import precedence that shows up when you use formalpara/para.

Here is what is going on. The stock <xsl:template match="para"> template wraps its content in <p> </p>, except when its unwrap process kicks in to avoid <p> tags where HTML doesn't like them.

But the block.xsl file also has a template <xsl:template match="formalpara/para">. This template does not output <p> </p> at all, because it knows the wrapper formalpara element's template has already done that, so that the title and para are inside the <p> </p>. Because this template's match pattern is more specific, it has a higher priority that the "para" template.

Now copy the "para" template to your customization layer and import docbook.xsl. The rules of import precedence state that the importing file's templates take precedence over the imported file's templates. In general, that's how customized templates override the stock ones.

But what isn't obvious is that import precedence is stronger than priority selection. So your custom "para" template is used inside formalpara. The "formalpara/para" template has higher priority inside the stock docbook stylesheet, but not in the importing stylesheet. So you end up with nested <p> elements, which is not legal HTML.

The solution is to add another template to your customization layer:

<xsl:template match="formalpara/para">
  <xsl:apply-imports/>
</xsl:template>

Now this template has higher priority than your custom "para" template in the importing stylesheet. Its effect is to use the imported stock "formalpara/para" template, which is what you want in order to avoid the extra <p> elements.

A quick scan of the stylesheets also shows a template in footnote.xsl: <xsl:template match=""footnote/para[1]|footnote/simpara[1]" priority="2"> To avoid problems with footnote paras, you should probably add an apply-imports template for this one too.

35.

Label seperation in HTML

Bob Stayton


> In DocBook XSL 1.53.0 there is a HTML param 'autotoc.label.separator'
> which sets the string to use to seperate labels and titles in TOC.

> Is there a similar param (I couldn't find one) for setting the string
> to seperate labels and titles in running text (H1, H2, ...)?

> I want to get numbered sections _without_ a trailing '.'.

There is no 'separator' parameter for titles, but you can still customize the titles to remove the dot. The titles use the gentext templates in common/en.xml (for English) under the 'title-numbered' context. You'll see the sect1-5 'text' attributes include the dot and a non-breaking space character.

36.

Cals Table customisation

Bob Stayton


> I'm writing a customization layer for docbook, but I don't know how to
> redeclare tables. I'm starting now with xml and I've understand how to
> ignore, modify, remove elements, mixtures and classes, but with the
> calstblx.dtd file I don't know what do I have to do and where do I have to
> place the modifications. I only want to make these changes:

> <!ENTITY % tbl.table-main.mdl "(tgroup+|graphic+)">
> I want that appears this:
> <!ENTITY % tbl.table-main.mdl "(tgroup+|imageobject+)">


> <!ENTITY % tbl.entry.mdl "(para|warning|caution|note|legend|%paracon;)*">
> I want that appears this:
> <!ENTITY % tbl.entry.mdl "(para|%paracon;)*">

> I have my customization layer (dtd file), and the mod files rdbpool
> (redeclare pool mixtures), rdbhier (redeclare hierarchy mixtures), rdbhier2
> (redeclare hierarchy content model entities), rdbhier3 (redeclare hierarchy
> elements) and rdbinter (redeclare pool elements).
> Please, can anyone explain me in detail what do I have to do?

You are in luck. Since all your changes can be done with changes to existing parameter entities, you only have to declare them before they are declared in the calstblx module. That module is pulled in by the dbpoolx module. You can put your declarations right in your main customization driver file anywhere above where the dbpoolx module is pulled in.

If this is the only change you want, then your entire customization layer could consist of just this:


<!ENTITY % tbl.table-main.mdl "(tgroup+|imageobject+)">
<!ENTITY % tbl.entry.mdl "(para|%paracon;)*">

<!ENTITY % docbook PUBLIC
     "-//OASIS//DTD DocBook XML V4.2//EN"
     "docbookx.dtd">
%docbook;
37.

Customising with language specific text

Bob Stayton


> I have to add some application specific things to the stylesheet and
> I would like to use the internationalization that is used in docbook. 

If you are using the XSL stylesheets, you can add localization entries to your customization layer without touching the distribution files. See: sagehill.net

Entries like this define general text for each language file:


   <l:gentext key="abstract" text="Abstract"/>

The key attribute is the identifier, and the text attribute is the printable text. To call the text from an XSL template, you use the gentext template with the key parameter specified:

 <xsl:call-template name="gentext">
   <xsl:with-param name="key" select="'abstract'"/>
 </xsl:call-template>

This will return the value of the text attribute, which is 'Abstract' in this example.

38.

Customising title chapters

Bob Stayton


> I used docbook-xsl v1.58.1. I've tried to customize the space after
> the title of a chapter in my fo style-sheet by using
> "component.title.properties". This does not work.  Indeed, I take a
> look at fo/component.xsl and "component.title.properties" is never
> used. I will add

>  xsl:use-attribute-sets="component.title.properties"

> around line 41. No?

That is one way to do it, but there's a reason that component.title.properties is not used by the stylesheets. That is because it has been replaced by the fo/titlepage.templates.xml specification file. The parameter should probably be removed from the distribution because people think it is doing something, but it isn't.

The problem was that the component.title template is used by a lot of elements including article, appendix, index, bibliography, glossary, colophon, dedication, and chapter. So change one, you change them all.

The specifications in titlepage.templates.xml let you set properties for each kind of title independently, which gives you much finer control. You have to regenerate the titlepage.templates.xsl stylesheet file when you change the spec file. This URL shows you how to do that (for HTML, but the process for FO is the same):

www.sagehill.net The "Print customization examples" chapter in that book has many other formatting options as well.

39.

Image scaling

Bob Stayton



> I use the depth parameter of the graphic element to resize my screenshots 
> for pdf-output. When I generate HTML output, the image are scaled, too, but 
> this looks ugly, because it's done by the browser. I use my own 
> transformation stylesheet, that includes html/docbook.xsl. What's the 
> easiest way (editing my stylesheet) to generate <img>-tags without the 
> height attribute?

Setting the stylesheet parameter 'ignore.image.scaling' to 1 should work. You'll need stylesheet version 1.59.1 or later.

40.

Adding the date and time.

Rune Lausen




> * generate a timestamp (this is a M$-DOS example)
> echo %date% %time% >timestamp.txt
> * declare this file as an entity:
> <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "docbookx.dtd" [
> ...
> <!ENTITY timestamp SYSTEM "timestamp.txt">
> ...
> ]>
> * and use it
> <pubdate>&timestamp;</pubdate>

Neat!

If you are willing to rely on EXSLT support in the XSLT processor, you could do like I did in our XSL-FO customization layer. It works with Saxon and xsltproc. Don't know about Xalan.

Here is what I did:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
                 xmlns:xlink='http://www.w3.org/1999/xlink'
                 xmlns:date="http://exslt.org/dates-and-times"
                 exclude-result-prefixes="xlink"
                 version="1.0">

<!-- Note the xmlns:date="..." above -->

<!-- SNIP (Imports and other customizations) -->

<!--
      Template formatted for readability.
      May produce extra blanks.
      Add number formatting to ensure two digits in
      time fields.
  -->
   <xsl:template match="pubdate[@role='now']" mode="titlepage.mode">
     <xsl:variable name="now" select="date:date-time()"/>
     <fo:block>
       <xsl:text>Generated at </xsl:text>
       <xsl:value-of select="date:day-in-month($now)"/>
       <xsl:text> </xsl:text>
       <xsl:value-of select="date:month-name($now)"/>
       <xsl:text> </xsl:text>
       <xsl:value-of select="date:year($now)"/>
       <xsl:text> </xsl:text>
       <xsl:value-of select="date:hour-in-day($now)"/>
       <xsl:text>:</xsl:text>
       <xsl:value-of select="date:minute-in-hour($now)"/>
       <xsl:text>:</xsl:text>
       <xsl:value-of select="date:second-in-minute($now)"/>
     </fo:block>
   </xsl:template>

<!-- ETC -->

</xsl:stylesheet>

Document:

<!DOCTYPE book PUBLIC "..." "...">

<book lang="en">
   <bookinfo>
     <title>Blah blah/title>
     <pubdate role="now"/>
     <!-- ETC -->
   </bookinfo>

<!-- ETC -->
</book>
41.

Customising authorgroup

Bob Stayton



> I have an authorgroup with 2 authors in my articleinfo. Their firstnames 
> and surnames get displayed fine, but their email tags get suppressed. 
> How can I get their email addresses to be displayed on the titlepage?

In general, if you want to add a top level element to a titlepage, you add it in the titlepage.templates.xml specification file and generate a new titlepage.templates.xsl.

But in this case, authorgroup is already in the spec file, but you want to change what it does with its children. So it can be done by customizing existing templates.

The template you want to customize is in html/titlepage.xsl:

<xsl:template match="author" mode="titlepage.mode">
  <div class="{name(.)}">
    <h3 class="{name(.)}"><xsl:call-template name="person.name"/></h3>
    <xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
    <xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
  </div>
</xsl:template>

As you can see, it is processing the name, contrib, and affiliation elements. If your email element was inside the affiliation, it would automatically appear. Otherwise, you need to add a line to this template in your customization layer:

<xsl:template match="author" mode="titlepage.mode">
  <div class="{name(.)}">
    <h3 class="{name(.)}"><xsl:call-template name="person.name"/></h3>
    <xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
    <xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
    <xsl:apply-templates mode="titlepage.mode" select="./email"/>
  </div>
</xsl:template>

This template is discussed in my book in the section "Modify individual element templates" in sagehill

42.

Custom footer for print output

Bob Stayton



> I am trying to add a custom footer to every page (a simple
> copyright).
> I am using the RedHat 9 RPMs, including:

> docbook-style-xsl-1.58.1-2
> xmlto-0.0.12-3

To customize the footers in print output, you customize the template named 'footer.content'. The original template is in fo/pagesetup.xsl. It lets you set context conditions for each of pageclass, sequence, and position.

See this reference for further explanation and an example: sagehill

43.

Draft mode

Bob Stayton


> I use xsltproc to generate a resolved and profiled docbook xml file
> (using docbook-profile.xsl, options --xinclude and --param.os ="linux").
> This works fine. When I check the resolved xml file there is nowhere any
> attribute status="draft". When I proces this xml file to a fo file,
> again with xsltproc, and process further to pdf with FOP I get a nice
> pdf file WITHOUT any watermarks.
> I did check when I mark a chapter status="draft" and put in the
> customization file (which is very simple only params are set e.g.
> paper.type etc.) draft.mode parameter to maybe I do get the chapter
> marked draft. When i explicitly set parameter draft.mode to no the image
> url is NOT inserted in the fo file.

> Does anybody know why the url to the unused draft images is in the fo
> file and FOP looks for them over the network? It took me a while to
> figure out why my docbook wouldn't compile to PDF at home (not
> networked) but would in the office.

> In the mean time I do know now I can set draft.watermark.image parameter
> to a local file. But still, curious, is this meant to be so?

The default setting for draft.mode is "maybe". That means the draft watermark is output only for pages that have a status="draft" attribute. I think this was intended as a convenience for those who want to turn on the watermark with an attribute and without having to set a parameter.

When set to "maybe", the stylesheet does not check to see if there are any instances of status="draft" in the document, it just prepares the FO page-master set so the draft page-masters are available in case they are needed.

The reason draft.png is a URL and not a local file path is because the stylesheet cannot manage local files. The stylesheet can only write a path to the FO file, and it is up to the FO processor to locate the draft.png file to integrate it into the PDF. The stylesheet could write a path relative to the stylesheet location, but the FO processor doesn't know the path to the stylesheet directories.

The use of a URL is a compromise, and can be a headache for unsuspecting users. Perhaps the default behavior of the stylesheet should be to check to see if the document has a status="draft" attribute anywhere before outputting the draft page-masters. Then you would run into the URL problem only if you are actually trying to use draft mode.

44.

Docbook customisation for jsp [no html, head, body tags]

Bob Stayton


> Is it possible to customize the generated HTML such
> that it does not include the <html>, <head> and 
> <body> tags?

> The HTML I am generating will be included in some
> JSP pages which already provide these top level
> elements.

I assume you are talking about an XSL customization? If so, then it depends on whether you are chunking or not.

For nonchunked output, you want to customize the 'process.root' template in html/docbook.xsl.

For chunked output, you want to customize the 'chunk-element-content' template in html/chunk-common.xsl.

In both cases, you want to eliminate the <html> and <body> tags, as well as the calls to the header and footer templates. There won't be much left. For example, process.root would go from this original template:

<xsl:template match="*" mode="process.root">
  <xsl:variable name="doc" select="self::*"/>

  <xsl:call-template name="root.messages"/>

  <html>
    <head>
      <xsl:call-template name="system.head.content">
        <xsl:with-param name="node" select="$doc"/>
      </xsl:call-template>
      <xsl:call-template name="head.content">
        <xsl:with-param name="node" select="$doc"/>
      </xsl:call-template>
      <xsl:call-template name="user.head.content">
        <xsl:with-param name="node" select="$doc"/>
      </xsl:call-template>
    </head>
    <body>
      <xsl:call-template name="body.attributes"/>
      <xsl:call-template name="user.header.content">
        <xsl:with-param name="node" select="$doc"/>
      </xsl:call-template>
      <xsl:apply-templates select="."/>
      <xsl:call-template name="user.footer.content">
        <xsl:with-param name="node" select="$doc"/>
      </xsl:call-template>
    </body>
  </html>
</xsl:template>

To just this:

<xsl:template match="*" mode="process.root">
  <xsl:call-template name="root.messages"/>

      <xsl:apply-templates select="."/>

</xsl:template>
45.

Customising figure captions

Charles Plessy

I am using DocBook XML/XSL to write my biology thesis, and I use formalparas in captions for the figure legends. To make them clearly distiguishable from the text, I have set their font to sans-serif, however it looks bigger than the original one.

I modify my customisation layer to reduce the size.

 <xsl:param name="toto">
   <xsl:value-of select="$body.font.master * 0.8"/>
   <xsl:text>pt</xsl:text>
 </xsl:param>
 
 <!-- toto is the french foo -->
 
 <xsl:template match="formalpara/para">
   <fo:block font-family="sans-serif" font-size="{$toto}">
     <xsl:apply-templates/>
   </fo:block>
 </xsl:template>
 
 <!-- changes the font family and size -->
46.

Shade the background of the note element in XSL-FO

Bob Stayton

There is no stylesheet parameter to shade the background of note elements in FO output. But it can be done with attribute-sets in a customization layer:

<xsl:attribute-set name="admonition.properties">
  <xsl:attribute name="background-color">#E0E0E0</xsl:attribute>
  <xsl:attribute name="padding">0.1in</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="admonition.title.properties">
  <xsl:attribute name="background-color">#E0E0E0</xsl:attribute>
  <xsl:attribute name="padding">0.1in</xsl:attribute>
</xsl:attribute-set>
47.

Change from one to two columns on each chapter

Bob Stayton


> I am spending more time tweaking the PDF output of my Docbook files,
> and I was wondering if there was a way to switch from 1-column to
> 2-column from chapter to chapter - would I need to create a new page
> master? Any examples of how anyone else has done this would be most
> appreciated.

Yes, you would need a new set of page masters to switch from 1-column to 2-column from chapter to chapter. See the page masters for index in fo/pagesetup.xsl for examples of 2-column layout. You can add your new pagemasters in the placeholder template named 'user.pagemasters'. Then you will need to customize the 'select.user.pagemaster' template to choose the right pagemaster.

48.

Font size change for programlisting

Jirka Kosek




> How can we specify a different font size just for programlisting elements?

Add following into your customization layer:

<xsl:attribute-set name="verbatim.properties">
   <xsl:attribute name="font-size">8pt</xsl:attribute>
</xsl:attribute-set>

> We also want to use a line-height of > 1 (either 1.5 or 1.8) for everything
> except these programlistings. What is the best way to accomplish this?

You can add as many FO properties as you want into the attribute set mentioned above.

Bob Stayton adds

Actually, if you want a line-height of 1.5 for everything *except* programlisting, then you can put this attribute in the root.properties attribute-set in your customization:

<xsl:attribute name="line-height">1.5</xsl:attribute>

and then put this one in the verbatim.properties attribute-set:

<xsl:attribute name="line-height">1</xsl:attribute>

Any properties in the root.properties attribute-set are inherited by all blocks in the document, unless they are overridden with a different value.

49.

Remove preface numbering

Bob Stayton



>I'd like to stop preface numbrering, and having the first chapter
>numbrered from the very start.
>IE, I have a 6 page preface, I do not want it numbered, but I want the
>first chapter numbered 7.

>Is it possible?

To turn off the display of the page number in the preface, you need to customize the footer.content template to add a xsl:when clause for preface. See this doc for examples: sagehill.net

It's possible to change the page numbering sequences, but currently you would have to customize both the chapter and preface templates. You need to change the initial-page-number property to be "1" in preface, and to be "auto-odd" in chapter, including the first chapter. If you are doing single-sided output, then it should be "auto" instead.

In the next release of the XSL stylesheets (real soon), a new template generates the value of the initial-page-number property for page-sequences. It will be a lot easier to customize the numbering sequences then.

50.

Customizing index layout

Bob Stayton


> I am generating an index.  I would like to
> change the font color used for both the title (Index), and the letters
> for each section (A, B, C, etc).
>
> Where are these parameters located? I cannot find the appropriate
> documentation that states how I can change the appearance of my index.

The titles for index and index divisions can be customized using the titlepage.templates.xml mechanism. You should be able to add a color property and rebuild the XSL templates for title pages. See this reference for more information: sagehill.net

It describes the process for HTML titlepages, but the general method applies to FO titlepages, which are further described in: sagehill.net

51.

Move figure title to below image

Bob Stayton


> I would like to have the title, including the automatically generated
> "Figure 1"  for my image display below the image, but above the
> caption.  Do I have to modify fo/docbook.xsl or is there another file?
> I tried moving <title></title>  into the mediaobject, but that just
> confuses FOP (quite badly).
>
> <figure>
> <title>Regional Model Visualized with OpenDX</title>
> <mediaobject id="RegModel">
> <imageobject role="fo">
> <imagedata fileref="graphics/simpletest.eps" scale="125" format="EPS"/>
>  </imageobject>
> <caption>
> <para>A snapshot of a scientific model. </para>
> </caption>
> </mediaobject>
> </figure>
>
> which produces
>
> Figure 1. Regional Model Visualized with OpenDX
> [image]
> A snapshot of a scientific model.
>
> I'd like it to look like
>
> [image]
> Figure 1. Regional Model Visualized with OpenDX.
> A snapshot of a scientific model.

First, change the 'formal.title.placement' parameter for figure as described in: http://www.sagehill.net/docbookxsl/FormalTitles.html#FormalTitleLocation

To put the caption below the title, though, you need to customize the match="mediabobject" template and the name="formal.object.heading" template. That's because the mediaobject template currently handles the caption, since caption is part of its content. Since figure is a wrapper around mediaobject, you have to tell mediaobject to not output the caption so that formal.object.heading can place it after the title. That means changing the caption line in the mediaobject template:

  <xsl:if test="not(parent::figure)">
    <xsl:apply-templates select="caption"/>
  </xsl:if>

At the end of the template named 'formal.object.heading', add:

  <!-- Add mediaobject caption below title -->
  <xsl:if test="self::figure/mediaobject/caption">
    <xsl:apply-templates select="mediaobject/caption"/>
  </xsl:if>

And then add a template to handle caption:

<xsl:template match="caption">
  <fo:block keep-with-previous.within-column="always">
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

Of course, if you are using FOP the keep won't work ... If you want this repositioning to also apply to tables, examples, etc, then don't make it dependent on figure as I have done here.

52.

Convert footnotes to endnotes

Bob Stayton


> For my  assignments I have to present references as
> endnotes rather than footnotes. They come out that way when I prepare
> html. However in both chunked html and pdf (via fop) they come out at
> the bottom of the page (which of course is expected for footnotes).
>
> Can I via the xsl customizations present footnotes at the end of the
> document (ie as endnotes) when using print and chunked html?

There is no stylesheet parameter that converts footnotes to endnotes, but it can be done with a customization. Take a look at the template with match="footnote" in fo/footnote.xsl, for example. You can customize that to generate endnotes.

First copy the template to your customization layer and remove the fo:footnote elements, because they generate bottom-of-page footnotes. Leave just the part that generates the footnote number, inside an fo:inline:

  <xsl:template match="footnote">
        <fo:inline>
          <xsl:call-template name="format.footnote.mark">
            <xsl:with-param name="mark">
              <xsl:apply-templates select="." mode="footnote.number"/>
            </xsl:with-param>
          </xsl:call-template>
        </fo:inline>
  </xsl:template>

The copy the same template to your customization layer and add mode="endnote". Edit this version to format the number and block of text inside an fo:block:

  <xsl:template match="footnote" mode="endnote">
        <fo:block font-family="{$body.fontset}"
                          font-size="{$footnote.font.size}"
                          font-weight="normal"
                          font-style="normal"
                          text-align="{$alignment}"
                          margin-left="0pc">
          <xsl:call-template name="format.footnote.mark">
            <xsl:with-param name="mark">
              <xsl:apply-templates select="." mode="footnote.number"/>
            </xsl:with-param>
          </xsl:call-template>
          <xsl:text> </xsl:text>
          <xsl:apply-templates/>
        </fo:block>
  </xsl:template>

Then you can generate the list of end notes by having a template like this:

<xsl:template name="make.endnotes">
    <xsl:apply-templates select="//footnote" mode="endnote"/>
</xsl:template>

The only remaining item is figuring out how to call this template at the appropriate place. I don't know how you want to present your end notes in PDF output. Perhaps in an appendix, or some other container. Or use a processing instruction that triggers a template that generates its own page-sequence for the endnotes.

You may also want to make the footnote number a hotlink, or maybe make them go both ways, by generating different ids for each end, and using fo:basic-link around the footnote numbers.