XML technologies / DocBook / The DocBook XSL stylesheets / Extension functions and extension elements

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

The author Norman Walsh has provided for Saxon and Xalan extensions written in Java that would be impossible or very difficult to implement with standard XSLT. An equivalent for xsltproc is in preparation.

The following problems are difficult or impossible to solve using XSLT alone:

Determining an image’s width and height

XSLT cannot determine an image’s width and height. The following extension functions are therefore provided: getWidth and getDepth.

Calculating table column widths

The CALS table model supports absolute (3cm) and relative (2*) column widths, as well as a combination (2*+3mm) of both. Although XSL-FO has a corresponding attribute (proportional-column-width), HTML has no equivalent. For this purpose, the extension function adjustColumnWidths calculates the absolute column widths.

Callouts

Callout positions can also be specified outside the text (see Callouts). The extension function insertCallouts inserts these callouts into the relevant text.

Text insertion

DocBook uses textdata to reference external, non-XML text data. XSLT 1 has no mechanism for inserting external text files. The extension function insertfile remedies this limitation.

Line numbering

Numbered program listings are possible in XSLT 1 with some effort. The extension function numberLines makes this task easier.

To use extension functions, you need Saxon or Xalan and must enable the appropriate parameters in the following table, “Extension function parameters”. Set the value to 1. By default, all extension functions (except use.extensions) are set to 1 (= on). 

Table: Extension function parameters

Parameters

Description

use.extensions

the “master switch”, without which nothing works; one of the following parameters must also be enabled.

callouts.extension

used to position callouts

linenumbering.extension

enables line numbering, as in screen and programlisting.

tablecolumns.extension

enables calculation of table column widths.

textinsert.extension

enables text insertion.

graphicsize.extension

enables calculation of image width and depth.

To enable extended callout handling, invoke Saxon as follows:

saxon -o OUTFILE XML_FILE XSLT_FILE \ 
  use.extensions="1" callouts.extension="1" ...

The equivalent invocation with Xalan is as follows:

xalan -OUT OUTFILE -IN XML_FILE -XSL XSLT_FILE \
  -PARAM use.extensions "1" -PARAM callouts.extension "1"

  

back to top