Install and configure the docbook Tool

Source: Internet
Author: User
Tags xsl xslt xslt processor

 

To publish a document using docbook, install the following tools:
* Docbook DTD
* Docbook XSL style sheet
* XSLT processing program
* XSL-FO Processor

The following describes how to install each tool.

1. Install docbook DTD

Docbook DTD can be downloaded (http://www.oasis-open.org/docbook/xml/) on the oasis website, where you can find zip compressed packages. The latest version is 4.2.

In fact, you can not download the docbook DTD. If your document DTD declaration is written as follows:

;! Doctype book public "-// oasis // DTD docbook XML v4.2 // en" http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd ";

According to this definition, most XML processors can obtain the DTD from the network. The advantage of doing so is that the edited docbook document is portable and can be used on a machine without the docbook DTD installed. However, because the docbook DTD is relatively large, obtaining the DTD through the network will affect the processing speed, especially when the low speed network or network is poor.

If you select to use a local DTD, the document's DTD reference should be written as follows:

Linux:
;! Doctype book system "/usr/share/docbook-4.2/docbookx. DTD ";

Windows:
;! Doctype book system "file: // C:/XML/docbook42/docbookx. DTD ";

Docbook provides a way for users to use the same DTD declaration, but you can switch between obtaining a DTD over the network and using a local DTD, and have the advantages of both. This is the role of the catalog file. The typical catalog declaration is as follows:

; Catalog xmlns = "urn: Oasis: names: TC: entity: xmlns: XML: catalog ";
; Group ID = "docbookdtd" prefer = "public ";
; System
Systemid = "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
Uri = "file: // usr/share/XML/docbook42/docbookx. DTD "/;
;/Group;
;/CATALOG;

This statement maps the network DTD to the local DTD. If you use XSLT processor that supports catalog, it first looks for the local file. If the local file does not exist, it looks for the network.

2. Install the docbook XSL style sheet

You can download the docbook XSL style sheet on the http://docbook.sourceforge.net, with the latest version 1.67.2.

After decompression, there are several main directories:
* Common-contains public modules, where files such as languages are located.
* Extensions-extended code written for a specific XSLT processor.
* Fo-XSL style sheets required to generate XSL-FO files.
* HTML-the XSL style sheet required to generate an HTML file.
* Images-images required for document generation.
* Doc-documents related to XSL style sheets are also docbook documents.

There are other directories like htmlhelp, but not necessary to generate HTML or XSL-FO.

3. Install XSLT Processor

There are currently many free XSLT processor, the most commonly used is
* Saxon-implemented in Java at http://saxon.sourceforge.net /.
* Xalan-Java and C ++ versions, http://xml.apache.org/xalan-j/index.html.
* Javastproc-implemented using C, is the fastest processor, http://xmlsoft.org/XSLT/
 
Because both Saxon and xalan have the Java version, you can install it according to the general Java program installation method. The following describes how to install javastproc. Because of its high speed, it is my favorite processing program.

If you are using Windows, you have two options:

* 1. Download the pre-compiled version on Windows.
Ftp://ftp.zlatkovic.com/libxml/
. You need to download libxml, libxslt, and iconv. both are in the zipformat. After the compression, the path of the tproc.exe and. DLL files is added to the environment variable path.
 
If you do not want to edit environment variables, you can simply copy the following files to C:/Windows/system32:
Libxslt. dll
Libxml2.dll
Libexslt. dll
Iconv. dll
Xsltproc.exe

In this way, you can directly find these files in the command line. Run
Xsltproc-version
The installation is completed by printing the current number.
 
* Second, install it in cygwin. This is the method I chose to use. Cygwin is an application that simulates Linux Shell in windows. If you prefer to use xsltproc using Linux commands, you can
Http://www.cygwin.com/
Download the cygwin installer. Cygwin is installed through the network. First, you select libxslt from the package list provided by cygwin. Then, the installer automatically selects libxml2 Based on the dependency, download and install xsltproc. After installation, you can run
Xsltproc-version
To check whether the installation is successful.
 
* Third, if Linux is used, it is likely that the xsltproc has been installed in the system. Run
Xsltproc-version
Check whether the installation is complete. If the command fails or the version is too old, visit the following two URLs to obtain the latest RPM package:
Http://rpmfind.net/linux/rpm2html/search.php? Query = libxml2
Http://rpmfind.net/linux/rpm2html/search.php? Query = libxslt

Switch to the root permission and install the new package:
Rpm-UV libxml2-2.6.17-2.i386.rpm
Rpm-UV libxslt-1.1.12-4.i386.rpm

After completion, you can run
Xsltproc-version
Check whether the installation is complete.

After installation, you can use xsltproc to generate HTML or XSL-FO files.

For example, the following example generates HTML based on the docbook document:
Export tproc -- output myfile.html docbook-XSL/html/docbook. XSL myfile. xml

Or an example of generating a XSL-FO document based on the docbook document:
Export tproc -- output myfile. Fo docbook-XSL/FO/docbook. XSL myfile. xml

On http://xmlsoft.org/xslt/xsltproc2.html, all the scripts for tprocare listed and run directly.
Xsltproc also prints the parameter list.

If you only need to publish HTML documents, so far. If you want to publish a PDF or PS document, you need to install the XSL-FO handler.

4. Install the XSL-FO Handler

The XSL-FO handler generates PDF or PS files based on the XSL-FO files generated by the XSLT handler. Currently, there are far fewer XSL-FO processors to choose from than XSLT processors, because:
A. The XSL-FO standard is developed two years later than the XSLT standard;
B. XSL-FO standards and their huge and complex, the author also found its implementation difficulty, thus the standard is divided into three levels: basic, expansion and complete.

Now available free XSL-FO handlers are:

* Fop-from Apache XML project (http://xml.apache.org/fop ). The latest version is 0.20.5, which is still under development and is not supported by many features, but can be used in general.

* Passivetex-a Tex-based http://www.tei-c.org.uk/Software/passivetex/ processor from Sebastian rahtz (XSL-FO. It is also complicated in development than fop.

There are also some commercial products to choose from. The quality of the generated documents may be better than that of open source code, such:

* Xep (http://www.renderx.com)

* XSL formatter (http://www.antennahouse.com)

The following describes how to install fop.

. Install JDK first.

4.2. Go to http://www.apache.org/dyn/closer.cgi/xml/fop/download fop, you can select the tardy zipzip package. Download and decompress the package to your local device.

4.3. Download the graphic code library. FOP does not support images such as PNG. If images are involved in your document, you need to download additional code libraries. You can choose Jai (http://java.sun.com/products/java-media/jai/current.html) Or Jimi (http://java.sun.com/products/jimi ). Versions earlier than 0.20.5 can only use Jimi. After the download, copy jai_core.jar and jai_codec.jar (JAI), or jimiproclasses. Jar (Jimi) to the lib directory of the FOP installation directory, and then add it in fop. BAT (Windows platform ).

Set localclasspath = % localclasspath %; % libdir %/jai_core.jar
Set localclasspath = % localclasspath %; % libdir %/jai_codec.jar
Or
Set localclasspath = % localclasspath %; % libdir %/jimiproclasses.zip

If you use fop. Sh (Linux), it is automatically searched.

4.4. Add extension code. If the docbook XSL style sheet has extended code for fop (not available currently), add them to the lib directory under the FOP installation directory as above.

Now you can use fop to generate PDF documents. FOP provides two scripts, fop. BAT (Windows platform) and FOP. Sh (UNIX and Linux platform), for ease of use. The command line for generating a PDF file is as follows:
Linux or Unix:
FOP. Sh-XSL/docbook-XSL/FO/docbook. XSL-XML myfile. XML-PDF myfileworkflow

Windows:
FOP. Bat-XSL/docbook-XSL/FO/docbook. XSL-XML myfile. XML-PDF myfileworkflow

During Processing, you may be prompted that some attributes are not supported or are not implemented. Ignore these prompts because FOP is still under development, which does not affect the generation of PDF documents.

At this point, the configuration of a docbook publishing system is complete and can be used to publish documents. You can write tasks on Linux and use the system to automatically publish technical documents.

References:
Docbook Introduction: http://blog.csdn.net/mickeyrat/archive/2005/02/04/281050.aspx
Docbook XSL: the complete guide: http://www.sagehill.net/docbookxsl/index.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.