2 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
3 xmlns:
exsl=
"http://exslt.org/common"
4 exclude-result-prefixes=
"exsl"
7 <!-- ********************************************************************
8 $Id: synop.xsl,v 1.1 2007/03/10 05:15:34 scott Exp $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://docbook.sf.net/release/xsl/current/ for
13 copyright and other information.
15 ******************************************************************** -->
17 <xsl:variable name=
"arg.or.sep"> |
</xsl:variable>
19 <!-- * Note: If you're looking for the *Synopsis* element, you won't -->
20 <!-- * find any code here for handling it. It's a "verbatim" -->
21 <!-- * environment; see the block.xsl file instead. -->
23 <xsl:template match=
"synopfragmentref">
24 <xsl:variable name=
"target" select=
"key('id',@linkend)"/>
25 <xsl:variable name=
"snum">
26 <xsl:apply-templates select=
"$target" mode=
"synopfragment.number"/>
28 <xsl:text>(
</xsl:text>
29 <xsl:value-of select=
"$snum"/>
30 <xsl:text>)
</xsl:text>
31 <xsl:text>▀</xsl:text>
32 <xsl:variable name=
"synopfragmentref">
33 <FragRefContents><xsl:value-of select=
"normalize-space(.)"/></FragRefContents>
35 <xsl:apply-templates select=
"exsl:node-set($synopfragmentref)" mode=
"italic"/>
38 <xsl:template match=
"synopfragment" mode=
"synopfragment.number">
39 <xsl:number format=
"1"/>
42 <xsl:template match=
"synopfragment">
43 <xsl:variable name=
"snum">
44 <xsl:apply-templates select=
"." mode=
"synopfragment.number"/>
46 <xsl:text> </xsl:text>
47 <!-- * If we have a group of Synopgfragments, we only want to output a -->
48 <!-- * line of space before the first; so when we find a Synopfragment -->
49 <!-- * whose first preceding sibling is another Synopfragment, we back -->
50 <!-- * up one line vertically to negate the line of vertical space -->
51 <!-- * that's added by the .HP macro -->
52 <xsl:if test=
"preceding-sibling::*[1][self::synopfragment]">
53 <xsl:text>.sp -
1n
</xsl:text>
55 <xsl:text>.HP
</xsl:text>
56 <!-- * For each Synopfragment, make a hanging paragraph, with the -->
57 <!-- * indent calculated from the length of the generated number -->
58 <!-- * used as a reference + pluse 3 characters (for the open and -->
59 <!-- * close parens around the number, plus a space). -->
60 <xsl:value-of select=
"string-length (normalize-space ($snum)) + 3"/>
61 <xsl:text> </xsl:text>
62 <xsl:text>(
</xsl:text>
63 <xsl:value-of select=
"$snum"/>
64 <xsl:text>)
</xsl:text>
65 <xsl:text> </xsl:text>
66 <xsl:apply-templates/>
69 <xsl:template match=
"group|arg" name=
"group-or-arg">
70 <xsl:variable name=
"choice" select=
"@choice"/>
71 <xsl:variable name=
"rep" select=
"@rep"/>
72 <xsl:variable name=
"sepchar">
74 <xsl:when test=
"ancestor-or-self::*/@sepchar">
75 <xsl:value-of select=
"ancestor-or-self::*/@sepchar"/>
78 <xsl:text> </xsl:text>
82 <xsl:if test=
"position()>1 and
83 not(preceding-sibling::*[1][self::sbr])"
84 ><xsl:value-of select=
"$sepchar"/></xsl:if>
86 <xsl:when test=
"$choice='plain'">
89 <xsl:when test=
"$choice='req'">
90 <xsl:value-of select=
"$arg.choice.req.open.str"/>
92 <xsl:when test=
"$choice='opt'">
93 <xsl:value-of select=
"$arg.choice.opt.open.str"/>
96 <xsl:value-of select=
"$arg.choice.def.open.str"/>
99 <xsl:variable name=
"arg">
100 <xsl:apply-templates/>
103 <xsl:when test=
"local-name(.) = 'arg' and not(ancestor::arg)">
104 <!-- * Prevent arg contents from getting wrapped and broken up -->
105 <xsl:variable name=
"arg.wrapper">
106 <Arg><xsl:value-of select=
"normalize-space($arg)"/></Arg>
108 <xsl:apply-templates mode=
"prevent.line.breaking"
109 select=
"exsl:node-set($arg.wrapper)"/>
112 <xsl:value-of select=
"$arg"/>
116 <xsl:when test=
"$rep='repeat'">
117 <xsl:value-of select=
"$arg.rep.repeat.str"/>
119 <xsl:when test=
"$rep='norepeat'">
120 <xsl:value-of select=
"$arg.rep.norepeat.str"/>
123 <xsl:value-of select=
"$arg.rep.def.str"/>
127 <xsl:when test=
"$choice='plain'">
129 <xsl:value-of select=
"$arg.choice.plain.close.str"/>
132 <xsl:when test=
"$choice='req'">
133 <xsl:value-of select=
"$arg.choice.req.close.str"/>
135 <xsl:when test=
"$choice='opt'">
136 <xsl:value-of select=
"$arg.choice.opt.close.str"/>
139 <xsl:value-of select=
"$arg.choice.def.close.str"/>
144 <xsl:template match=
"group/arg">
145 <xsl:variable name=
"choice" select=
"@choice"/>
146 <xsl:variable name=
"rep" select=
"@rep"/>
147 <xsl:if test=
"position()>1"><xsl:value-of select=
"$arg.or.sep"/></xsl:if>
148 <xsl:call-template name=
"group-or-arg"/>
151 <xsl:template match=
"sbr">
152 <xsl:text>▒</xsl:text>
153 <xsl:text>.br
▒</xsl:text>
156 <xsl:template match=
"cmdsynopsis">
157 <!-- * if justification is enabled by default, turn it off temporarily -->
158 <xsl:if test=
"$man.justify != 0">
159 <xsl:text>.ad l
</xsl:text>
161 <!-- * if hyphenation is enabled by default, turn it off temporarily -->
162 <xsl:if test=
"$man.hyphenate != 0">
163 <xsl:text>.hy
0 </xsl:text>
165 <xsl:text>.HP
</xsl:text>
166 <xsl:value-of select=
"string-length (normalize-space (command)) + 1"/>
167 <xsl:text> </xsl:text>
168 <xsl:apply-templates/>
169 <xsl:text> </xsl:text>
170 <!-- * if justification is enabled by default, turn it back on -->
171 <xsl:if test=
"$man.justify != 0">
172 <xsl:text>.ad
</xsl:text>
174 <!-- * if hyphenation is enabled by default, turn it back on -->
175 <xsl:if test=
"$man.hyphenate != 0">
176 <xsl:text>.hy
</xsl:text>
180 <!-- ==================================================================== -->
181 <!-- * Funcsynopis hierarchy starts here -->
182 <!-- ==================================================================== -->
184 <!-- * Note: If you're looking for the *Funcsynopsisinfo* element, -->
185 <!-- * you won't find any code here for handling it. It's a "verbatim" -->
186 <!-- * environment; see the block.xsl file instead. -->
188 <!-- * Within funcsynopis output, disable hyphenation, and use -->
189 <!-- * left-aligned filling for the duration of the synopsis, so that -->
190 <!-- * line breaks only occur between separate paramdefs. -->
191 <xsl:template match=
"funcsynopsis">
192 <!-- * if justification is enabled by default, turn it off temporarily -->
193 <xsl:if test=
"$man.justify != 0">
194 <xsl:text>.ad l
</xsl:text>
196 <!-- * if hyphenation is enabled by default, turn it off temporarily -->
197 <xsl:if test=
"$man.hyphenate != 0">
198 <xsl:text>.hy
0 </xsl:text>
200 <xsl:apply-templates/>
201 <!-- * if justification is enabled by default, turn it back on -->
202 <xsl:if test=
"$man.justify != 0">
203 <xsl:text>.ad
</xsl:text>
205 <!-- * if hyphenation is enabled by default, turn it back on -->
206 <xsl:if test=
"$man.hyphenate != 0">
207 <xsl:text>.hy
</xsl:text>
211 <!-- * All Funcprototype content is by default rendered in bold, -->
212 <!-- * because the man(7) man page says this: -->
214 <!-- * For functions, the arguments are always specified using -->
215 <!-- * italics, even in the SYNOPSIS section, where the rest of -->
216 <!-- * the function is specified in bold -->
218 <!-- * Look through the contents of the man/man2 and man3 directories -->
219 <!-- * on your system, and you'll see that most existing pages do follow -->
220 <!-- * this "bold everything in function synopsis" rule. -->
222 <!-- * Users who don't want the bold output can choose to adjust the -->
223 <!-- * man.font.funcprototype parameter on their own. So even if you -->
224 <!-- * don't personally like the way it looks, please don't change the -->
225 <!-- * default to be non-bold - because it's a convention that's -->
226 <!-- * followed is the vast majority of existing man pages that document -->
227 <!-- * functions, and we need to follow it by default, like it or no. -->
228 <xsl:template match=
"funcprototype">
229 <xsl:variable name=
"funcprototype.string.value">
230 <xsl:value-of select=
"funcdef"/>
232 <xsl:variable name=
"funcprototype">
233 <xsl:apply-templates select=
"funcdef"/>
235 <xsl:text>.HP
</xsl:text>
236 <!-- * Hang Paragraph by length of string value of <funcdef> + 1 -->
237 <!-- * (because funcdef is always followed by one open paren char) -->
238 <xsl:value-of select=
"string-length (normalize-space ($funcprototype.string.value)) + 1"/>
239 <xsl:text> </xsl:text>
240 <xsl:text>.
</xsl:text>
241 <xsl:value-of select=
"$man.font.funcprototype"/>
242 <xsl:text> </xsl:text>
243 <!-- * The following quotation mark (and the one further below) are -->
244 <!-- * needed to properly delimit the parts of the Funcprototype that -->
245 <!-- * should be rendered in the prevailing font (either Bold or Roman) -->
246 <!-- * from Parameter output that needs to be alternately rendered in -->
248 <xsl:text>"</xsl:text>
249 <xsl:value-of select="normalize-space($funcprototype)
"/>
250 <xsl:text>(</xsl:text>
251 <xsl:apply-templates select="*[local-name() != 'funcdef']
"/>
252 <xsl:text>"</xsl:text>
253 <xsl:text> </xsl:text>
256 <xsl:template match=
"funcdef">
257 <xsl:apply-templates mode=
"prevent.line.breaking"/>
260 <xsl:template match=
"funcdef/function">
261 <xsl:apply-templates/>
264 <xsl:template match=
"void">
265 <xsl:text>void);
</xsl:text>
268 <xsl:template match=
"varargs">
269 <xsl:text>...);
</xsl:text>
272 <xsl:template match=
"paramdef">
273 <xsl:apply-templates mode=
"prevent.line.breaking" select=
"."/>
275 <xsl:when test=
"following-sibling::*">
276 <xsl:text>,
</xsl:text>
279 <xsl:text>);
</xsl:text>
284 <xsl:template match=
"paramdef/parameter">
285 <!-- * We use U+2591 here in place of a normal space, because if we -->
286 <!-- * were to just use a normal space, it would get replaced with a -->
287 <!-- * non-breaking space when we run the whole Paramdef through the -->
288 <!-- * prevent.line.breaking template. And as far as why we're -->
289 <!-- * inserting the space and quotation marks around each Parameter -->
290 <!-- * to begin with, the reason is that we need to because we are -->
291 <!-- * outputting Funcsynopsis in either the "BI" or "RI" font, and -->
292 <!-- * the space and quotation marks delimit the text as the -->
293 <!-- * "alternate" or "I" text that needs to be rendered in italic. -->
294 <xsl:text>"░"</xsl:text>
295 <xsl:apply-templates/>
296 <xsl:text>"░"</xsl:text>
299 <xsl:template match=
"funcparams">
300 <xsl:text>(
</xsl:text>
301 <xsl:apply-templates/>
302 <xsl:text>)
</xsl:text>