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:
First validate your document and correct any errors.
Transform your DocBook document with the stylesheet
xhtml/docbook.xslinto a single XHTML file, rather than HTML. This is important for producing a text file from XHTML later.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 > TEXTFILEThe program
lynxdoes not handle tables well. In that case, tryw3m. The option-nolistsuppresses 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.
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top