]> granicus.if.org Git - docbook-dsssl/commitdiff
Initial checkins; moved from contrib by nwalsh
authorNorman Walsh <ndw@nwalsh.com>
Thu, 4 Jul 2002 20:27:53 +0000 (20:27 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Thu, 4 Jul 2002 20:27:53 +0000 (20:27 +0000)
xsl/manpages/README [new file with mode: 0644]
xsl/manpages/db2man.xsl [new file with mode: 0644]
xsl/manpages/lists.xsl [new file with mode: 0644]
xsl/manpages/sect23.xsl [new file with mode: 0644]
xsl/manpages/synop.xsl [new file with mode: 0644]
xsl/manpages/xref.xsl [new file with mode: 0644]

diff --git a/xsl/manpages/README b/xsl/manpages/README
new file mode 100644 (file)
index 0000000..36368cd
--- /dev/null
@@ -0,0 +1,10 @@
+README for db2man by Martijn van Beers (lotr@users.sourceforge.net)
+
+I've been working on some stylesheets to convert <refentry>s to man
+format. I thought I'd submit what I have for inclusion in the
+docbook-xsl package.
+
+See also:
+
+  http://sourceforge.net/tracker/index.php?func=detail&aid=468779&group_id=21935&atid=373749
+
diff --git a/xsl/manpages/db2man.xsl b/xsl/manpages/db2man.xsl
new file mode 100644 (file)
index 0000000..ae8eebf
--- /dev/null
@@ -0,0 +1,423 @@
+<?xml version='1.0'?>
+<!-- vim:set sts=2 shiftwidth=2 syntax=sgml: -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'>
+
+<xsl:import href="../html/docbook.xsl"/>
+<xsl:include href="synop.xsl"/>
+<xsl:include href="lists.xsl"/>
+<xsl:include href="xref.xsl"/>
+
+<!-- Needed for chunker.xsl (for now): -->
+<xsl:param name="chunker.output.method" select="'text'"/>
+<xsl:param name="chunker.output.encoding" select="'ISO-8859-1'"/>
+
+<xsl:output method="text"
+            encoding="ISO-8859-1"
+            indent="no"/>
+
+<!--
+  named templates for bold and italic. call like:
+
+  <xsl:apply-templates mode="bold" select="node-you-want" />
+-->
+<xsl:template mode="bold" match="*">
+  <xsl:text>\fB</xsl:text>
+  <xsl:value-of select="."/>
+  <xsl:text>\fR</xsl:text>
+</xsl:template>
+
+<xsl:template mode="italic" match="*">
+  <xsl:text>\fI</xsl:text>
+  <xsl:value-of select="."/>
+  <xsl:text>\fR</xsl:text>
+</xsl:template>
+
+<xsl:template match="refsect2">
+  <xsl:text>&#10;.Sh "</xsl:text>
+  <xsl:value-of select="title[1]"/>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="caution|important|note|tip|warning">
+  <xsl:text>&#10;.RS&#10;.Sh "</xsl:text>
+  <!-- capitalize word -->
+  <xsl:value-of
+    select="translate (substring (name(.), 1, 1), 'cintw', 'CINTW')" />
+  <xsl:value-of select="substring (name(), 2)" />
+  <xsl:if test="title">
+    <xsl:text>: </xsl:text>
+    <xsl:value-of select="title[1]"/>
+  </xsl:if>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;.RE&#10;</xsl:text>
+</xsl:template> 
+
+<xsl:template match="refsect1">
+  <xsl:text>&#10;.SH "</xsl:text>
+  <xsl:value-of select="translate(title[1],'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
+  <xsl:text>"
+</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="refsynopsisdiv">
+  <xsl:text>&#10;.SH "SYNOPSIS"&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+
+<xsl:template match="para">
+  <xsl:text>&#10;.PP&#10;</xsl:text>
+  <xsl:for-each select="node()">
+    <xsl:choose>
+      <xsl:when test="self::screen|self::programlisting|self::itemizedlist|self::orderedlist|self::variablelist">
+        <xsl:text>&#10;</xsl:text>
+        <xsl:apply-templates select="."/>
+      </xsl:when>
+      <xsl:when test="self::text()">
+       <xsl:if test="starts-with(translate(.,'&#10;',' '), ' ') and
+                     preceding-sibling::node()[name(.)!='']">
+         <xsl:text> </xsl:text>
+       </xsl:if>
+        <xsl:variable name="content">
+         <xsl:apply-templates select="."/>
+       </xsl:variable>
+       <xsl:value-of select="normalize-space($content)"/>
+       <xsl:if
+        test="translate(substring(., string-length(.), 1),'&#10;',' ') = ' ' and
+              following-sibling::node()[name(.)!='']">
+         <xsl:text> </xsl:text>
+       </xsl:if>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:variable name="content">
+          <xsl:apply-templates select="."/>
+        </xsl:variable>
+        <xsl:value-of select="normalize-space($content)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:for-each>
+  <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="simpara">
+  <xsl:variable name="content">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:text>&#10;&#10;</xsl:text>
+  <xsl:value-of select="normalize-space($content)"/>
+  <xsl:text>
+</xsl:text>
+</xsl:template>
+
+  
+<xsl:template match="refentry">
+  <xsl:variable name="section" select="refmeta/manvolnum"/>
+  <xsl:variable name="name" select="refnamediv/refname[1]"/>
+
+  <xsl:call-template name="write.text.chunk">
+    <xsl:with-param name="filename"
+                   select="concat(normalize-space ($name), '.', $section)"/>
+    <xsl:with-param name="content">
+      <xsl:text>.\"Generated by db2man.xsl. Don't modify this, modify the source.
+.de Sh \" Subsection
+.br
+.if t .Sp
+.ne 5
+.PP
+\fB\\$1\fR
+.PP
+..
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Ip \" List item
+.br
+.ie \\n(.$>=3 .ne \\$3
+.el .ne 3
+.IP "\\$1" \\$2
+..
+.TH "</xsl:text>
+      <xsl:value-of select="translate(refmeta/refentrytitle,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
+      <xsl:text>" </xsl:text>
+      <xsl:value-of select="refmeta/manvolnum[1]"/>
+      <xsl:text> "</xsl:text>
+      <xsl:value-of select="refentryinfo/date"/>
+      <xsl:text>" "</xsl:text>
+      <xsl:value-of select="refentryinfo/productname"/>
+      <xsl:text>" "</xsl:text>
+      <xsl:value-of select="refentryinfo/title"/>
+      <xsl:text>"
+</xsl:text>
+      <xsl:apply-templates/>
+      <xsl:text>&#10;</xsl:text>
+
+      <!-- Author section -->
+      <xsl:choose>
+        <xsl:when test="refentryinfo//author">
+          <xsl:apply-templates select="refentryinfo" mode="authorsect"/>
+        </xsl:when>
+        <xsl:when test="/book/bookinfo//author">
+          <xsl:apply-templates select="/book/bookinfo" mode="authorsect"/>
+        </xsl:when>
+        <xsl:when test="/article/articleinfo//author">
+          <xsl:apply-templates select="/article/articleinfo" mode="authorsect"/>
+        </xsl:when>
+      </xsl:choose>
+
+    </xsl:with-param>
+  </xsl:call-template>
+  <!-- Now generate stub include pages for every page documented in
+       this refentry (except the page itself) -->
+  <xsl:for-each select="refnamediv/refname">
+    <xsl:if test=". != $name">
+      <xsl:call-template name="write.text.chunk">
+       <xsl:with-param name="filename"
+                       select="concat(normalize-space(.), '.', $section)"/>
+       <xsl:with-param name="content" select="concat('.so man',
+             $section, '/', $name, '.', $section, '&#10;')"/>
+      </xsl:call-template>
+    </xsl:if>
+  </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="refmeta"></xsl:template>
+<xsl:template match="title"></xsl:template>
+<xsl:template match="abstract"></xsl:template>
+
+<xsl:template match="articleinfo|bookinfo|refentryinfo" mode="authorsect">
+  <xsl:text>.SH AUTHOR</xsl:text>
+  <xsl:if test="count(.//author)>1">
+    <xsl:text>S</xsl:text>
+  </xsl:if>
+  <xsl:text>&#10;</xsl:text>
+
+  <xsl:for-each select=".//author">
+    <xsl:if test="position() > 1">
+      <xsl:text>, </xsl:text>
+    </xsl:if>
+    <xsl:apply-templates select="."/>
+  </xsl:for-each>
+  <xsl:text>.&#10;</xsl:text>
+  <xsl:if test=".//editor">
+    <xsl:text>.br&#10;Man page edited by </xsl:text>
+    <xsl:apply-templates select=".//editor"/>
+    <xsl:text>.&#10;</xsl:text>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="author|editor">
+  <xsl:call-template name="person.name"/>
+  <xsl:apply-templates select="./affiliation/address/email" />
+</xsl:template>
+
+<xsl:template match="copyright">
+  <xsl:text>Copyright </xsl:text>
+  <xsl:apply-templates select="./year" />
+  <xsl:text>&#10;.Sp&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="email">
+  <xsl:text>  &lt;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&gt;</xsl:text>
+</xsl:template>
+
+<xsl:template match="refnamediv">
+  <xsl:text>.SH NAME&#10;</xsl:text>
+  <xsl:for-each select="refname">
+    <xsl:if test="position()>1">
+      <xsl:text>, </xsl:text>
+    </xsl:if>
+    <xsl:value-of select="."/>
+  </xsl:for-each>
+  <xsl:text> \- </xsl:text>
+  <xsl:value-of select="normalize-space (refpurpose)"/>
+</xsl:template>
+
+<xsl:template match="refentry/refentryinfo"></xsl:template>
+
+<xsl:template match="option">
+  <xsl:apply-templates mode="bold" select="."/>
+</xsl:template>
+
+<xsl:template match="replaceable|varname">
+  <xsl:apply-templates mode="italic" select="."/>
+</xsl:template>
+
+<xsl:template match="filename">
+  <xsl:text>&#10;.FN </xsl:text><xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="userinput">
+  <xsl:apply-templates mode="bold" select="."/>
+</xsl:template>
+
+<xsl:template match="informalexample|screen">
+  <xsl:text>&#10;.IP&#10;.nf&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;.fi&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="envar">
+  <xsl:apply-templates mode="bold" select="."/>
+</xsl:template>
+
+<xsl:template match="filename">
+  <xsl:apply-templates mode="italic" select="."/>
+</xsl:template>
+
+<xsl:template match="errorcode|constant|type">
+  <xsl:apply-templates mode="bold" select="."/>
+</xsl:template>
+
+<xsl:template match="quote">
+  <xsl:text>``</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>''</xsl:text>
+</xsl:template>
+
+<xsl:template match="programlisting">
+  <xsl:text>&#10;.nf&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;.fi&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template name="do-citerefentry">
+  <xsl:param name="refentrytitle" select="''"/>
+  <xsl:param name="manvolnum" select="''"/>
+
+  <xsl:apply-templates mode="bold" select="$refentrytitle"/>
+  <xsl:text>(</xsl:text>
+  <xsl:value-of select="$manvolnum"/>
+  <xsl:text>)</xsl:text>
+</xsl:template>
+
+<xsl:template match="citerefentry">
+  <xsl:call-template name="do-citerefentry">
+    <xsl:with-param name="refentrytitle" select="refentrytitle"/>
+    <xsl:with-param name="manvolnum" select="manvolnum"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="ulink">
+  <xsl:variable name="content">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:if test="$content != ''">
+    <xsl:text>: </xsl:text>
+    <xsl:value-of select="$content" />
+  </xsl:if>
+  <xsl:apply-templates mode="italic" select="@url" />
+</xsl:template>
+
+<!-- Translate some entities to textual equivalents. -->
+<xsl:template name="replace-string">
+  <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="replace-string">
+        <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 name="replace-mdash">
+  <xsl:param name="content" select="''"/>
+  <xsl:call-template name="replace-string">
+    <xsl:with-param name="content" select="$content"/>
+    <xsl:with-param name="replace" select="'&#8212;'"/>
+    <xsl:with-param name="with" select="'--'"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="replace-hellip">
+  <xsl:param name="content" select="''"/>
+  <xsl:call-template name="replace-string">
+    <xsl:with-param name="content" select="$content"/>
+    <xsl:with-param name="replace" select="'&#8230;'"/>
+    <xsl:with-param name="with" select="'...'"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="replace-setmn">
+  <xsl:param name="content" select="''"/>
+  <xsl:call-template name="replace-string">
+    <xsl:with-param name="content" select="$content"/>
+    <xsl:with-param name="replace" select="'&#8726;'"/>
+    <xsl:with-param name="with" select="'\\'"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="replace-minus">
+  <xsl:param name="content" select="''"/>
+  <xsl:value-of select="translate($content,'&#8722;','-')"/>
+</xsl:template>
+
+<xsl:template name="replace-backslash">
+  <xsl:param name="content" select="''"/>
+  <xsl:call-template name="replace-string">
+    <xsl:with-param name="content" select="$content"/>
+    <xsl:with-param name="replace" select="'\'"/>
+    <xsl:with-param name="with" select="'\\'"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="replace-entities">
+  <xsl:param name="content" select="''"/>
+  <xsl:call-template name="replace-hellip">
+    <xsl:with-param name="content">
+      <xsl:call-template name="replace-minus">
+        <xsl:with-param name="content">
+          <xsl:call-template name="replace-mdash">
+            <xsl:with-param name="content">
+              <xsl:call-template name="replace-setmn">
+                <xsl:with-param name="content">
+                 <xsl:call-template name="replace-backslash">
+                   <xsl:with-param name="content" select="$content"/>
+                 </xsl:call-template>
+                </xsl:with-param>
+              </xsl:call-template>
+            </xsl:with-param>
+          </xsl:call-template>
+        </xsl:with-param>
+      </xsl:call-template>
+    </xsl:with-param>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="text()">
+  <xsl:call-template name="replace-entities">
+    <xsl:with-param name="content">
+      <xsl:value-of select="."/>
+    </xsl:with-param>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="/">
+  <xsl:choose>
+    <xsl:when test="//refentry">
+      <xsl:apply-templates select="//refentry"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:message>No refentry elements!</xsl:message>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/manpages/lists.xsl b/xsl/manpages/lists.xsl
new file mode 100644 (file)
index 0000000..39f19b9
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version='1.0'?>
+<!-- vim:set sts=2 shiftwidth=2 syntax=sgml: -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'>
+
+<xsl:template match="para|simpara|remark" mode="list">
+  <xsl:variable name="foo">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:value-of select="normalize-space($foo)"/>
+  <xsl:text>&#10;</xsl:text>
+  <xsl:if test="following-sibling::para or following-sibling::simpara or
+               following-sibling::remark">
+    <!-- Make sure multiple paragraphs within a list item don't -->
+    <!-- merge together.                                        -->
+    <xsl:text>&#10;</xsl:text>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="varlistentry|glossentry">
+  <xsl:text>&#10;.TP&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="variablelist|glosslist" mode="list">
+  <xsl:text>&#10;.RS&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;.RE&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="varlistentry/term|glossterm">
+  <xsl:variable name="content">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:value-of select="normalize-space($content)"/>
+  <xsl:text>, </xsl:text>
+</xsl:template>
+
+<xsl:template
+     match="varlistentry/term[position()=last()]|glossterm[position()=last()]"
+     priority="2">
+  <xsl:variable name="content">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:value-of select="normalize-space($content)"/>
+</xsl:template>
+
+<xsl:template match="varlistentry/listitem|glossdef">
+  <xsl:text>&#10;</xsl:text>
+  <xsl:apply-templates mode="list"/>
+</xsl:template>
+
+<xsl:template match="itemizedlist/listitem">
+  <xsl:text>\(bu&#10;</xsl:text>
+  <xsl:apply-templates mode="list"/>
+  <xsl:if test="position()!=last()">
+    <xsl:text>.TP&#10;</xsl:text>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="orderedlist/listitem|procedure/step">
+  <xsl:number format="1."/>
+  <xsl:text>&#10;</xsl:text>
+  <xsl:apply-templates mode="list"/>
+  <xsl:if test="position()!=last()">
+    <xsl:text>.TP&#10;</xsl:text>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="itemizedlist|orderedlist|procedure">
+  <xsl:text>&#10;.TP 3&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>.LP&#10;</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/manpages/sect23.xsl b/xsl/manpages/sect23.xsl
new file mode 100644 (file)
index 0000000..a72514c
--- /dev/null
@@ -0,0 +1,147 @@
+<?xml version='1.0'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'>
+
+<xsl:template match="refsect2">
+  <xsl:text>&#10;.Sh "</xsl:text>
+  <xsl:value-of select="substring-before(title[1],' ')"/>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+<xsl:template match="refsect2/title"></xsl:template>
+<xsl:template match="refsect2/programlisting"></xsl:template>
+
+<xsl:template match="funcsynopsis">
+  <xsl:text>&#10;.BI "</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="funcsynopsis/funcprototype">
+  <xsl:apply-templates/>
+  <xsl:text> );&#10;.br&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="funcsynopsis/funcprototype/funcdef">
+  <xsl:apply-templates/>
+  <xsl:value-of select="function"/>
+  <xsl:text> (</xsl:text>
+</xsl:template>
+<xsl:template match="funcsynopsis/funcprototype/funcdef/function"></xsl:template>
+
+<xsl:template match="funcsynopsis/funcprototype/paramdef">
+  <xsl:apply-templates/>
+  <xsl:text>" </xsl:text>
+  <xsl:value-of select="parameter"/>
+  <xsl:choose>
+  <xsl:when test="following-sibling::paramdef">
+    <xsl:text> ", </xsl:text>
+  </xsl:when>
+  </xsl:choose>
+</xsl:template>
+<xsl:template match="funcsynopsis/funcprototype/paramdef/parameter"></xsl:template>
+
+<xsl:template match="refsect2/informaltable/tgroup/tbody/row">
+  <xsl:text>.Ip "\(bu \s-1</xsl:text>
+  <xsl:value-of select="entry[1]/parameter[1]"/>
+  <xsl:text>\s0 \- </xsl:text>
+  <xsl:value-of select="normalize-space(entry[2])"/>
+  <xsl:text>"&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="refsect1">
+  <xsl:text>&#10;.SH "</xsl:text>
+  <xsl:value-of select="translate(title[1],'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="refsynopsisdiv">
+  <xsl:text>&#10;.SH "</xsl:text>
+  <xsl:value-of select="translate(title[1],'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+<xsl:template match="refsynopsisdiv/title"></xsl:template>
+
+<xsl:template match="refsect1/title"></xsl:template>
+
+<xsl:template match="para">
+     <xsl:text>.PP&#10;</xsl:text>
+     <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="*"><xsl:apply-templates/></xsl:template>
+
+<xsl:template match="refentry">
+  <xsl:text>." DO NOT MODIFY THIS FILE!
+.de Sh \" Subsection
+.br
+.if t .Sp
+.ne 5
+.PP
+\fB\\$1\fR
+.PP
+..
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Ip \" List item
+.br
+.ie \\n(.$>=3 .ne \\$3
+.el .ne 3
+.IP "\\$1" \\$2
+..
+.TH "</xsl:text>
+  <xsl:value-of select="refmeta/refentrytitle[1]"/>
+  <xsl:text>" </xsl:text>
+  <xsl:value-of select="refmeta/manvolnum[1]"/>
+  <xsl:text> "</xsl:text>
+  <xsl:value-of select="@revision"/>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="refmeta"></xsl:template>
+
+<xsl:template match="refnamediv">
+  <xsl:text>.SH NAME&#10;</xsl:text>
+  <xsl:value-of select="refname"/>
+  <xsl:text> \- </xsl:text>
+  <xsl:value-of select="refpurpose"/>
+</xsl:template>
+
+<xsl:template match="refentry/refentrytitle"></xsl:template>
+<xsl:template match="article/articleinfo/*"></xsl:template>
+
+<xsl:template match="term/option">
+  <xsl:text>\fB</xsl:text><xsl:apply-templates/><xsl:text>\fR</xsl:text>
+</xsl:template>
+
+<xsl:template match="varlistentry">
+  <xsl:text>&#10;.TP&#10;</xsl:text>
+<xsl:apply-templates select="./term"/>
+<xsl:apply-templates select="./listitem"/>
+</xsl:template>
+
+<xsl:template match="varlistentry/listitem/para">
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="filename">
+  <xsl:text>&#10;.FN </xsl:text><xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="userinput">
+  <xsl:text>&#10;.IP&#10;.B </xsl:text><xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="envar">
+  <xsl:text>\fB</xsl:text><xsl:apply-templates/><xsl:text>\fR</xsl:text>
+</xsl:template>
+
+<xsl:template match="filename">
+  <xsl:text>\fI</xsl:text><xsl:apply-templates/><xsl:text>\fR</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/manpages/synop.xsl b/xsl/manpages/synop.xsl
new file mode 100644 (file)
index 0000000..0512266
--- /dev/null
@@ -0,0 +1,230 @@
+<?xml version='1.0'?>
+<!-- vim:set sts=2 shiftwidth=2 syntax=sgml: -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'>
+
+<xsl:template match="synopfragment">
+<xsl:text>&#10;.PP&#10;</xsl:text>
+<xsl:apply-templates/>
+</xsl:template>
+<!--
+  there's a bug were an <arg> that's not inside a <group> isn't made bold
+-->
+
+<xsl:template match="group|arg">
+  <xsl:variable name="choice" select="@choice"/>
+  <xsl:variable name="rep" select="@rep"/>
+  <xsl:variable name="sepchar">
+    <xsl:choose>
+      <xsl:when test="ancestor-or-self::*/@sepchar">
+        <xsl:value-of select="ancestor-or-self::*/@sepchar"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:text> </xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:if test="position()>1"><xsl:value-of select="$sepchar"/></xsl:if>
+  <xsl:choose>
+    <xsl:when test="$choice='plain'">
+      <!-- do nothing -->
+    </xsl:when>
+    <xsl:when test="$choice='req'">
+      <xsl:value-of select="$arg.choice.req.open.str"/>
+    </xsl:when>
+    <xsl:when test="$choice='opt'">
+      <xsl:value-of select="$arg.choice.opt.open.str"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$arg.choice.def.open.str"/>
+    </xsl:otherwise>
+  </xsl:choose>
+  <xsl:variable name="arg">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:value-of select="normalize-space($arg)"/>
+  <xsl:choose>
+    <xsl:when test="$rep='repeat'">
+      <xsl:value-of select="$arg.rep.repeat.str"/>
+    </xsl:when>
+    <xsl:when test="$rep='norepeat'">
+      <xsl:value-of select="$arg.rep.norepeat.str"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$arg.rep.def.str"/>
+    </xsl:otherwise>
+  </xsl:choose>
+  <xsl:choose>
+    <xsl:when test="$choice='plain'">
+      <xsl:if test='arg'>
+      <xsl:value-of select="$arg.choice.plain.close.str"/>
+      </xsl:if>
+    </xsl:when>
+    <xsl:when test="$choice='req'">
+      <xsl:value-of select="$arg.choice.req.close.str"/>
+    </xsl:when>
+    <xsl:when test="$choice='opt'">
+      <xsl:value-of select="$arg.choice.opt.close.str"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$arg.choice.def.close.str"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="group/arg">
+  <xsl:if test="position()>1">
+    <xsl:value-of select="$arg.or.sep"/>
+  </xsl:if>
+  <!-- Don't use the 'bold' named template here since there may be -->
+  <!-- child elements that require different markup (such as       -->
+  <!-- <replaceable>).                                             -->
+  <xsl:text>\fB</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>\fR</xsl:text>
+</xsl:template>
+
+<xsl:template match="command">
+  <xsl:apply-templates mode="bold" select="."/>
+</xsl:template>
+
+<xsl:template match="function[not(ancestor::command)]">
+  <xsl:apply-templates mode="bold" select="."/>
+</xsl:template>
+
+<xsl:template match="parameter[not(ancestor::command)]">
+  <xsl:apply-templates mode="italic" select="."/>
+</xsl:template>
+
+<xsl:template match="sbr">
+  <xsl:variable name="cmd" select="ancestor::cmdsynopsis/command"/>
+  <xsl:text>&#10;</xsl:text>
+  <xsl:value-of select="translate($cmd,$cmd,'                        ')"/>
+</xsl:template>
+
+<xsl:template name="wrap-cmd">
+  <xsl:param name="indent" select="''"/>
+  <xsl:param name="text" select="''"/>
+  <xsl:param name="allow" select="75"/>
+  <xsl:param name="width" select="$allow - string-length($indent)"/>
+  <xsl:variable name="total" select="string-length($text)"/>
+  <xsl:variable name="split"
+                select="substring($text,$width+1,$total - $width)"/>
+  <xsl:variable name="fragment" select="substring-before($split,' ')"/>
+  <xsl:variable name="line">
+    <xsl:value-of select="substring($text,1,$width)"/>
+    <xsl:choose>
+      <xsl:when test="$fragment!=''">
+        <xsl:value-of select="$fragment"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$split"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:choose>
+    <xsl:when test="$split=''">
+      <xsl:value-of select="$line"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$line"/>
+      <xsl:text>&#10;</xsl:text>
+      <xsl:value-of select="$indent"/>
+      <xsl:variable name="done" select="string-length($line)"/>
+      <xsl:variable name="remaining" select="$total - $done + 1"/>
+      <xsl:call-template name="wrap-cmd">
+        <xsl:with-param name="indent" select="$indent"/>
+        <xsl:with-param name="text"
+                        select="substring($text,1+$done,$remaining)"/>
+      </xsl:call-template>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="cmdsynopsis">
+  <xsl:text>&#10;.nf&#10;</xsl:text>
+  <xsl:choose>
+    <xsl:when test=".//sbr">
+      <!-- The author has put explicit formatting hints in for us. -->
+      <xsl:apply-templates/>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- Try to do some smart formatting. -->
+      <xsl:variable name="cmdsynopsis">
+        <xsl:apply-templates/>
+      </xsl:variable>
+      <xsl:variable name="cmd" select="command"/>
+      <xsl:variable name="indent"
+                    select="translate($cmd,$cmd,'                         ')"/>
+      <xsl:text>\fB</xsl:text>
+      <xsl:value-of select="$cmd"/><xsl:text>\fR </xsl:text>
+      <xsl:call-template name="wrap-cmd">
+        <xsl:with-param name="indent" select="$indent"/>
+        <xsl:with-param name="text" select="substring-after($cmdsynopsis,' ')"/>
+      </xsl:call-template>
+    </xsl:otherwise>
+  </xsl:choose>
+  <xsl:text>&#10;.fi&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="synopsis">
+  <xsl:text>&#10;.nf&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;.fi&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="void">
+  <xsl:text> (void</xsl:text>
+</xsl:template>
+
+<xsl:template match="varargs">
+  <xsl:text> (...</xsl:text>
+</xsl:template>
+
+<xsl:template match="funcsynopsisinfo">
+  <xsl:text>&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;.sp&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="funcsynopsis">
+  <xsl:text>.nf&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>.fi&#10;</xsl:text>
+</xsl:template>
+
+<!-- TODO: Handle K&R-style parameter lists
+           Comment that used to go with the paramdef template, which
+          is now obsolete and thus deleted
+-->
+
+<xsl:template match="funcprototype">
+  <xsl:variable name="funcprototype">
+    <xsl:apply-templates select="funcdef"/>
+  </xsl:variable>
+  <xsl:text>.sp&#10;</xsl:text>
+  <xsl:value-of select="normalize-space ($funcprototype)"/>
+  <xsl:text> (</xsl:text>
+  <xsl:for-each select="paramdef">
+    <xsl:variable name="param">
+      <xsl:apply-templates select="." />
+    </xsl:variable>
+    <xsl:value-of select="normalize-space ($param)" />
+    <xsl:choose>
+      <xsl:when test="following-sibling::paramdef">
+       <xsl:text>,&#10;</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+       <xsl:text>);&#10;.RE&#10;</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+    <xsl:if test="not (preceding-sibling::paramdef)">
+      <xsl:text>.RS </xsl:text>
+      <xsl:value-of
+       select="string-length(normalize-space ($funcprototype)) - 4" />
+      <xsl:text>&#10;</xsl:text>
+    </xsl:if>
+  </xsl:for-each>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/manpages/xref.xsl b/xsl/manpages/xref.xsl
new file mode 100644 (file)
index 0000000..ccf8d65
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version='1.0'?>
+<!-- vim:set sts=2 shiftwidth=2 syntax=sgml: -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'>
+
+<xsl:template match="xref">
+  <xsl:variable name="targets" select="id(@linkend)"/>
+  <xsl:variable name="target" select="$targets[1]"/>
+  <xsl:variable name="type" select="local-name($target)"/>
+
+  <xsl:choose>
+    <xsl:when test="$type=''">
+      <xsl:message>
+        <xsl:text>xref to nonexistent id </xsl:text>
+        <xsl:value-of select="@linkend"/>
+      </xsl:message>
+    </xsl:when>
+
+    <xsl:when test="$type='refentry'">
+      <xsl:call-template name="do-citerefentry">
+        <xsl:with-param name="refentrytitle"
+                        select="$target/refmeta/refentrytitle[1]"/>
+        <xsl:with-param name="manvolnum"
+                       select="$target/refmeta/manvolnum"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="$type='refname'">
+      <xsl:call-template name="do-citerefentry">
+        <xsl:with-param name="refentrytitle" select="$target"/>
+        <xsl:with-param name="manvolnum"
+          select="$target/../../refmeta/manvolnum"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:text>[xref to </xsl:text>
+      <xsl:value-of select="$type"/>
+      <xsl:text>]</xsl:text>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>