This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
Re: XSLT for text files ?(Re: XSL from DocBook refentry-> man)
Dan York wrote:
<SNIP>
> So there we are... a CSV file from a XML file by way of an XSLT stylesheet.
> Not really overly useful, perhaps, but it was an interesting learning
> experiment I did.
>
> I personally have never written a man page, so I don't know what's exactly
> involved... but this is the (very basic) way you could get a stylesheet going.
>
> Regards,
> Dan
>
>
As a little training I did a (really quick and ugly hack so don't take
it too seriously) XSL stylesheet that should produce the correct output
for the nologin manpage (which is my testcase right now), the goal would
be 'man 7 man' compliance on a Linux box (note, I cleaned this up
without checking that the cleaned up version actually works, too far
from my XSLT processor right now):
(Sorry for the length of the message)
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/refentry">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="refmeta">
<xsl:text>.TH </xsl:text>
<xsl:value-of select="refentrytitle"/>
<xsl:text> </xsl:text>
<xsl:value-of select="manvolnum"/>
<xsl:text> </xsl:text>
<xsl:value-of select="refmiscinfo"/>
<xsl:text>

</xsl:text>
</xsl:template>
<xsl:template match="refnamediv">
<xsl:text>.SH NAME</xsl:text>
<xsl:text>
</xsl:text>
<xsl:value-of select="refname"/>
<xsl:text> \- </xsl:text>
<xsl:value-of select="refpurpose"/>
<xsl:text>

</xsl:text>
</xsl:template>
<xsl:template match="refsect1">
<xsl:text>.SH </xsl:text>
<xsl:value-of select="title"/>
<xsl:text>
</xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="para">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="filename">
<xsl:choose>
<xsl:when test="@class='headerfile'">
<xsl:text>.B </xsl:text>
<xsl:value-of select="."/>
<xsl:text>
.sp
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>.I </xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="para/text()">
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="citerefentry">
<xsl:text>.BR </xsl:text>
<xsl:value-of select="refentrytitle"/>
<xsl:text> "(</xsl:text>
<xsl:value-of select="manvolnum"/>
<xsl:text>)"
</xsl:text>
</xsl:template>
<xsl:template match="text()|*"/>
</xsl:stylesheet>
and the XML file would be something like:
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<refentry id="nologin">
<refmeta>
<refentrytitle>NOLOGIN</refentrytitle>
<manvolnum>5</manvolnum>
<refmiscinfo>"December 29 1992" "Linux" "Linux Programmer's
Manual"</refmiscinfo>
</refmeta>
<refnamediv>
<refname>nologin</refname>
<refpurpose>prevent non-root users from logging into the
system</refpurpose>
</refnamediv>
<refsect1>
<title>DESCRIPTION</title>
<para>
If the file
<filename>/etc/nologin</filename>
exists,
<citerefentry>
<refentrytitle>login</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>
will allow access only to root. Other users will
be shown the contents of this file and their logins refused.
</para>
</refsect1>
<refsect1>
<title>FILES</title>
<para>
<filename>/etc/nologin</filename>
</para>
</refsect1>
<refsect1>
<title>SEE ALSO</title>
<para>
<citerefentry>
<refentrytitle>login</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>
,
<citerefentry>
<refentrytitle>shutdown</refentrytitle>
<manvolnum>8</manvolnum>
</citerefentry>
</para>
</refsect1>
</refentry>
So it can be done, question is how many ugly hacks will have to be
made....well...thats another issue....time to go to bed
Regards,
David