XML technologies / DocBook / Block elements / Program listings / Numbering lines
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
Numbering every line of a listing is currently possible only with Saxon or Xalan, not with xsltproc.
Line numbering uses the linenumbering attribute:
<programlisting linenumbering="numbered">#!/usr/bin/python -u
...
</programlisting>By default, numbering starts at 1. The optional attribute startinglinenumber sets any starting number. To continue numbering from an earlier listing, specify continuation with the value continues.
To enable line numbering, set both DocBook stylesheet parameters use.extensions and linenumbering.extension to 1. To customize the interval, width or separator, use processing instructions as shown in the following example.
Example: Controlling interval, width and separator with processing instructions
<programlisting linenumbering="numbered"
><?dbhtml
linenumbering.everyNth="2"
linenumbering.separator=" |"
linenumbering.width="2"
?><?dbfo
linenumbering.everyNth="2"
linenumbering.separator=" |"
linenumbering.width="2"
?>#!/usr/bin/python -u
...
</programlisting>Line 1: Add the attribute linenumbering and position the processing instructions so that no accidental whitespace is inserted.
Line 2: This processing instruction targets (X)HTML.
Line 3: Numbering interval, here every second line.
Line 4: Separator between line number and text
Line 5: Column width
Line 6: This processing instruction targets XSL-FO. The parameters are the same as in line 2.
For more information on these processing instructions, see Adjusting output with processing instructions.
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top