In this post I will demonstrate and explain howto create a manual with the DocBook XML schema using Saxon as XSLT processor the DocBook XSL as stylesheet and xslthl for syntax highlighting. More informations about DocBook at docbook.org. Note in some files you have to adjust the paths according to your system (I have build this on an windows machine using absolute paths).
First you need the following files. Note xslthl is included in the DocBook XSL in the folder highlighting but it is maybe not the latest version. Because Saxon is writte in Java you need also an working JRE on your system. We cant use a newer version of Saxon because we need an XSLT 1.0 processor for parsing the
DocBook XSL.
- DocBook XSL (1.76.1)
- Saxon (6.5.5)
- xslthl (2.0.2)
In order to create a manual we need some DocBook XML wich we later convert to HTML. Here an example DocBook XML file called manual.xml with some dummy code.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<book lang="en">
<bookinfo>
<title>DocBook with syntax highlighting</title>
<abstract>
<para>A simple demonstration howto cre</para>
</abstract>
</bookinfo>
<chapter>
<title>Foobar</title>
<para>Here an simple example of some dummy code with syntax highlighting:</para>
<programlisting language="php"><![CDATA[
<?php
class foo
{
private $bar;
public function __construct($bar)
{
$this->bar = $bar;
}
/**
* getFoo
*
* Returns bar if $this->bar is foo else foo .. Oo ;D
*
* @return string
*/
public function getFoo()
{
if($this->bar == 'foo')
{
return 'bar';
}
else
{
return 'foo';
}
}
}
]]></programlisting>
</chapter>
</book>
In order to use xslthl and to set some other settings we create a costum XSL file called “manual.xsl”.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="file:///I:/application/tools/saxon/docbook-xsl-1.76.1/html/docbook.xsl" /> <xsl:import href="file:///I:/application/tools/saxon/docbook-xsl-1.76.1/html/highlight.xsl" /> <xsl:param name="html.stylesheet" select="'foo.css'" /> <xsl:param name="section.autolabel" select="1" /> <xsl:param name="chapter.autolabel" select="1" /> <xsl:param name="appendix.autolabel" select="1" /> <xsl:param name="section.label.includes.component.label" select="1" /> <xsl:param name="highlight.source" select="1" /> </xsl:stylesheet>
Now we have all files wich we need to transform the XML. We are using the following command:
java -cp "I:/application/tools/saxon/saxon.jar;I:/application/tools/saxon/xslthl.jar" -Dxslthl.config="file:///I:/application/tools/saxon/docbook-xsl-1.76.1/highlighting/xslthl-config.xml" com.icl.saxon.StyleSheet -o J:/test/manual.html J:/test/manual.xml J:/test/manual.xsl
If everything works correctly you should have created a new file “manual.html”. From this point you can extend the example to build a complete manual using the DocBook XML schema with syntax highlite.