]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/styleguide/docbook-xsl-1.75.2/manpages/docbook.xsl
stylesheet changes.
[working/Evergreen.git] / stylesheets / styleguide / docbook-xsl-1.75.2 / manpages / docbook.xsl
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:ng="http://docbook.org/docbook-ng"
5                 xmlns:db="http://docbook.org/ns/docbook"
6                 exclude-result-prefixes="exsl"
7                 version='1.0'>
8
9   <xsl:import href="../html/docbook.xsl"/>
10   <xsl:import href="../html/manifest.xsl"/>
11   <!-- * html-synop.xsl file is generated by build -->
12   <xsl:import href="html-synop.xsl"/>
13   <xsl:output method="text"
14               encoding="UTF-8"
15               indent="no"/>
16   <!-- ********************************************************************
17        $Id: docbook.xsl 8486 2009-07-14 19:33:56Z mzjn $
18        ********************************************************************
19
20        This file is part of the XSL DocBook Stylesheet distribution.
21        See ../README or http://docbook.sf.net/release/xsl/current/ for
22        copyright and other information.
23
24        ******************************************************************** -->
25
26   <!-- ==================================================================== -->
27
28   <xsl:include href="../common/refentry.xsl"/>
29   <xsl:include href="../common/charmap.xsl"/>
30   <xsl:include href="param.xsl"/>
31   <xsl:include href="utility.xsl"/>
32   <xsl:include href="info.xsl"/>
33   <xsl:include href="other.xsl"/>
34   <xsl:include href="refentry.xsl"/>
35   <xsl:include href="block.xsl"/>
36   <xsl:include href="inline.xsl"/>
37   <xsl:include href="synop.xsl"/>
38   <xsl:include href="lists.xsl"/>
39   <xsl:include href="endnotes.xsl"/>
40   <xsl:include href="table.xsl"/>
41   <xsl:include href="pi.xsl"/>
42
43   <!-- * we rename the following just to avoid using params with "man" -->
44   <!-- * prefixes in the table.xsl stylesheet (because that stylesheet -->
45   <!-- * can potentially be reused for more than just man output) -->
46   <xsl:param name="tbl.font.headings" select="$man.font.table.headings"/>
47   <xsl:param name="tbl.font.title" select="$man.font.table.title"/>
48
49   <xsl:param name="stylesheet.result.type" select="'manpages'"/>
50
51   <!-- ==================================================================== -->
52
53   <xsl:template match="/">
54     <!-- * Get a title for current doc so that we let the user -->
55     <!-- * know what document we are processing at this point. -->
56     <xsl:variable name="doc.title">
57       <xsl:call-template name="get.doc.title"/>
58     </xsl:variable>
59     <xsl:choose>
60       <!-- * when we find a namespaced document, strip the -->
61       <!-- * namespace and then continue processing it. -->
62       <xsl:when test="//self::db:*">
63         <xsl:call-template name="log.message">
64           <xsl:with-param name="level">Note</xsl:with-param>
65           <xsl:with-param name="source" select="$doc.title"/>
66           <xsl:with-param name="context-desc">
67             <xsl:text>namesp. cut</xsl:text>
68           </xsl:with-param>
69           <xsl:with-param name="message">
70             <xsl:text>stripped namespace before processing</xsl:text>
71           </xsl:with-param>
72         </xsl:call-template>
73         <xsl:variable name="stripns">
74           <xsl:apply-templates mode="stripNS"/>
75         </xsl:variable>
76         <xsl:call-template name="log.message">
77           <xsl:with-param name="level">Note</xsl:with-param>
78           <xsl:with-param name="source" select="$doc.title"/>
79           <xsl:with-param name="context-desc">
80             <xsl:text>namesp. cut</xsl:text>
81           </xsl:with-param>
82           <xsl:with-param name="message">
83             <xsl:text>processing stripped document</xsl:text>
84           </xsl:with-param>
85         </xsl:call-template>
86         <xsl:apply-templates select="exsl:node-set($stripns)"/>
87       </xsl:when>
88       <xsl:when test="//*[local-name() = 'refentry']">
89         <!-- * Check to see if we have any refentry children in this -->
90         <!-- * document; if so, process them. The reason we use -->
91         <!-- * local-name()=refentry (instead of just //refentry) to to -->
92         <!-- * check for refentry children is because this stylsheet is -->
93         <!-- * also post-processed by the stylesheet build to create the -->
94         <!-- * manpages/profile-docbook.xsl, and the refentry child check -->
95         <!-- * in the profile-docbook.xsl stylesheet won't work if we do -->
96         <!-- * a simple //refentry check. -->
97         <xsl:apply-templates select="//refentry"/>
98         <!-- * if $man.output.manifest.enabled is non-zero, -->
99         <!-- * generate a manifest file -->
100         <xsl:if test="not($man.output.manifest.enabled = 0)">
101           <xsl:call-template name="generate.manifest">
102             <xsl:with-param name="filename">
103               <xsl:choose>
104                 <xsl:when test="not($man.output.manifest.filename = '')">
105                   <!-- * If a name for the manifest file is specified, -->
106                   <!-- * use that name. -->
107                   <xsl:value-of select="$man.output.manifest.filename"/>
108                 </xsl:when>
109                 <xsl:otherwise>
110                   <!-- * Otherwise, if user has unset -->
111                   <!-- * $man.output.manifest.filename, default to -->
112                   <!-- * using "MAN.MANIFEST" as the filename. Because -->
113                   <!-- * $man.output.manifest.enabled is non-zero and -->
114                   <!-- * so we must have a filename in order to -->
115                   <!-- * generate the manifest. -->
116                   <xsl:text>MAN.MANIFEST</xsl:text>
117                 </xsl:otherwise>
118               </xsl:choose>
119             </xsl:with-param>
120           </xsl:call-template>
121         </xsl:if>
122       </xsl:when>
123       <xsl:otherwise>
124         <!-- * Otherwise, the document does not contain any -->
125         <!-- * refentry elements, so log/emit message and stop. -->
126         <xsl:call-template name="log.message">
127           <xsl:with-param name="level">Erro</xsl:with-param>
128           <xsl:with-param name="source" select="$doc.title"/>
129           <xsl:with-param name="context-desc">
130             <xsl:text> no refentry</xsl:text>
131           </xsl:with-param>
132           <xsl:with-param name="message">
133             <xsl:text>No refentry elements found</xsl:text>
134             <xsl:if test="$doc.title != ''">
135             <xsl:text> in "</xsl:text>
136               <xsl:choose>
137                 <xsl:when test="string-length($doc.title) &gt; 30">
138                   <xsl:value-of select="substring($doc.title,1,30)"/>
139                   <xsl:text>...</xsl:text>
140                 </xsl:when>
141                 <xsl:otherwise>
142                   <xsl:value-of select="$doc.title"/>
143                 </xsl:otherwise>
144               </xsl:choose>
145               <xsl:text>"</xsl:text>
146             </xsl:if>
147             <xsl:text>.</xsl:text>
148           </xsl:with-param>
149         </xsl:call-template>
150       </xsl:otherwise>
151     </xsl:choose>
152   </xsl:template>
153
154   <!-- ============================================================== -->
155
156   <xsl:template match="refentry">
157     <xsl:param name="lang">
158       <xsl:call-template name="l10n.language"/>
159     </xsl:param>
160     <!-- * Just use the first refname found as the "name" of the man -->
161     <!-- * page (which may different from the "title"...) -->
162     <xsl:variable name="first.refname" select="refnamediv[1]/refname[1]"/>
163
164     <xsl:call-template name="root.messages">
165       <xsl:with-param name="refname" select="$first.refname"/>
166     </xsl:call-template>
167
168     <!-- * Because there are several times when we need to check *info of -->
169     <!-- * each refentry and its ancestors, we get those and store the -->
170     <!-- * data from them as a node-set in memory. -->
171
172     <!-- * Make a node-set with contents of *info -->
173     <xsl:variable name="get.info"
174                   select="ancestor-or-self::*/*[substring(local-name(),
175                           string-length(local-name()) - 3) = 'info']"
176                   />
177     <xsl:variable name="info" select="exsl:node-set($get.info)"/>
178
179     <!-- * The get.refentry.metadata template is in -->
180     <!-- * ../common/refentry.xsl. It looks for metadata in $info -->
181     <!-- * and in various other places and then puts it into a form -->
182     <!-- * that's easier for us to digest. -->
183     <xsl:variable name="get.refentry.metadata">
184       <xsl:call-template name="get.refentry.metadata">
185         <xsl:with-param name="refname" select="$first.refname"/>
186         <xsl:with-param name="info" select="$info"/>
187         <xsl:with-param name="prefs" select="$refentry.metadata.prefs"/>
188       </xsl:call-template>
189     </xsl:variable>
190     <xsl:variable name="refentry.metadata" select="exsl:node-set($get.refentry.metadata)"/>
191
192     <!-- * Assemble the various parts into a complete page, then store into -->
193     <!-- * $manpage.contents so that we can manipluate them further. -->
194     <xsl:variable name="manpage.contents">
195       <!-- * preprocessor invocation (need for legacy AT&T troff use) -->
196       <!-- * this tells troff to pre-process the page through tbl(1) -->
197       <!-- * (groff can figure it out automatically, but AT&T troff can't) -->
198       <xsl:text>'\" t&#10;</xsl:text>
199       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
200       <!-- * top.comment = commented-out section at top of roff source -->
201       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
202       <xsl:call-template name="top.comment">
203         <xsl:with-param name="info"       select="$info"/>
204         <xsl:with-param name="date"       select="$refentry.metadata/date"/>
205         <xsl:with-param name="title"      select="$refentry.metadata/title"/>
206         <xsl:with-param name="manual"     select="$refentry.metadata/manual"/>
207         <xsl:with-param name="source"     select="$refentry.metadata/source"/>
208         <xsl:with-param name="refname"    select="$first.refname"/>
209       </xsl:call-template>
210       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
211       <!-- * TH.title.line = title line in header/footer of man page -->
212       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
213       <xsl:call-template name="TH.title.line">
214         <!-- * .TH TITLE  section  extra1  extra2  extra3 -->
215         <!-- *  -->
216         <!-- * According to the man(7) man page: -->
217         <!-- *  -->
218         <!-- * extra1 = date,   "the date of the last revision" -->
219         <!-- * extra2 = source, "the source of the command" -->
220         <!-- * extra3 = manual, "the title of the manual -->
221         <!-- *                  (e.g., Linux Programmer's Manual)" -->
222         <!-- * -->
223         <!-- * So, we end up with: -->
224         <!-- *  -->
225         <!-- * .TH TITLE  section  date  source  manual -->
226         <!-- * -->
227         <xsl:with-param name="title"   select="$refentry.metadata/title"/>
228         <xsl:with-param name="section" select="$refentry.metadata/section"/>
229         <xsl:with-param name="extra1"  select="$refentry.metadata/date"/>
230         <xsl:with-param name="extra2"  select="$refentry.metadata/source"/>
231         <xsl:with-param name="extra3"  select="$refentry.metadata/manual"/>
232       </xsl:call-template>
233       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
234       <!-- * (re)define some macros -->
235       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
236       <xsl:if test="not($man.output.better.ps.enabled = 0)">
237         <xsl:call-template name="define.macros"/>
238       </xsl:if>
239       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
240       <!-- * Set default hyphenation, justification, indentation, and -->
241       <!-- * line-breaking -->
242       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
243       <xsl:call-template name="set.default.formatting"/>
244       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
245       <!-- * Main body of man page -->
246       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
247       <xsl:text>.\" -----------------------------------------------------------------&#10;</xsl:text>
248       <xsl:text>.\" * MAIN CONTENT STARTS HERE *&#10;</xsl:text>
249       <xsl:text>.\" -----------------------------------------------------------------&#10;</xsl:text>
250       <xsl:apply-templates/>
251       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
252       <!-- * AUTHOR section -->
253       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
254       <xsl:if test="not($man.authors.section.enabled = 0)">
255         <xsl:call-template name="author.section">
256           <xsl:with-param name="info" select="$info"/>
257         </xsl:call-template>
258       </xsl:if>
259       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
260       <!-- * COPYRIGHT section -->
261       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
262       <xsl:if test="not($man.copyright.section.enabled = 0)">
263         <xsl:call-template name="copyright.section">
264           <xsl:with-param name="info" select="$info"/>
265         </xsl:call-template>
266       </xsl:if>
267       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
268       <!-- * NOTES list (only if user wants endnotes numbered and/or listed) -->
269       <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
270       <xsl:if test="$man.endnotes.list.enabled != 0 or
271                     $man.endnotes.are.numbered != 0">
272         <xsl:call-template name="endnotes.list"/>
273       </xsl:if>
274     </xsl:variable> <!-- * end of manpage.contents -->
275
276     <!-- * Prepare the page contents for final output, then store in -->
277     <!-- * $manpage.contents.prepared so the we can pass it on to the -->
278     <!-- * write.text.chunk() function -->
279     <xsl:variable name="manpage.contents.prepared">
280       <!-- * "Preparing" the page contents involves, at a minimum, -->
281       <!-- * doubling any backslashes found (so they aren't interpreted -->
282       <!-- * as roff escapes). -->
283       <!-- * -->
284       <!-- * If $charmap.enabled is true, "preparing" the page contents also -->
285       <!-- * involves applying a character map to convert Unicode symbols and -->
286       <!-- * special characters into corresponding roff escape sequences. -->
287       <xsl:call-template name="prepare.manpage.contents">
288         <xsl:with-param name="content" select="$manpage.contents"/>
289       </xsl:call-template>
290     </xsl:variable>
291     
292     <!-- * Write the prepared page contents to disk to create -->
293     <!-- * the final man page. -->
294     <xsl:call-template name="write.man.file">
295       <xsl:with-param name="name" select="$first.refname"/>
296       <xsl:with-param name="section" select="$refentry.metadata/section"/>
297       <xsl:with-param name="lang" select="$lang"/>
298       <xsl:with-param name="content" select="$manpage.contents.prepared"/>
299     </xsl:call-template>
300
301     <!-- * Generate "stub" (alias) pages (if any needed) -->
302     <xsl:call-template name="write.stubs">
303       <xsl:with-param name="first.refname" select="$first.refname"/>
304       <xsl:with-param name="section" select="$refentry.metadata/section"/>
305       <xsl:with-param name="lang" select="$lang"/>
306     </xsl:call-template>
307
308   </xsl:template>
309
310 </xsl:stylesheet>