Debian Codegraph @

xsl/synopsis.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
4 <!--############################################################################
5 XSLT Stylesheet DocBook -> LaTeX
6 ############################################################################ -->
7
8 <xsl:strip-space elements="cmdsynopsis arg group"/>
9
10
11 <xsl:template match="synopsis">
12 <xsl:call-template name="label.id"/>
13 <xsl:call-template name="output.verbatim"/>
14 </xsl:template>
15
16 <xsl:template match="synopsis|funcsynopsisinfo" mode="save.verbatim">
17 <xsl:call-template name="save.verbatim"/>
18 </xsl:template>
19
20 <!-- we want the brackets -->
21 <xsl:template match="optional" mode="latex.verbatim">
22 <xsl:value-of select="$arg.choice.opt.open.str"/>
23 <xsl:apply-templates mode="latex.verbatim"/>
24 <xsl:value-of select="$arg.choice.opt.close.str"/>
25 </xsl:template>
26
27
28 <!-- ###############
29 # cmdsynopsis #
30 ############### -->
31
32 <xsl:template match="cmdsynopsis">
33 <xsl:text>&#10;</xsl:text>
34 <xsl:call-template name="label.id"/>
35 <xsl:apply-templates/>
36 <xsl:text>&#10;</xsl:text>
37 </xsl:template>
38
39 <xsl:template match="cmdsynopsis/command">
40 <xsl:text>&#10; </xsl:text>
41 <xsl:call-template name="inline.monoseq"/>
42 <xsl:text> </xsl:text>
43 </xsl:template>
44
45 <xsl:template match="cmdsynopsis/command[1]">
46 <xsl:call-template name="inline.monoseq"/>
47 <xsl:text> </xsl:text>
48 </xsl:template>
49
50 <xsl:template match="group|arg">
51 <xsl:variable name="choice" select="@choice"/>
52 <xsl:variable name="rep" select="@rep"/>
53 <xsl:variable name="sepchar">
54 <xsl:choose>
55 <xsl:when test="ancestor-or-self::*/@sepchar">
56 <xsl:value-of select="ancestor-or-self::*/@sepchar"/>
57 </xsl:when>
58 <xsl:otherwise>
59 <xsl:text> </xsl:text>
60 </xsl:otherwise>
61 </xsl:choose>
62 </xsl:variable>
63 <xsl:if test="preceding-sibling::*">
64 <xsl:value-of select="$sepchar"/>
65 </xsl:if>
66 <xsl:choose>
67 <xsl:when test="$choice='plain'">
68 <xsl:value-of select="$arg.choice.plain.open.str"/>
69 </xsl:when>
70 <xsl:when test="$choice='req'">
71 <xsl:value-of select="$arg.choice.req.open.str"/>
72 </xsl:when>
73 <xsl:when test="$choice='opt'">
74 <xsl:value-of select="$arg.choice.opt.open.str"/>
75 </xsl:when>
76 <xsl:otherwise>
77 <xsl:value-of select="$arg.choice.def.open.str"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 <xsl:apply-templates/>
81 <xsl:choose>
82 <xsl:when test="$rep='repeat'">
83 <xsl:value-of select="$arg.rep.repeat.str"/>
84 </xsl:when>
85 <xsl:when test="$rep='norepeat'">
86 <xsl:value-of select="$arg.rep.norepeat.str"/>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:value-of select="$arg.rep.def.str"/>
90 </xsl:otherwise>
91 </xsl:choose>
92 <xsl:choose>
93 <xsl:when test="$choice='plain'">
94 <xsl:value-of select="$arg.choice.plain.close.str"/>
95 </xsl:when>
96 <xsl:when test="$choice='req'">
97 <xsl:value-of select="$arg.choice.req.close.str"/>
98 </xsl:when>
99 <xsl:when test="$choice='opt'">
100 <xsl:value-of select="$arg.choice.opt.close.str"/>
101 </xsl:when>
102 <xsl:otherwise>
103 <xsl:value-of select="$arg.choice.def.close.str"/>
104 </xsl:otherwise>
105 </xsl:choose>
106 </xsl:template>
107
108 <xsl:template match="group/arg">
109 <xsl:if test="preceding-sibling::*">
110 <xsl:value-of select="$arg.or.sep"/>
111 </xsl:if>
112 <xsl:apply-templates/>
113 </xsl:template>
114
115 <xsl:template match="sbr">
116 <xsl:text>\newline&#10;</xsl:text>
117 </xsl:template>
118
119 <xsl:template match="synopfragmentref">
120 <xsl:variable name="target" select="key('id',@linkend)"/>
121 <xsl:variable name="snum">
122 <xsl:apply-templates select="$target" mode="synopfragment.number"/>
123 </xsl:variable>
124
125 <xsl:text>{\em (</xsl:text>
126 <xsl:value-of select="$snum"/>
127 <xsl:text>)</xsl:text>
128 <xsl:apply-templates/>
129 <xsl:text>}</xsl:text>
130 </xsl:template>
131
132 <xsl:template match="synopfragment" mode="synopfragment.number">
133 <xsl:number format="1"/>
134 </xsl:template>
135
136 <xsl:template match="synopfragment">
137 <xsl:variable name="snum">
138 <xsl:apply-templates select="." mode="synopfragment.number"/>
139 </xsl:variable>
140
141 <xsl:if test="$snum=1"><xsl:text>&#10;</xsl:text></xsl:if>
142 <xsl:text>&#10;(</xsl:text>
143 <xsl:value-of select="$snum"/>
144 <xsl:text>) </xsl:text>
145 <xsl:apply-templates/>
146 <xsl:text>&#10;</xsl:text>
147 </xsl:template>
148
149
150 <!-- ################
151 # funcsynopsis #
152 ################ -->
153
154 <xsl:template match="funcsynopsis">
155 <xsl:text>&#10;</xsl:text>
156 <xsl:call-template name="label.id"/>
157 <xsl:apply-templates/>
158 <xsl:text>&#10;</xsl:text>
159 </xsl:template>
160
161 <xsl:template match="funcsynopsisinfo">
162 <xsl:call-template name="output.verbatim"/>
163 </xsl:template>
164
165 <xsl:template match="funcprototype">
166 <xsl:apply-templates/>
167 <xsl:if test="$funcsynopsis.style='kr'">
168 <xsl:apply-templates select="./paramdef" mode="kr"/>
169 </xsl:if>
170 <xsl:if test="following-sibling::*">
171 <xsl:text>\newline</xsl:text>
172 </xsl:if>
173 <xsl:text>&#10;</xsl:text>
174 </xsl:template>
175
176 <xsl:template match="funcdef">
177 <xsl:apply-templates/>
178 </xsl:template>
179
180 <xsl:template match="funcdef/function">
181 <xsl:choose>
182 <xsl:when test="$funcsynopsis.decoration != 0">
183 <xsl:text>\textbf{</xsl:text>
184 <xsl:apply-templates/>
185 <xsl:text>}</xsl:text>
186 </xsl:when>
187 <xsl:otherwise>
188 <xsl:apply-templates/>
189 </xsl:otherwise>
190 </xsl:choose>
191 </xsl:template>
192
193 <xsl:template match="void">
194 <xsl:choose>
195 <xsl:when test="$funcsynopsis.style='ansi'">
196 <xsl:text>(void);</xsl:text>
197 </xsl:when>
198 <xsl:otherwise>
199 <xsl:text>();</xsl:text>
200 </xsl:otherwise>
201 </xsl:choose>
202 </xsl:template>
203
204 <xsl:template match="varargs">
205 <xsl:text>( ... );</xsl:text>
206 </xsl:template>
207
208 <xsl:template match="paramdef">
209 <xsl:variable name="paramnum">
210 <xsl:number count="paramdef" format="1"/>
211 </xsl:variable>
212
213 <xsl:if test="$paramnum=1">(</xsl:if>
214 <xsl:choose>
215 <xsl:when test="not(parameter) or $funcsynopsis.style='ansi'">
216 <xsl:apply-templates/>
217 </xsl:when>
218 <xsl:otherwise>
219 <xsl:apply-templates select="./parameter"/>
220 </xsl:otherwise>
221 </xsl:choose>
222 <xsl:choose>
223 <xsl:when test="following-sibling::paramdef">
224 <xsl:text>, </xsl:text>
225 </xsl:when>
226 <xsl:otherwise>
227 <xsl:text>);</xsl:text>
228 </xsl:otherwise>
229 </xsl:choose>
230 </xsl:template>
231
232 <xsl:template match="paramdef/parameter">
233 <xsl:choose>
234 <xsl:when test="$funcsynopsis.decoration != 0">
235 <xsl:apply-templates/>
236 </xsl:when>
237 <xsl:otherwise>
238 <xsl:apply-templates/>
239 </xsl:otherwise>
240 </xsl:choose>
241 <xsl:if test="following-sibling::parameter">
242 <xsl:text>, </xsl:text>
243 </xsl:if>
244 </xsl:template>
245
246 <xsl:template match="paramdef" mode="kr">
247 <xsl:if test="parameter">
248 <xsl:text>\newline&#10;</xsl:text>
249 <xsl:apply-templates/>
250 <xsl:text>;</xsl:text>
251 </xsl:if>
252 </xsl:template>
253
254 <xsl:template match="funcparams">
255 <xsl:text>(</xsl:text>
256 <xsl:apply-templates/>
257 <xsl:text>)</xsl:text>
258 </xsl:template>
259
260 </xsl:stylesheet>