Re: [docbook-apps] ANNOUNCE: docbook2X 0.8.2: convert to man pages and Texinfo
Steve Cheng <[email protected]> Fri, 27 Jun 2003 18:12:34 -0400
| Newsgroups | gmane.text.docbook.docbook2x.general |
|---|---|
| Message-ID | <[email protected]> |
On June 26, 2003 11:14 pm, you wrote: > > That's a very worthy goal. I think docbook2X would be much more widely > used if people could just get it installed. You are right of course. What I find most frustrating is that people who encounter problems do not tell me about them. (... Sorry, have to let off some steam) > Well, if getting rid of the Perl dependencies altogether isn't an option > anywhere on the horizon, it would be nice to see docbook2X at least It can be done, if you insist :) In 15 minutes I made a XSL-based hack that substitutes for db2x_manxml (see attachment). It generates recognizable man pages. (But not suprisingly, whitespace normalizing and character escaping are broken.) -- Steve Cheng 鄭君博
db2x_manxml.xsl
(text/xml, 6 KB)
<?xml version='1.0'?>
<!-- vim: sw=2 sta et
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc"
version='1.0'
xml:lang="en">
<!-- ********************************************************************
$Id: docbook.xsl,v 1.5 2003/06/15 21:39:55 stevecheng Exp $
********************************************************************
© 2003 Steve Cheng <[email protected]>
Part of docbook2X, DocBook to man page conversion.
******************************************************************** -->
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="para">
<xsl:text> </xsl:text>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="text()">
<xsl:call-template name="string-subst">
<xsl:with-param name="content"
select="translate(normalize-space(.), ' ', ' ')" />
<xsl:with-param name="replace" select="'\'" />
<xsl:with-param name="with" select="'\\'" />
</xsl:call-template>
</xsl:template>
<xsl:template name="roff-request">
<xsl:param name="name" />
<xsl:param name="arg-1" />
<xsl:param name="arg-2" />
<xsl:param name="arg-3" />
<xsl:param name="arg-4" />
<xsl:param name="arg-5" />
<xsl:text> .</xsl:text>
<xsl:value-of select="$name" />
<xsl:text> </xsl:text>
<xsl:call-template name="string-subst">
<xsl:with-param name="content" select="$arg-1" />
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'\ '" />
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:call-template name="string-subst">
<xsl:with-param name="content" select="$arg-2" />
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'\ '" />
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:call-template name="string-subst">
<xsl:with-param name="content" select="$arg-3" />
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'\ '" />
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:call-template name="string-subst">
<xsl:with-param name="content" select="$arg-4" />
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'\ '" />
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:call-template name="string-subst">
<xsl:with-param name="content" select="$arg-5" />
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'\ '" />
</xsl:call-template>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template name="string-subst">
<xsl:param name="content" select="''"/>
<xsl:param name="replace" select="''"/>
<xsl:param name="with" select="''"/>
<xsl:choose>
<xsl:when test="not(contains($content,$replace))">
<xsl:value-of select="$content"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($content,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="string-subst">
<xsl:with-param name="content"
select="substring-after($content,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="sp">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'sp'" />
</xsl:call-template>
</xsl:template>
<xsl:template match="indent">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'RS'" />
</xsl:call-template>
<xsl:apply-templates />
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'RE'" />
</xsl:call-template>
</xsl:template>
<xsl:template match="manpage">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'TH'" />
<xsl:with-param name="arg-1" select="@h1" />
<xsl:with-param name="arg-2" select="@h2" />
<xsl:with-param name="arg-3" select="@h3" />
<xsl:with-param name="arg-4" select="@h4" />
<xsl:with-param name="arg-5" select="@h5" />
</xsl:call-template>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="b">
<xsl:text>\fB</xsl:text>
<xsl:apply-templates />
<xsl:text>\fR</xsl:text>
</xsl:template>
<xsl:template match="i">
<xsl:text>\fI</xsl:text>
<xsl:apply-templates />
<xsl:text>\fR</xsl:text>
</xsl:template>
<xsl:template match="SH">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'SH'" />
<xsl:with-param name="arg-1" select="." />
</xsl:call-template>
</xsl:template>
<xsl:template match="SS">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'SS'" />
<xsl:with-param name="arg-1" select="." />
</xsl:call-template>
</xsl:template>
<xsl:template match="TP">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="TPtag">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'TP'" />
</xsl:call-template>
<xsl:apply-templates />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="verbatim">
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'nf'" />
</xsl:call-template>
<xsl:apply-templates />
<xsl:call-template name="roff-request">
<xsl:with-param name="name" select="'fi'" />
</xsl:call-template>
</xsl:template>
<xsl:template match="refnameline">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="refname">
<xsl:if test="preceding-sibling::refname">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="refpurpose">
<xsl:text> \- </xsl:text>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="manpageset">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>