Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

DocBook with Eclipse - Tutorial

Lars Vogel

Version 1.6

17.01.2010

Revision History
Revision 0.1 - 0.528.06.2007Lars Vogel
Created
Revision 0.616.10.2008Lars Vogel
Adjusted the xinclude description
Revision 0.703.11.2008Lars Vogel
How to add external HTML code to the HTML output
Revision 0.817.04.2009Lars Vogel
Removed broken link, restructured article
Revision 0.925.07.2009Lars Vogel
Simplified installation description
Revision 1.026.07.2009Lars Vogel
added XSLT definition
Revision 1.110.08.2009Lars Vogel
Removed autobuilder
Revision 1.211.08.2009Lars Vogel
xinclude now using Eclipse XSL, update to Eclipse 3.5
Revision 1.317.08.2009Lars Vogel
Simplified description
Revision 1.427.08.2009Lars Vogel
Typo fixed, removed xalan include and using the standard XML parser of JDK
Revision 1.512.09.2009Lars Vogel
Typo fixed
Revision 1.617.01.2010Lars Vogel
added suggested project to description

DocBook

This article explains how to write DocBook files in Eclipse and how to convert these files into various output formats, e.g. to HTML and pdf. It also explains how to configure XInclude to divide the information into different source files.

This article uses Eclipse 3.5.


Table of Contents

1. Introduction to DocBook
1.1. Overview
1.2. Example
1.3. The required toolset
2. Installation
2.1. Eclipse
2.2. Docbook and Stylesheets
2.3. XSL processor
3. Putting it to work
3.1. Project
3.2. Add xalan
3.3. Write your first DocBook document
3.4. Use ant to convert DocBook to html
4. Docbook examples
4.1. Tags
4.2. Tables
4.3. Lists
4.4. Links
4.5. Including images
5. Create pdf output
5.1. Installation
5.2. Define the Ant Task
6. Influencing the output result
6.1. HTML Parameters
6.2. pdf Parameters
6.3. Add content into the HTML output
7. Using XInclude with Eclipse XSL
7.1. Overview
7.2. Eclipse XSL Tools
7.3. Using the XInclude ant task
8. Thank you
9. Questions and Discussion
10. Links and Literature

1. Introduction to DocBook

1.1. Overview

DocBook is a standard for creating well-formated plain text documents. It allows the creation of documentation that is portable between different operating systems and text processing tools. DocBook documents can easily be transformed into other output formats. DocBook is plain text and can therefore be writen in a text editor which supports plain text as output format and put under version control.

You can convert DocBook via XSLT to any other document format you want. XSLT stands for Extensible Stylesheet Language Transformation.

Stylesheets for converting DocBook to common output are available, e.g. to convert into HTML, pdf, java help or Unix man pages.

To translate the DocBook source file into other formats you need:

  • A XSLT Stylesheet to transform the DocBook document into another output format, e.g. html

  • A XSLT parser

  • A CSS style sheet to format your output

DocBook has two main document class, book and article.

  • Article: Used for writing technical articles. The main tag is article. Article is used in the following example.

  • Book: Used for longer description. The main tags is book. In addition to sections which are used in an article another structuring element exists, the chapter.

1.2. Example

The following is an example of a DocBook document:

				
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "../docbook-xml-4.5/docbookx.dtd">
<article>
	<articleinfo>
		<title>DocBook Intro</title>
		<author>
			<firstname>Lars</firstname>
			<surname>Vogel</surname>
		</author>
	</articleinfo>
	<sect1 label="1.0">
		<title>An introduction to DocBook</title>
		<para> 
			This is text.
		</para>
	</sect1>
</article>

			

Tip

The above defines that the DTD is stored in a directory one levels above the document directory.

1.3. The required toolset

To create DocBook files and to convert them into other formats you have to use :

  • The DocBook DTD which defines how a DocBook must be written.

  • XSLT stylesheets to convert your DocBook into another format.

  • A XSLT parser

We will use Eclipse as an XML editor, Xalan as the XSLT parser and Apache Ant for the XSLT transformation.