summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/stylesheet-man.xsl
blob: fcb485c29319d6a5205ccafbf1a27b11c53615e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                version='1.0'
                exclude-result-prefixes="exsl">

<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"/>
<xsl:import href="stylesheet-common.xsl" />


<!-- Parameters -->

<xsl:param name="man.authors.section.enabled">0</xsl:param>
<xsl:param name="man.copyright.section.enabled">0</xsl:param>
<xsl:param name="man.endnotes.are.numbered">0</xsl:param> <!-- for performance -->
<xsl:param name="man.output.base.dir"></xsl:param>
<xsl:param name="man.output.in.separate.dir" select="1"></xsl:param>
<xsl:param name="man.output.quietly" select="1"></xsl:param>
<xsl:param name="man.th.title.max.length">32</xsl:param> <!-- enough room for "CREATE TEXT SEARCH CONFIGURATION" -->
<xsl:param name="man.th.extra3.max.length">40</xsl:param> <!-- enough room for "PostgreSQL X.Ydevel Documentation" -->
<xsl:param name="refentry.meta.get.quietly" select="0"></xsl:param>
<xsl:param name="refentry.xref.manvolnum" select="1"/> <!-- overridden from stylesheet-common.xsl -->

<!-- Fixup for apostrophe groff output.  See the following references:
     <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=457839>
     <https://sourceforge.net/tracker/?func=detail&aid=2412738&group_id=21935&atid=373747>
 -->
<xsl:param name="man.string.subst.map.local.post">
  <substitution oldstring="\'" newstring="\(aq"></substitution>
</xsl:param>


<!-- Custom templates -->

<!-- Improve output of email element.  See also
     <https://sourceforge.net/tracker/?func=detail&aid=3524417&group_id=21935&atid=373747>
 -->
<xsl:template match="email">
  <xsl:text>&lt;</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>&gt;</xsl:text>
</xsl:template>


<!-- Make superscripts visible in man pages (default is no decoration) -->
<xsl:template match="superscript">
  <xsl:text>^</xsl:text>
  <xsl:apply-templates/>
</xsl:template>


<xsl:template match="refentry" mode="xref-to">
  <xsl:param name="referrer"/>
  <xsl:param name="xrefstyle"/>

  <xsl:choose>
    <!-- If the refname contains a space, we construct a reference
         like CREATE DATABASE (CREATE_DATABASE(7)), so the reader
         knows both the command name being referred to and the name of
         the man page to read about it. -->
    <xsl:when test="contains(refnamediv/refname[1],' ')">
      <xsl:variable name="mangled.title">
        <xsl:value-of select="translate(refnamediv/refname[1],' ','_')"/>
      </xsl:variable>
      <xsl:apply-templates select="refnamediv/refname[1]"/>
      <xsl:text> (</xsl:text>
      <xsl:call-template name="bold">
        <xsl:with-param name="node" select="exsl:node-set($mangled.title)"/>
        <xsl:with-param name="context" select="."/>
      </xsl:call-template>
      <xsl:apply-templates select="refmeta/manvolnum"/>
      <xsl:text>)</xsl:text>
    </xsl:when>

    <!-- This is the original case, except that boldness has been
         added, per the convention mentioned in man-pages(7). -->
    <xsl:otherwise>
      <xsl:choose>
        <xsl:when test="refmeta/refentrytitle">
          <xsl:call-template name="bold">
            <xsl:with-param name="node" select="refmeta/refentrytitle"/>
            <xsl:with-param name="context" select="."/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="bold">
            <xsl:with-param name="node" select="refnamediv/refname[1]"/>
            <xsl:with-param name="context" select="."/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="refmeta/manvolnum"/>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>


<!-- For refentries we don't man to generate a man page for, leave out
     manvolnum, let it default to 0, and skip writing out man files
     with section 0. -->

