This is an old revision of the document!


Metaware

The Technology Behind the Text

This book is being written in DocBook XML, which is the format that O'Reilly likes for cross publishing to paper, the web, and other forms. We're bringing that vision to the wiki as well. All the Chapters are being automatically translated via a scripted pipeline to Dokuwiki formatting and are posted here periodically.

Building a Doku Wiki from a DocBook XML document

I've hacked together something out of Saxon-B, and sed all running on Cygwin on my PC. Don't look below if you have a weak stomach.

— Randy

todoku.bat

cp BuildingReputation/ch01.xml .
rm -f ch01.doku
cat ch01.xml | sed -e 's/^[ \t]*//' | sed 's/^<entry^>/^<entry align="center"^>/' >temp.doku
java -jar saxon9.jar -t -s:temp.doku -xsl:docbook2dokuwiki.xsl -o:temp2.doku
sed -e 's/^&lt;/^</' < temp2.doku | sed -e 's/^&gt;/^>/' | tail +2 >ch01.doku
rm -f temp*.doku

The sed calls, in order:

  • removes leading white space from every line. Dokuwiki interprets it as significant. Sigh.
  • I don't understand xsl: vars yet, so just add an align to every table entry that doesn't explicitly set it.
  • Dokuwiki plugins have their own tag parameter formatting (no equal signs) so I have to fix the longhand lt and gt.
  • The tail command strips off the top xsl header added by saxon for easy cut and paste.

docbook2dokuwiki.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="sect1/title">
==== <xsl:apply-templates/> ====
</xsl:template>

<xsl:template match="sect2/title">
=== <xsl:apply-templates/> ===
</xsl:template>

<xsl:template match="sect3/title">
== <xsl:apply-templates/> ==
</xsl:template>

<xsl:template match="title">
===== <xsl:apply-templates/> =====
</xsl:template>

<xsl:template match="para">
<xsl:apply-templates/><xsl:text>

</xsl:text>
</xsl:template>

<xsl:template match="emphasis">//<xsl:apply-templates/>//</xsl:template>
<xsl:template match="itemizedlist/listitem">  * <xsl:apply-templates/></xsl:template>


<xsl:template match="sidebar">
<xsl:text>&lt;box center blue 75%</xsl:text> <xsl:apply-templates/>
</xsl:template>

<xsl:template match="sidebar/title">| <xsl:apply-templates/><xsl:text>&gt;</xsl:text></xsl:template>

<xsl:template match="sidebar/para">
<xsl:apply-templates/><xsl:text>&lt;/box&gt;
</xsl:text>
</xsl:template>

<xsl:template match="sidebar/variablelist">
<xsl:apply-templates/><xsl:text>&lt;/box&gt;
</xsl:text>
</xsl:template>

<xsl:template match="variablelist"><xsl:apply-templates/></xsl:template>

<xsl:template match="varlistentry"><xsl:apply-templates/></xsl:template>

<xsl:template match="varlistentry/term">
  * **<xsl:apply-templates/>**</xsl:template>

<xsl:template match="varlistentry/listitem">
    * <xsl:apply-templates/></xsl:template>

<xsl:template match="varlistentry/para"><xsl:apply-templates/></xsl:template>

<xsl:template match="informalfigure"><xsl:apply-templates/></xsl:template>

<xsl:template match="figure">
== Figure: <xsl:value-of select="title"/> ==
<xsl:apply-templates/></xsl:template>

<xsl:template match="figure/title"></xsl:template>

<xsl:template match="mediaobject"><xsl:apply-templates/></xsl:template>

<xsl:template match="imageobject"><xsl:apply-templates/></xsl:template>

<xsl:template match="imagedata">
<html>
<center>
<img src="http://buildingreputation.com/lib/exe/fetch.php?media={@fileref}"/><xsl:value-of select="."/>
</center>
</html>
</xsl:template>

<xsl:template match="textobject"><xsl:text>
</xsl:text></xsl:template>

<xsl:template match="table">
=== <xsl:value-of select="title"/> ===
<html>
<table align="center" border="1">
<xsl:apply-templates/>
</table>
</html>
</xsl:template>

<xsl:template match="table/title"></xsl:template>
<xsl:template match="tgroup"><xsl:apply-templates/></xsl:template>

<xsl:template match="thead">
<thead>
<xsl:apply-templates/>
</thead>
</xsl:template>

<xsl:template match="tbody">
<tbody>
<xsl:apply-templates/>
</tbody>
</xsl:template>

<xsl:template match="row">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>

<xsl:template match="entry"><td align="{@align}"><xsl:value-of select="."/></td></xsl:template>

<xsl:template match="remark">
&lt;color gray&gt;[Author's comment:<xsl:apply-templates/>]&lt;/color&gt;<xsl:text>

</xsl:text>
</xsl:template>

</xsl:stylesheet>

This is oversimplified. Don't use it. Really. I can't believe I'm using it, but I am in a hurry at the moment.

metaware.1231370764.txt.gz · Last modified: 2023/03/12 12:11 (external edit)
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0