XML technologies / DocBook / Generating (X)HTML / Further output options / Converting to text

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

Converting DocBook XML to text is relatively easy with XSLT, but no ready-made stylesheets are currently available. Use HTML as an intermediate format, as follows:

  1. First validate your document and correct any errors.

  2. Transform your DocBook document with the stylesheet xhtml/docbook.xsl into a single XHTML file, rather than HTML. This is important for producing a text file from XHTML later.

  3. Create the text file by exporting HTML as text through a browser. These programs are suitable:

    • In Mozilla Firefox, choose File > Save Page As.... In the dialog, under File type choose Text files (*.txt; *.text).

    • In Internet Explorer, choose Page > Save As. In the dialog, under File type choose Text File *.txt.

    • With Lynx:

      lynx -dump -nolist HTMLFILE > TEXTFILE

      The program lynx does not handle tables well. In that case, try w3m. The option -nolist suppresses Lynx’s summary of links from the HTML file. Consult the programs’ man pages for further output options.

    • In Opera, open the menu File > Save As... and, under File type choose Text file (*.txt).

    • With w3m:

      w3m -dump HTMLFILE > TEXTFILE

Results depend on how much unnecessary markup the HTML contains. Links, images and other HTML constructs are difficult or impossible to represent as text. Likewise, CSS information is not retained. Use an XSLT customization file to simplify XHTML during transformation. The following example shows one approach.

Example: Customization file for text output through XHTML

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="DBBASISURI/xhtml/docbook.xsl"/>
    <!-- Keine Calloutgrafiken: -->
    <xsl:param name="callout.graphics" select="0"/>
    <!-- Callouts sollen als Unicode-Zeichen erscheinen: -->
    <xsl:param name="callout.unicode" select="0"/>
    <!-- Navigation ist in Texten nutzlos, daher abschalten: -->
    <xsl:param name="suppress.navigation" select="1"/>
    <!-- Inhaltsverzeichnis auf die wichtigsten Element einschränken: -->
    <xsl:param name="generate.toc">
appendix    toc,title
article/appendix    nop
article     toc,title
book        toc,title,figure,table,example,equation
set         toc,title
    </xsl:param>
</xsl:stylesheet>

Replace the placeholder DBBASISURI with the corresponding official URI.

  

back to top