Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DocBook XSL - ok to edit the original stylesheets?

Tags:

xslt

docbook

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?

like image 756
carillonator Avatar asked Jan 24 '23 00:01

carillonator


1 Answers

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">

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

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

</xsl:stylesheet> 
like image 93
Mads Hansen Avatar answered Feb 01 '23 14:02

Mads Hansen