Generate HTML from DocBook in Ubuntu

DocBook is a widely-used format for writing documentation, articles, books, etc. For my purposes, I needed to generate an XHTML file from a DocBook file on an Ubuntu server.


You need to install the following packages.

sudo aptitude install xsltproc docbook-xsl-ns

I’m not sure if you really need to install the following but I did anyways.:

sudo aptitude install docbook5-xml

Convert DocBook to XHTML

Now comes the conversion. Run xsltproc as below and it will create an HTML file (mydocbook.html in this case) in the current directory.

xsltproc -o mydocbook.html /usr/share/xml/docbook/stylesheet/docbook-xsl-ns/xhtml-1_1/docbook.xsl mydocbook.xml

You can explore the /usr/share/xml/docbook/stylesheet/docbook-xsl-ns/ path for more options.

bash alias

Since I work with one DocBook file only, I have created a bash alias as below:

alias wpdoc="xsltproc -o /home/codeghar/book/wikiply.html /usr/share/xml/docbook/stylesheet/docbook-xsl-ns/xhtml-1_1/docbook.xsl /home/codeghar/book/wikiply.docbook.xml; sed -e 's/</\n</g' -e 's/<meta name/\n<meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/> \n <meta name/g' -i /home/codeghar/book/wikiply.html"

The generated file does not have the HTML meta tag to identify it as UTF-8 and so space characters display as the character  in the web browser. Therefore, sed is used to enter the appropriate meta tag in the file.

Hat Tips

DocBook Ubuntu Documentation; How to generate pdf from docbook 5.0; Getting Started with Docbook Book Authoring on Ubuntu; Writing Documentation

Comments are closed.

%d bloggers like this: