All pastes #47716 Raw Edit

db2html script

public text v1 · immutable
#47716 ·published 2006-03-31 19:13 UTC
rendered paste body
#!/bin/sh

# This script converts a DocBook XML file into HTML and then displays it using a
# Web browser.  This script uses Firefox to display the generated HTML.  If you
# use a different Web browser, change the BROWSER variable below.
#
# There are only (!) five things you need for this script to work:
#
# 1. A shell that can execute this script.  On UNIX/Linux systems, you get this
#    for free.  On Windows, you can install Cygwin from http://www.cygwin.com/
#    to get the Bash shell.
#
# 2. The DocBook 4.2 XML DTD (Document Type Definition).  This is a file named
#    docbookx.dtd along with a bunch of supporting files having the extensions
#    .mod, .cat, and .ent. The DocBook DTD is used to validate the syntactic
#    correctness of your DocBook XML file.  It also defines entitiies such as
#    " ", which is replaced by a non-breaking space.  You can download the
#    DocBook 4.2 DTD files from:
#
#	http://www.oasis-open.org/docbook/xml/4.2/
#
#    After you download the DocBook DTD, put the files in a directory of your
#    choosing, and change variable DOCBOOK_DTD_DIR in this script to point to
#    that directory.  You can learn more about DTDs at:
#
#	http://en.wikipedia.org/wiki/Document_Type_Definition
#
# 3. A DocBook XSL (Extensible Stylesheet Language) stylesheet that outputs HTML.
#    You can download this from:
#
#	http://sourceforge.net/projects/docbook
#
#    Download only the "docbook-xsl" package.  The other packages at that site
#    are not needed.  After downloading the docbook-xsl archive file, unpack it
#    into a directory of your choosing, and change the variable DOCBOOK_XSL_DIR
#    in this script to point to that directory.
#
# 4. The LDP customization stylesheet.  This is a stylesheet written by the LDP
#    that makes the generated HTML conform to LDP conventions.  You can download
#    this from:
#
#	http://www.happy-monkey.net/docbook/
#
#    The above page has installation instructions for the LDP customization
#    stylesheet, which basically just requires unpacking the archive and copying
#    some files.  This stylesheet is actually optional, but if you don't install
#    it, then you won't get numbered sections.  You must install this on top of
#    the DocBook XSL stylesheet -- don't install it in a separate directory.
#
# 5. An XSLT (Extensible Stylesheet Language Transformations) processor.  This
#    is a program that reads the DocBook DTD, the DocBook XSL for a given kind
#    of output (e.g., HTML), and the DocBook XML document you have written,
#    validates the document against the DTD and uses the stylesheet to convert
#    the document into the output format (e.g., HTML).
#
#    Most Linux systems come with an XSLT processor named "xsltproc", which is
#    what this script invokes.  If you are using Windows, you can install Cygwin
#    from http://www.cygwin.com/ which includes xsltproc.  You can learn more
#    about XSLT processors at:
#
#	http://en.wikipedia.org/wiki/Xslt
#
# IMHO, it's sad that converting DocBook XML to HTML is so complicated.  This is
# what you get when engineers create tools for other engineers.


################################################################################
# Change these variables so they are appropriate for your system.

# Change this to point to the directory containing the DocBook DTD (i.e., the
# directory containing the file docbookx.dtd and its supporting files).

DOCBOOK_DTD_DIR="/cygdrive/c/franl/work/ldp/dtd-4.2"

# Change this to point to the directory containing the DocBook XSL stylesheet.

DOCBOOK_XSL_DIR="$HOME/work/ldp/xsl/docbook-xsl-1.69.1"

# Change this to point to the temporary file in which the converted HTML will
# be stored.

TMPFILE="c:/temp/db2html.html"

# Change this to point to your preferred Web browser.

BROWSER="c:/program files/mozilla firefox/firefox.exe"

################################################################################
# We use the LDP customization stylesheet if it's installed, otherwise we use
# the DocBook XSL stylesheet.

if [ -f "$DOCBOOK_XSL_DIR/html/tldp-one-page.xsl" ]
then
	STYLESHEET="file://$DOCBOOK_XSL_DIR/html/tldp-one-page.xsl"
else
	STYLESHEET="file://$DOCBOOK_XSL_DIR/html/docbook.xsl"
fi

################################################################################
# Now do the conversion.

rm -f "$TMPFILE"

# This entire script exists basically to execute these two commands, so you
# could probably just type these commands by hand, after manually substituting
# the variables.

. "$DOCBOOK_XSL_DIR/.profile.incl"

xsltproc --nonet --path "$DOCBOOK_DTD_DIR" --output "$TMPFILE" "$STYLESHEET" "$@"
#xsltproc --output "$TMPFILE" "$STYLESHEET" "$@"

################################################################################
# Now display the result (if the conversion was successful).

if [ -f "$TMPFILE" ]
then
	"$BROWSER" "file://$TMPFILE" &
	exit 0
fi

echo "No HTML file produced due to errors!" >&2
exit 1