<!-- overridden from common/refentry.xsl -->
<xsl:template name="get.refentry.section">
  <xsl:choose>
    <xsl:when test="refmeta/manvolnum">
      <xsl:value-of select="refmeta/manvolnum"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>0</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- overridden from manpages/other.xsl -->
  <xsl:template name="write.man.file">
    <xsl:param name="name"/>
    <xsl:param name="section"/>
    <xsl:param name="lang"/>
    <xsl:param name="content"/>
    <xsl:param name="filename">
      <xsl:call-template name="make.adjusted.man.filename">
        <xsl:with-param name="name" select="$name"/>
        <xsl:with-param name="section" select="$section"/>
        <xsl:with-param name="lang" select="$lang"/>
      </xsl:call-template>
    </xsl:param>
    <xsl:if test="$section != 0">
    <xsl:call-template name="write.text.chunk">
      <xsl:with-param name="filename" select="$filename"/>
      <xsl:with-param name="suppress-context-node-name" select="1"/>
      <xsl:with-param name="quiet" select="$man.output.quietly"/>
      <xsl:with-param
          name="message-prolog"
          >Note: </xsl:with-param>
      <xsl:with-param name="encoding" select="$man.output.encoding"/>
      <xsl:with-param name="content" select="$content"/>
    </xsl:call-template>
    </xsl:if>
  </xsl:template>


<!-- Overridden template as workaround for this problem:
     <https://sourceforge.net/tracker/?func=detail&aid=2831602&group_id=21935&atid=373747>
-->
  <xsl:template name="write.stubs">
    <xsl:param name="first.refname"/>
    <xsl:param name="section"/>
    <xsl:param name="lang"/>
    <xsl:for-each select="refnamediv/refname">
      <xsl:if test=". != $first.refname">
        <xsl:call-template name="write.text.chunk">
          <xsl:with-param name="filename">
            <xsl:call-template name="make.adjusted.man.filename">
              <xsl:with-param name="name" select="."/>
              <xsl:with-param name="section" select="$section"/>
              <xsl:with-param name="lang" select="$lang"/>
            </xsl:call-template>
          </xsl:with-param>
          <xsl:with-param name="quiet" select="$man.output.quietly"/>
          <xsl:with-param name="suppress-context-node-name" select="1"/>
          <xsl:with-param name="message-prolog">Note: </xsl:with-param>
          <xsl:with-param name="message-epilog"> (soelim stub)</xsl:with-param>
          <xsl:with-param name="content">
            <xsl:choose>
              <xsl:when test="$man.output.in.separate.dir = 0">
                <xsl:value-of select="concat('.so man', $section, '/')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="'.so '"/> <!-- added case -->
              </xsl:otherwise>
            </xsl:choose>
            <xsl:call-template name="make.adjusted.man.filename">
              <xsl:with-param name="name" select="$first.refname"/>
              <xsl:with-param name="section" select="$section"/>
            </xsl:call-template>
            <xsl:text>&#10;</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>


  <!-- https://sourceforge.net/tracker/?func=detail&aid=3545150&group_id=21935&atid=373747 -->
  <xsl:template match="step/title">
    <xsl:apply-templates/>
    <xsl:text>: </xsl:text>
  </xsl:template>


  <!-- http://sourceforge.net/p/docbook/bugs/1340/ -->
  <xsl:template match="indexterm"/>


<!-- https://github.com/docbook/xslt10-stylesheets/issues/59 -->
<xsl:template match="a/sup">
  <xsl:apply-templates/>
</xsl:template>


<!-- Gentext customization -->

<!-- see http://www.sagehill.net/docbookxsl/CustomGentext.html -->
<xsl:param name="local.l10n.xml" select="document('')"/>
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
  <l:l10n language="en">
    <!-- Use ISO 8601 date format. -->
    <l:context name="datetime">
      <l:template name="format" text="Y-m-d"/>
    </l:context>

    <!-- Slight rephrasing to indicate that missing sections are found
         in the documentation. -->
    <l:context name="xref-number-and-title">
      <l:template name="chapter" text="Chapter %n, %t, in the documentation"/>
      <l:template name="sect1" text="Section %n, “%t”, in the documentation"/>
      <l:template name="sect2" text="Section %n, “%t”, in the documentation"/>
      <l:template name="sect3" text="Section %n, “%t”, in the documentation"/>
      <l:template name="sect4" text="Section %n, “%t”, in the documentation"/>
      <l:template name="sect5" text="Section %n, “%t”, in the documentation"/>
    </l:context>
  </l:l10n>
</l:i18n>

</xsl:stylesheet>