tags:

views:

75

answers:

1

I would like to make certain lines of a DocBook table of contents bold based on whether the particular <section> has a certain attribute defined. This is easy by adding an <xsl:if test="..."> statement to the DocBook XSL (fo/autotoc.xsl lines 187-230 -- this is for output to PDF using XMLMind).

I'm wondering, though, if it's bad practice to edit the DocBook XSLs themselves. I have other customizations in a separate XSL of my own, mostly setting parameters, but I can't imagine how I would introduce this conditional logic--based on which line of the TOC is currently being processed--without putting some sort of code in the originals. Any thoughts? How do you upgrade to a newer DocBook XSL after making changes?

+6  A: 

Import the docbook stylesheets from your own XSLT. Then, (re)define the Docbook template that you want to "override".

Since your template will be the highest in the import tree, it will take precedence.

By doing it that way you don't have to modify any of the core docbook XSLT files. It will make upgrades of the Docbook stylesheets easier in the future.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

<xsl:import href="xsl/fo/docbook.xsl"/>

<xsl:template match="template-that-you-need-to-redefine">
  ...
</xsl:template>

</xsl:stylesheet>
Mads Hansen
awesome, thank you.
carillonator
I can recommend _DocBook XSL: The Complete Guide_ by Bob Stayton which is a really awesome resource. Chapter 9 contains instructions for customizing DocBook XSL stylesheets: http://www.sagehill.net/docbookxsl/CustomMethods.html
Jukka Matilainen