Debian Codegraph @

docs/xsl-generic/manpages/utility.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:exsl="http://exslt.org/common"
4 xmlns:dyn="http://exslt.org/dynamic"
5 xmlns:saxon="http://icl.com/saxon"
6 exclude-result-prefixes="exsl dyn saxon"
7 version='1.0'>
8
9 <!-- ********************************************************************
10 $Id: utility.xsl 6843 2007-06-20 12:21:13Z xmldoc $
11 ********************************************************************
12
13 This file is part of the XSL DocBook Stylesheet distribution.
14 See ../README or http://docbook.sf.net/release/xsl/current/ for
15 copyright and other information.
16
17 ******************************************************************** -->
18
19 <!-- ==================================================================== -->
20
21 <!-- * This file contains "utility" templates that are called multiple -->
22 <!-- * times per each Refentry. -->
23
24 <!-- ==================================================================== -->
25
26 <!-- * NOTE TO DEVELOPERS: For ease of maintenance, the current -->
27 <!-- * manpages stylesheets use the "bold" and "italic" named -->
28 <!-- * templates for anything and everything that needs to get -->
29 <!-- * boldfaced or italicized. -->
30 <!-- * -->
31 <!-- * So if you add anything that needs bold or italic character -->
32 <!-- * formatting, try to apply these templates to it rather than -->
33 <!-- * writing separate code to format it. This can be a little odd if -->
34 <!-- * the content you want to format is not element content; in those -->
35 <!-- * cases, you need to turn it into element content before applying -->
36 <!-- * the template; see examples of this in the existing code. -->
37
38 <xsl:template name="bold">
39 <xsl:param name="node"/>
40 <xsl:param name="context"/>
41 <xsl:choose>
42 <xsl:when test="not($context[ancestor::title])">
43 <xsl:for-each select="$node/node()">
44 <xsl:text>\fB</xsl:text>
45 <xsl:apply-templates select="."/>
46 <xsl:text>\fR</xsl:text>
47 </xsl:for-each>
48 </xsl:when>
49 <xsl:otherwise>
50 <xsl:apply-templates select="$node/node()"/>
51 </xsl:otherwise>
52 </xsl:choose>
53 </xsl:template>
54
55 <xsl:template name="italic">
56 <xsl:param name="node"/>
57 <xsl:param name="context"/>
58 <xsl:for-each select="$node/node()">
59 <xsl:text>\fI</xsl:text>
60 <xsl:apply-templates select="."/>
61 <xsl:text>\fR</xsl:text>
62 </xsl:for-each>
63 </xsl:template>
64
65 <!-- ================================================================== -->
66
67 <!-- * NOTE TO DEVELOPERS: For ease of maintenance, the current -->
68 <!-- * manpages stylesheets use the mode="prevent.line.breaking" -->
69 <!-- * templates for anything and everything that needs to have -->
70 <!-- * embedded spaces turned into no-break spaces in output - in -->
71 <!-- * order to prevent that output from getting broken across lines -->
72 <!-- * -->
73 <!-- * So if you add anything that whose output, try to apply this -->
74 <!-- * template to it rather than writing separate code to format -->
75 <!-- * it. This can be a little odd if the content you want to -->
76 <!-- * format is not element content; in those cases, you need to -->
77 <!-- * turn it into element content before applying the template; -->
78 <!-- * see examples of this in the existing code. -->
79 <!-- * -->
80 <!-- * This template is currently called by the funcdef and paramdef -->
81 <!-- * and group/arg templates. -->
82 <xsl:template mode="prevent.line.breaking" match="*">
83 <xsl:variable name="rcontent">
84 <xsl:apply-templates/>
85 </xsl:variable>
86 <xsl:variable name="content">
87 <xsl:value-of select="normalize-space($rcontent)"/>
88 </xsl:variable>
89 <xsl:call-template name="string.subst">
90 <xsl:with-param name="string" select="$content"/>
91 <xsl:with-param name="target" select="' '"/>
92 <!-- * U+2580 is a "UPPER HALF BLOCK"; we use it here because -->
93 <!-- * if we were to just use a normal space, it would get -->
94 <!-- * replaced when normalization is done. We replace it -->
95 <!-- * later with the groff markup for non-breaking space. -->
96 <xsl:with-param name="replacement" select="'&#x2580;'"/>
97 </xsl:call-template>
98 </xsl:template>
99
100 <!-- ================================================================== -->
101
102 <xsl:template name="suppress.hyphenation">
103 <!-- * we need to suppress hyphenation inline only if hyphenation is -->
104 <!-- * actually on, and even then only outside of Cmdsynopsis and -->
105 <!-- * Funcsynopsis, where it is already always turned off -->
106 <xsl:if test="$man.hyphenate != 0 and
107 not(ancestor::cmdsynopsis) and
108 not(ancestor::funcsynopsis)">
109 <xsl:text>\%</xsl:text>
110 </xsl:if>
111 </xsl:template>
112
113 <!-- ================================================================== -->
114
115 <!-- * The replace.dots.and.dashes template is used to cause real -->
116 <!-- * dots and dashes to be output in the top comment (instead of -->
117 <!-- * escaped ones as in the source for the text displayed in the -->
118 <!-- * body of the page) -->
119 <xsl:template name="replace.dots.and.dashes">
120 <xsl:param name="content">
121 <xsl:apply-templates/>
122 </xsl:param>
123 <xsl:variable name="dot-content">
124 <xsl:call-template name="string.subst">
125 <xsl:with-param name="string" select="$content"/>
126 <xsl:with-param name="target" select="'\.'"/>
127 <xsl:with-param name="replacement" select="'.'"/>
128 </xsl:call-template>
129 </xsl:variable>
130 <xsl:call-template name="string.subst">
131 <xsl:with-param name="string" select="$dot-content"/>
132 <xsl:with-param name="target" select="'\-'"/>
133 <xsl:with-param name="replacement" select="'-'"/>
134 </xsl:call-template>
135 </xsl:template>
136
137 <!-- ================================================================== -->
138
139 <!-- * The nested-section-title template is called for refsect3, and any -->
140 <!-- * refsection nested more than 2 levels deep. -->
141 <xsl:template name="nested-section-title">
142 <!-- * The next few lines are some arcane roff code to control line -->
143 <!-- * spacing after headings. -->
144 <xsl:text>.sp&#10;</xsl:text>
145 <xsl:text>.it 1 an-trap&#10;</xsl:text>
146 <xsl:text>.nr an-no-space-flag 1&#10;</xsl:text>
147 <xsl:text>.nr an-break-flag 1&#10;</xsl:text>
148 <xsl:text>.br&#10;</xsl:text>
149 <!-- * make title wrapper so that we can use mode="bold" template to -->
150 <!-- * apply character formatting to it -->
151 <xsl:variable name="title.wrapper">
152 <bold><xsl:choose>
153 <xsl:when test="title">
154 <xsl:value-of select="normalize-space(title[1])"/>
155 </xsl:when>
156 <xsl:otherwise>
157 <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
158 </xsl:otherwise>
159 </xsl:choose></bold>
160 </xsl:variable>
161 <xsl:call-template name="mark.subheading"/>
162 <xsl:apply-templates mode="bold" select="exsl:node-set($title.wrapper)"/>
163 <xsl:text>&#10;</xsl:text>
164 <xsl:call-template name="mark.subheading"/>
165 </xsl:template>
166
167 <!-- ================================================================== -->
168
169 <!-- * The mixed-block template jumps through a few hoops to deal with -->
170 <!-- * mixed-content blocks, so that we don't end up munging verbatim -->
171 <!-- * environments or lists and so that we don't gobble up whitespace -->
172 <!-- * when we shouldn't -->
173 <xsl:template name="mixed-block">
174 <xsl:for-each select="node()">
175 <xsl:choose>
176 <!-- * Check to see if this node is a verbatim environment. -->
177 <!-- * If so, put a line of space before it. -->
178 <!-- * -->
179 <!-- * Yes, address and synopsis are vertabim environments. -->
180 <!-- * -->
181 <!-- * The code here previously also treated informaltable as a -->
182 <!-- * verbatim, presumably to support some kludge; I removed it -->
183 <xsl:when test="self::address|self::literallayout|self::programlisting|
184 self::screen|self::synopsis">
185 <xsl:text>&#10;</xsl:text>
186 <xsl:text>.sp&#10;</xsl:text>
187 <xsl:call-template name="mark.up.block.start"/>
188 <xsl:apply-templates select="."/>
189 </xsl:when>
190 <!-- * Check to see if this node is a list; if it is, we don't -->
191 <!-- * want to normalize-space(), so we just apply-templates. -->
192 <!-- * Do same for all admonitions -->
193 <xsl:when test="(self::itemizedlist|self::orderedlist|
194 self::variablelist|self::glosslist|
195 self::simplelist[@type !='inline']|
196 self::segmentedlist|
197 self::caution|self::important|
198 self::note|self::tip|self::warning|
199 self::table|self::informaltable)">
200 <xsl:call-template name="mark.up.block.start"/>
201 <xsl:apply-templates select="."/>
202 </xsl:when>
203 <xsl:when test="self::text()">
204 <!-- * Check to see if this is a text node. -->
205 <!-- * -->
206 <!-- * If so, replace all whitespace at the beginning or end of it -->
207 <!-- * with a single linebreak. -->
208 <!-- * -->
209 <xsl:variable name="content">
210 <xsl:apply-templates select="."/>
211 </xsl:variable>
212 <xsl:if
213 test="starts-with(translate(.,'&#9;&#10;&#13; ',' '), ' ')
214 and preceding-sibling::node()[1][name(.)!='']
215 and normalize-space($content) != ''
216 and not(
217 preceding-sibling::*[1][
218 self::caution or
219 self::important or
220 self::note or
221 self::tip or
222 self::warning or
223 self::variablelist or
224 self::glosslist or
225 self::itemizedlist or
226 self::orderedlist or
227 self::segmentedlist or
228 self::procedure or
229 self::address or
230 self::literallayout or
231 self::programlisting or
232 self::screen or
233 self::table or
234 self::informaltable
235 ]
236 )
237 ">
238 <xsl:text>&#10;</xsl:text>
239 </xsl:if>
240 <xsl:value-of select="normalize-space($content)"/>
241 <xsl:if
242 test="(translate(substring(., string-length(.), 1),'&#9;&#10;&#13; ',' ') = ' '
243 and following-sibling::node()[1][name(.)!=''])
244 or following-sibling::node()[1][self::comment()]
245 or following-sibling::node()[1][self::processing-instruction()]
246 ">
247 <xsl:if test="normalize-space($content) != ''
248 or concat(normalize-space($content), ' ') = ' '">
249 <xsl:text>&#10;</xsl:text>
250 </xsl:if>
251 </xsl:if>
252 </xsl:when>
253 <xsl:otherwise>
254 <!-- * At this point, we know that this node is not a verbatim -->
255 <!-- * environment, list, admonition, or text node; so we can -->
256 <!-- * safely normalize-space() it. -->
257 <xsl:variable name="content">
258 <xsl:apply-templates select="."/>
259 </xsl:variable>
260 <xsl:value-of select="normalize-space($content)"/>
261 </xsl:otherwise>
262 </xsl:choose>
263 </xsl:for-each>
264 <xsl:call-template name="mark.up.block.end"/>
265 </xsl:template>
266
267 <!-- ================================================================== -->
268
269 <!-- * Footnote and annotation contents are displayed using a hanging -->
270 <!-- * indent out to $man.indent.width If a paragraph-level block -->
271 <!-- * element (verbatim, list, or admonition) is the first block -->
272 <!-- * element nested at its same level within the same footnote or -->
273 <!-- * annotation, then we push it over by the same indent width. -->
274 <!-- * -->
275 <!-- * We don't reset the indent for each following sibling, but -->
276 <!-- * instead do it after for-eaching over all block siblings at -->
277 <!-- * the same level. So the effect is that if there are any -->
278 <!-- * following-sibling blocks after the block that starts this -->
279 <!-- * indent, then they just retain the indent that was already set -->
280
281 <xsl:template name="mark.up.block.start">
282 <xsl:choose>
283 <xsl:when test="(ancestor::footnote
284 or ancestor::annotation)">
285 <xsl:if test="not(preceding-sibling::address|
286 preceding-sibling::literallayout|
287 preceding-sibling::programlisting|
288 preceding-sibling::screen|
289 preceding-sibling::synopsis|
290 preceding-sibling::itemizedlist|
291 preceding-sibling::orderedlist|
292 preceding-sibling::variablelist|
293 preceding-sibling::glosslist|
294 preceding-sibling::simplelist[@type !='inline']|
295 preceding-sibling::segmentedlist|
296 preceding-sibling::caution|
297 preceding-sibling::important|
298 preceding-sibling::note|
299 preceding-sibling::tip|
300 preceding-sibling::warning|
301 preceding-sibling::table|
302 preceding-sibling::informaltable
303 )">
304 <xsl:text>.RS</xsl:text>
305 <xsl:if test="not($list-indent = '')">
306 <xsl:text> </xsl:text>
307 <xsl:value-of select="$list-indent"/>
308 </xsl:if>
309 <xsl:text>&#10;</xsl:text>
310 </xsl:if>
311 </xsl:when>
312 </xsl:choose>
313 </xsl:template>
314
315 <!-- * Check to see if we were called from a block within a footnote or -->
316 <!-- * annotation; if so, and the block contains any nested block -->
317 <!-- * content, then we know the mark.up.block.end template was already -->
318 <!-- * called to generate a .RS macro to indent that nested block -->
319 <!-- * content; so we need to generate a .RE to set the margin back to -->
320 <!-- * where it was prior to the .RS call. -->
321 <xsl:template name="mark.up.block.end">
322 <xsl:if test="(ancestor::footnote
323 or ancestor::annotation)">
324 <xsl:if test="address|
325 literallayout|
326 programlisting|
327 screen|
328 synopsis|
329 itemizedlist|
330 orderedlist|
331 variablelist|
332 glosslist|
333 simplelist[@type !='inline']|
334 segmentedlist|
335 caution|
336 important|
337 note|
338 tip|
339 warning|
340 table|
341 informaltable">
342 <xsl:text>&#10;</xsl:text>
343 <xsl:text>.RE</xsl:text>
344 <xsl:text>&#10;</xsl:text>
345 </xsl:if>
346 </xsl:if>
347 </xsl:template>
348
349 <!-- ================================================================== -->
350
351 <!-- * The person.name template in the HTML stylesheets outputs extra -->
352 <!-- * spaces that we need to strip out for manpages output. This -->
353 <!-- * template calls person.name, then tries to do some smart -->
354 <!-- * normalization of the result tree fragment from that. -->
355 <xsl:template name="person.name.normalized">
356 <xsl:variable name="contents">
357 <xsl:call-template name="person.name"/>
358 </xsl:variable>
359 <!-- * We put the output of person.name into a node-set and then we -->
360 <!-- * check it node-by-node and strip out space only where needed. -->
361 <xsl:variable name="contents.tree" select="exsl:node-set($contents)"/>
362 <xsl:for-each select="$contents.tree/node()">
363 <xsl:choose>
364 <!-- * We don't want to monkey with single spaces or commas/periods -->
365 <!-- * followed by spaces, because those are bits of text that are -->
366 <!-- * actually generated by the person.name template itself (that -->
367 <!-- * is, they're not in the source). So, we preserve them. -->
368 <xsl:when test=". = ' ' or . = ', ' or . = '. '">
369 <xsl:value-of select="."/>
370 </xsl:when>
371 <xsl:otherwise>
372 <xsl:value-of select="normalize-space(.)"/>
373 </xsl:otherwise>
374 </xsl:choose>
375 </xsl:for-each>
376 </xsl:template>
377
378 <!-- ================================================================== -->
379
380 <xsl:template name="make.adjusted.man.filename">
381 <xsl:param name="name"/>
382 <xsl:param name="lang"/>
383 <xsl:param name="name.with.lang">
384 <xsl:choose>
385 <xsl:when test="$lang != 'en'
386 and not($man.output.lang.in.name.enabled = 0)
387 and ($man.output.subdirs.enabled = 0 or
388 $man.output.in.separate.dir = 0)">
389 <!-- * $lang is not en (English) -->
390 <!-- * AND user has specified man.output.lang.in.name.enabled -->
391 <!-- * AND doesn't want output going into separate dirs, -->
392 <!-- * SO... we include the $lang value in the filename; e.g., -->
393 <!-- * foo.ja.1 -->
394 <xsl:value-of select="concat($name, '.', $lang)"/>
395 </xsl:when>
396 <xsl:otherwise>
397 <!-- * user either has man.output.lang.in.name.enabled unset -->
398 <!-- * or has set it but also has man.output.subdirs.enabled -->
399 <!-- * set (in which case the $lang value is used to add a -->
400 <!-- * $lang subdir in the pathname); in either case, we don't -->
401 <!-- * want to include the $lang in the filename -->
402 <xsl:value-of select="$name"/>
403 </xsl:otherwise>
404 </xsl:choose>
405 </xsl:param>
406 <xsl:param name="section"/>
407 <xsl:param name="dirname">
408 <xsl:if test="not($man.output.in.separate.dir = 0)">
409 <xsl:choose>
410 <xsl:when test="not($man.output.subdirs.enabled = 0)">
411 <xsl:variable name="lang.subdir">
412 <xsl:if test="not($man.output.lang.in.name.enabled = 0)">
413 <!-- * user has man.output.lang.in.name.enabled set, so -->
414 <!-- * we need to add a $lang subdir -->
415 <xsl:value-of select="concat($lang, '/')"/>
416 </xsl:if>
417 </xsl:variable>
418 <xsl:value-of
419 select="concat($man.output.base.dir, $lang.subdir,
420 'man', normalize-space($section), '/')"/>
421 </xsl:when>
422 <xsl:otherwise>
423 <xsl:value-of select="$man.output.base.dir"/>
424 </xsl:otherwise>
425 </xsl:choose>
426 </xsl:if>
427 </xsl:param>
428 <xsl:call-template name="string.subst">
429 <!-- * To create the man filename, replace any spaces in filename with -->
430 <!-- * underscores and then append a dot plus a section number. -->
431 <xsl:with-param name="string"
432 select="concat($dirname,
433 normalize-space($name.with.lang),
434 '.', normalize-space($section))"/>
435 <xsl:with-param name="target" select="' '"/>
436 <xsl:with-param name="replacement" select="'_'"/>
437 </xsl:call-template>
438 </xsl:template>
439
440 <!-- ================================================================== -->
441
442 <!-- * Put a horizontal rule or other divider around section titles -->
443 <!-- * in roff source (just to make things easier to read). -->
444 <xsl:template name="mark.subheading">
445 <xsl:if test="$man.subheading.divider.enabled != 0">
446 <xsl:text>.\" </xsl:text>
447 <xsl:value-of select="$man.subheading.divider"/>
448 <xsl:text>&#10;</xsl:text>
449 </xsl:if>
450 </xsl:template>
451
452 </xsl:stylesheet>