summaryrefslogtreecommitdiff
path: root/docs/xsl-generic/manpages/refentry.xsl
blob: 9cb7005f9953b9083b76b84e163b81779b5b01e5 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>

<!-- ********************************************************************
     $Id: refentry.xsl 6657 2007-02-26 20:04:25Z xmldoc $
     ********************************************************************

     This file is part of the XSL DocBook Stylesheet distribution.
     See ../README or http://docbook.sf.net/release/xsl/current/ for
     copyright and other information.

     ******************************************************************** -->

<!-- ==================================================================== -->

  <xsl:template match="refnamediv">
    <xsl:choose>
      <xsl:when test="preceding-sibling::refnamediv">
        <!-- * No title on secondary refnamedivs! -->
        <!-- * Just put a single line break instead -->
        <xsl:text>.br&#10;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="mark.subheading"/>
        <xsl:text>.SH "</xsl:text>
        <xsl:apply-templates select="." mode="title.markup"/>
        <xsl:text>"</xsl:text>
        <xsl:text>&#10;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:call-template name="mark.subheading"/>
    <!-- * if we have multiple Refname instances, separate the names -->
    <!-- * with commas -->
    <xsl:for-each select="refname">
      <xsl:if test="position()>1">
        <xsl:text>, </xsl:text>
      </xsl:if>
      <xsl:value-of select="."/>
    </xsl:for-each>
    <!-- * The man(7) man pages says: -->
    <!-- * -->
    <!-- *   The only required heading is NAME, which should be the -->
    <!-- *   first section and be followed on the next line by a one -->
    <!-- *   line description of the program: -->
    <!-- * -->
    <!-- *      .SH NAME chess \- the game of chess -->
    <!-- * -->
    <!-- *   It is extremely important that this format is followed, -->
    <!-- *   and that there is a backslash before the single dash -->
    <!-- *   which follows the command name.  This syntax is used by -->
    <!-- *   the makewhatis(8) program to create a database of short -->
    <!-- *   command descriptions for the whatis(1) and apropos(1) -->
    <!-- *   commands. -->
    <!-- * -->
    <!-- * So why don't we precede the hyphen with a backslash here? -->
    <!-- * Well, because it's added later, by the apply-string-subst-map -->
    <!-- * template, before we generate final output -->
    <xsl:if test="refpurpose/node()">
      <xsl:text> - </xsl:text>
      <xsl:value-of select="normalize-space(refpurpose)"/>
    </xsl:if>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="refsynopsisdiv">
    <xsl:call-template name="mark.subheading"/>
    <xsl:text>.SH "</xsl:text>
    <xsl:apply-templates select="." mode="title.markup"/>
    <xsl:text>"&#10;</xsl:text>
    <xsl:call-template name="mark.subheading"/>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="refsect1|refentry/refsection">
    <xsl:variable name="title">
      <xsl:apply-templates select="." mode="title.markup"/>
    </xsl:variable>
    <xsl:call-template name="mark.subheading"/>
    <xsl:text>.SH "</xsl:text>
    <xsl:value-of select="normalize-space($title)"/>
    <xsl:text>"&#10;</xsl:text>
    <xsl:call-template name="mark.subheading"/>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="refsect2|refentry/refsection/refsection">
    <xsl:call-template name="mark.subheading"/>
    <xsl:variable name="title">
      <xsl:apply-templates
          select="(info/title
                  |refsectioninfo/title
                  |refsect1info/title
                  |title)[1]/node()"/>
      
    </xsl:variable>
    <xsl:text>.SS "</xsl:text>
    <xsl:value-of select="normalize-space($title)"/>
    <xsl:text>"&#10;</xsl:text>
    <xsl:call-template name="mark.subheading"/>
    <xsl:choose>
      <!-- * If default-indentation adjustment is on, then indent the -->
      <!-- * child content of this Refsect2 -->
      <xsl:when test="not($man.indent.refsect = 0)">
        <xsl:text>.RS&#10;</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>.RE&#10;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <!-- * If default-indentation adjustment is on, then do not -->
        <!-- * indent the child content of thie Refsect2, because -->
        <!-- * the title is already "sticking out to the left" -->
        <!-- * (as the groff_man(7) man page describes it), which -->
        <!-- * actually means the title is indented by the value of -->
        <!-- * the SN register, which appears by default to be -->
        <!-- * about half of the default indentation value -->
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="refsect3|refentry/refsection/refsection/refsection">
    <xsl:variable name="title">
      <xsl:value-of select="(info/title
                            |refsectioninfo/title
                            |refsect1info/title
                            |title)[1]"/>
    </xsl:variable>
    <xsl:choose>
      <!-- * If default-indentation adjustment is on, then indent the -->
      <!-- * child content of this Refsect3 or Refsection. -->
      <xsl:when test="not($man.indent.refsect != 0)">
        <xsl:call-template name="nested-section-title"/>
        <xsl:text>.RS&#10;</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>.RE&#10;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <!-- * If default-indentation adjustment is on, then do not -->
        <!-- * indent the child content of thie Refsect2, because -->
        <!-- * the title is already "sticking out to the left" -->
        <!-- * (as the groff_man(7) man page describes it), which -->
        <!-- * actually means the title is indented by the value of -->
        <!-- * the SN register, which appears by default to be -->
        <!-- * about half of the default indentation value -->
        <xsl:text>.ti (\n(SNu * 5u / 3u)&#10;</xsl:text>
        <xsl:call-template name="nested-section-title"/>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="refsection">
    <!-- * This template is used for a nested Refsection that is -->
    <!-- * is a child of a Refsect3-level section (The numberd -->
    <!-- * Refsect hierarchy in DocBook ends with Refsect3, so -->
    <!-- * there is not actually a Refsect4 element.) -->
    <xsl:variable name="title">
      <xsl:value-of select="(info/title
                            |refsectioninfo/title
                            |refsect1info/title
                            |title)[1]"/>
    </xsl:variable>
    <xsl:variable name="indent-width">
      <xsl:if test="not($man.indent.refsect = 0)">
        <!-- * If default-indentation adjustment is on, then indent the -->
        <!-- * child content of this Refsect3 or Refsection. -->
        <xsl:text>(\n(SNu)&#10;</xsl:text>
      </xsl:if>
    </xsl:variable>
    <xsl:call-template name="nested-section-title"/>
    <xsl:text>.RS (\n(SNu)&#10;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>.RE&#10;</xsl:text>
  </xsl:template>

  <!-- ==================================================================== -->

  <!-- * Use uppercase to render titles of all instances of Refsect1 or -->
  <!-- * top-level Refsection, including in cross-references -->
  <xsl:template match="refsect1|refentry/refsection"
                mode="title.markup">
    <xsl:variable name="title" select="(info/title
                                       |refsectioninfo/title
                                       |refsect1info/title
                                       |title)[1]"/>
    <xsl:call-template name="string.upper">
      <xsl:with-param name="string">
        <xsl:apply-templates select="$title" mode="title.markup"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- * Output of Titles from Xref with Endterm needs to be handled -->
  <!-- * separately from output for Endterm-less Xref -->
  <xsl:template match="refsect1/title
                       |refentry/refsection/title
                       |refsynopsisdiv/title"
                mode="endterm">
    <xsl:call-template name="string.upper">
      <xsl:with-param name="string">
        <xsl:apply-templates/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- * Use uppercase to render titles of all instances of Refsynopsisdiv, -->
  <!-- * including in cross-references -->
  <xsl:template match="refsynopsisdiv" mode="title.markup">
    <xsl:param name="allow-anchors" select="0"/>
    <xsl:call-template name="string.upper">
      <xsl:with-param name="string">
        <xsl:choose>
          <xsl:when test="info/title
                          |refsynopsisdivinfo/title
                          |title">
            <xsl:apply-templates
                select="(info/title
                        |refsynopsisdivinfo/title
                        |title)[1]" mode="title.markup">
              <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="gentext">
              <xsl:with-param name="key" select="'RefSynopsisDiv'"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- * Use uppercase to render titles of all instances of Refnamediv, -->
  <!-- * including in cross-references -->
  <xsl:template match="refnamediv" mode="title.markup">
    <xsl:call-template name="string.upper">
      <xsl:with-param name="string">
        <xsl:call-template name="gentext">
          <xsl:with-param name="key" select="'RefName'"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="refnamediv" mode="xref-to">
    <xsl:apply-templates select="." mode="title.markup"/>
  </xsl:template>

  <!-- ==================================================================== -->

  <!-- * suppress any title we don't otherwise process elsewhere -->

  <xsl:template match="title"/>

</xsl:stylesheet>