]> git.stg.codes - stg.git/blob - doc/xslt/html/formal.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / html / formal.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 version='1.0'>
4
5 <!-- ********************************************************************
6      $Id: formal.xsl 8806 2010-08-09 18:25:58Z bobstayton $
7      ********************************************************************
8
9      This file is part of the XSL DocBook Stylesheet distribution.
10      See ../README or http://docbook.sf.net/release/xsl/current/ for
11      copyright and other information.
12
13      ******************************************************************** -->
14
15 <xsl:param name="formal.object.break.after">1</xsl:param>
16
17 <xsl:template name="formal.object">
18   <xsl:param name="placement" select="'before'"/>
19   <xsl:param name="class">
20     <xsl:apply-templates select="." mode="class.value"/>
21   </xsl:param>
22
23   <xsl:call-template name="id.warning"/>
24
25   <xsl:variable name="content">
26     <div class="{$class}">
27       <xsl:call-template name="anchor">
28         <xsl:with-param name="conditional" select="0"/>
29       </xsl:call-template>
30     
31       <xsl:choose>
32         <xsl:when test="$placement = 'before'">
33           <xsl:call-template name="formal.object.heading"/>
34           <div class="{$class}-contents">
35             <xsl:apply-templates/>
36           </div>
37           <!-- HACK: This doesn't belong inside formal.object; it 
38                should be done by the table template, but I want 
39                the link to be inside the DIV, so... -->
40           <xsl:if test="local-name(.) = 'table'">
41             <xsl:call-template name="table.longdesc"/>
42           </xsl:if>
43     
44           <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
45         </xsl:when>
46         <xsl:otherwise>
47           <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
48           <div class="{$class}-contents"><xsl:apply-templates/></div>
49           <!-- HACK: This doesn't belong inside formal.object; it 
50                should be done by the table template, but I want 
51                the link to be inside the DIV, so... -->
52           <xsl:if test="local-name(.) = 'table'">
53             <xsl:call-template name="table.longdesc"/>
54           </xsl:if>
55     
56           <xsl:call-template name="formal.object.heading"/>
57         </xsl:otherwise>
58       </xsl:choose>
59     </div>
60     <xsl:if test="not($formal.object.break.after = '0')">
61       <br class="{$class}-break"/>
62     </xsl:if>
63   </xsl:variable>
64
65   <xsl:variable name="floatstyle">
66     <xsl:call-template name="floatstyle"/>
67   </xsl:variable>
68
69   <xsl:choose>
70     <xsl:when test="$floatstyle != ''">
71       <xsl:call-template name="floater">
72         <xsl:with-param name="class"><xsl:value-of 
73                      select="$class"/>-float</xsl:with-param>
74         <xsl:with-param name="floatstyle" select="$floatstyle"/>
75         <xsl:with-param name="content" select="$content"/>
76       </xsl:call-template>
77     </xsl:when>
78     <xsl:otherwise>
79       <xsl:copy-of select="$content"/>
80     </xsl:otherwise>
81   </xsl:choose>
82
83 </xsl:template>
84
85 <xsl:template name="formal.object.heading">
86   <xsl:param name="object" select="."/>
87   <xsl:param name="title">
88     <xsl:apply-templates select="$object" mode="object.title.markup">
89       <xsl:with-param name="allow-anchors" select="1"/>
90     </xsl:apply-templates>
91   </xsl:param>
92
93
94   <xsl:choose>
95     <xsl:when test="$make.clean.html != 0">
96       <xsl:variable name="html.class" select="concat(local-name($object),'-title')"/>
97       <div class="{$html.class}">
98         <xsl:copy-of select="$title"/>
99       </div>
100     </xsl:when>
101     <xsl:otherwise>
102       <p class="title">
103         <b>
104           <xsl:copy-of select="$title"/>
105         </b>
106       </p>
107     </xsl:otherwise>
108   </xsl:choose>
109 </xsl:template>
110
111 <xsl:template name="informal.object">
112   <xsl:param name="class" select="local-name(.)"/>
113
114   <xsl:variable name="content">
115     <div class="{$class}">
116       <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
117       <xsl:call-template name="anchor"/>
118       <xsl:apply-templates/>
119   
120       <!-- HACK: This doesn't belong inside formal.object; it 
121            should be done by the table template, but I want 
122            the link to be inside the DIV, so... -->
123       <xsl:if test="local-name(.) = 'informaltable'">
124         <xsl:call-template name="table.longdesc"/>
125       </xsl:if>
126   
127       <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
128     </div>
129   </xsl:variable>
130
131   <xsl:variable name="floatstyle">
132     <xsl:call-template name="floatstyle"/>
133   </xsl:variable>
134
135   <xsl:choose>
136     <xsl:when test="$floatstyle != ''">
137       <xsl:call-template name="floater">
138         <xsl:with-param name="class"><xsl:value-of 
139                      select="$class"/>-float</xsl:with-param>
140         <xsl:with-param name="floatstyle" select="$floatstyle"/>
141         <xsl:with-param name="content" select="$content"/>
142       </xsl:call-template>
143     </xsl:when>
144     <xsl:otherwise>
145       <xsl:copy-of select="$content"/>
146     </xsl:otherwise>
147   </xsl:choose>
148
149 </xsl:template>
150
151 <xsl:template name="semiformal.object">
152   <xsl:param name="placement" select="'before'"/>
153   <xsl:param name="class" select="local-name(.)"/>
154
155   <xsl:choose>
156     <xsl:when test="title or info/title">
157       <xsl:call-template name="formal.object">
158         <xsl:with-param name="placement" select="$placement"/>
159         <xsl:with-param name="class" select="$class"/>
160       </xsl:call-template>
161     </xsl:when>
162     <xsl:otherwise>
163       <xsl:call-template name="informal.object">
164         <xsl:with-param name="class" select="$class"/>
165       </xsl:call-template>
166     </xsl:otherwise>
167   </xsl:choose>
168 </xsl:template>
169
170 <xsl:template match="figure">
171   <xsl:variable name="param.placement"
172                 select="substring-after(normalize-space($formal.title.placement),
173                                         concat(local-name(.), ' '))"/>
174
175   <xsl:variable name="placement">
176     <xsl:choose>
177       <xsl:when test="contains($param.placement, ' ')">
178         <xsl:value-of select="substring-before($param.placement, ' ')"/>
179       </xsl:when>
180       <xsl:when test="$param.placement = ''">before</xsl:when>
181       <xsl:otherwise>
182         <xsl:value-of select="$param.placement"/>
183       </xsl:otherwise>
184     </xsl:choose>
185   </xsl:variable>
186
187   <xsl:call-template name="formal.object">
188     <xsl:with-param name="placement" select="$placement"/>
189   </xsl:call-template>
190
191 </xsl:template>
192
193 <xsl:template match="table">
194   <xsl:choose>
195     <xsl:when test="tgroup|mediaobject|graphic">
196       <xsl:call-template name="calsTable"/>
197     </xsl:when>
198     <xsl:otherwise>
199       <!-- do not use xsl:copy because of XHTML's needs -->
200       <xsl:element name="table" namespace="">
201         <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
202         <xsl:attribute name="id">
203           <xsl:call-template name="object.id"/>
204         </xsl:attribute>
205         <xsl:call-template name="htmlTable"/>
206       </xsl:element>
207     </xsl:otherwise>
208   </xsl:choose>
209 </xsl:template>
210
211 <xsl:template name="calsTable">
212   <xsl:if test="tgroup/tbody/tr
213                 |tgroup/thead/tr
214                 |tgroup/tfoot/tr">
215     <xsl:message terminate="yes">Broken table: tr descendent of CALS Table.</xsl:message>
216   </xsl:if>
217
218   <xsl:variable name="param.placement"
219                 select="substring-after(normalize-space($formal.title.placement),
220                                         concat(local-name(.), ' '))"/>
221
222   <xsl:variable name="placement">
223     <xsl:choose>
224       <xsl:when test="contains($param.placement, ' ')">
225         <xsl:value-of select="substring-before($param.placement, ' ')"/>
226       </xsl:when>
227       <xsl:when test="$param.placement = ''">before</xsl:when>
228       <xsl:otherwise>
229         <xsl:value-of select="$param.placement"/>
230       </xsl:otherwise>
231     </xsl:choose>
232   </xsl:variable>
233
234   <xsl:call-template name="formal.object">
235     <xsl:with-param name="placement" select="$placement"/>
236     <xsl:with-param name="class">
237       <xsl:choose>
238         <xsl:when test="@tabstyle">
239           <!-- hack, this will only ever occur on table, not example -->
240           <xsl:value-of select="@tabstyle"/>
241         </xsl:when>
242         <xsl:otherwise>
243           <xsl:value-of select="local-name(.)"/>
244         </xsl:otherwise>
245       </xsl:choose>
246     </xsl:with-param>
247   </xsl:call-template>
248 </xsl:template>
249
250 <xsl:template name="htmlTable">
251   <xsl:if test="tgroup/tbody/row
252                 |tgroup/thead/row
253                 |tgroup/tfoot/row">
254     <xsl:message terminate="yes">Broken table: row descendent of HTML table.</xsl:message>
255   </xsl:if>
256
257   <xsl:apply-templates mode="htmlTable"/>
258
259   <xsl:if test=".//footnote|../title//footnote">
260     <tbody class="footnotes">
261       <tr>
262         <td colspan="50">
263           <xsl:apply-templates select=".//footnote|../title//footnote" mode="table.footnote.mode"/>
264         </td>
265       </tr>
266     </tbody>
267   </xsl:if>
268 </xsl:template>
269
270 <xsl:template match="example">
271   <xsl:variable name="param.placement"
272              select="substring-after(normalize-space($formal.title.placement),
273                      concat(local-name(.), ' '))"/>
274
275   <xsl:variable name="placement">
276     <xsl:choose>
277       <xsl:when test="contains($param.placement, ' ')">
278         <xsl:value-of select="substring-before($param.placement, ' ')"/>
279       </xsl:when>
280       <xsl:when test="$param.placement = ''">before</xsl:when>
281       <xsl:otherwise>
282         <xsl:value-of select="$param.placement"/>
283       </xsl:otherwise>
284     </xsl:choose>
285   </xsl:variable>
286
287   <xsl:call-template name="formal.object">
288     <xsl:with-param name="placement" select="$placement"/>
289   </xsl:call-template>
290
291 </xsl:template>
292
293 <xsl:template match="equation">
294   <xsl:variable name="param.placement"
295               select="substring-after(normalize-space($formal.title.placement),
296                                       concat(local-name(.), ' '))"/>
297
298   <xsl:variable name="placement">
299     <xsl:choose>
300       <xsl:when test="contains($param.placement, ' ')">
301         <xsl:value-of select="substring-before($param.placement, ' ')"/>
302       </xsl:when>
303       <xsl:when test="$param.placement = ''">before</xsl:when>
304       <xsl:otherwise>
305         <xsl:value-of select="$param.placement"/>
306       </xsl:otherwise>
307     </xsl:choose>
308   </xsl:variable>
309
310   <xsl:call-template name="formal.object">
311     <xsl:with-param name="placement" select="$placement"/>
312   </xsl:call-template>
313
314 </xsl:template>
315
316 <xsl:template match="figure/title"></xsl:template>
317 <xsl:template match="figure/titleabbrev"></xsl:template>
318 <xsl:template match="table/title"></xsl:template>
319 <xsl:template match="table/titleabbrev"></xsl:template>
320 <xsl:template match="table/textobject"></xsl:template>
321 <xsl:template match="example/title"></xsl:template>
322 <xsl:template match="example/titleabbrev"></xsl:template>
323 <xsl:template match="equation/title"></xsl:template>
324 <xsl:template match="equation/titleabbrev"></xsl:template>
325
326 <xsl:template match="informalfigure">
327   <xsl:call-template name="informal.object"/>
328 </xsl:template>
329
330 <xsl:template match="informalexample">
331   <xsl:call-template name="informal.object"/>
332 </xsl:template>
333
334 <xsl:template match="informaltable">
335   <xsl:choose>
336     <xsl:when test="tgroup|mediaobject|graphic">
337       <xsl:call-template name="informal.object">
338         <xsl:with-param name="class">
339           <xsl:choose>
340             <xsl:when test="@tabstyle">
341               <xsl:value-of select="@tabstyle"/>
342             </xsl:when>
343             <xsl:otherwise>
344               <xsl:value-of select="local-name(.)"/>
345             </xsl:otherwise>
346           </xsl:choose>
347         </xsl:with-param>
348       </xsl:call-template>
349     </xsl:when>
350     <xsl:otherwise>
351       <xsl:element name="table" namespace="">
352         <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
353         <xsl:attribute name="id">
354           <xsl:call-template name="object.id"/>
355         </xsl:attribute>
356         <xsl:call-template name="htmlTable"/>
357       </xsl:element>
358     </xsl:otherwise>
359   </xsl:choose>
360 </xsl:template>
361
362 <xsl:template match="informaltable/textobject"></xsl:template>
363
364 <xsl:template name="table.longdesc">
365   <!-- HACK: This doesn't belong inside formal.objectt; it should be done by -->
366   <!-- the table template, but I want the link to be inside the DIV, so... -->
367   <xsl:variable name="longdesc.uri">
368     <xsl:call-template name="longdesc.uri">
369       <xsl:with-param name="mediaobject" select="."/>
370     </xsl:call-template>
371   </xsl:variable>
372
373   <xsl:variable name="irrelevant">
374     <!-- write.longdesc returns the filename ... -->
375     <xsl:call-template name="write.longdesc">
376       <xsl:with-param name="mediaobject" select="."/>
377     </xsl:call-template>
378   </xsl:variable>
379
380   <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0
381                 and textobject[not(phrase)]">
382     <xsl:call-template name="longdesc.link">
383       <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
384     </xsl:call-template>
385   </xsl:if>
386 </xsl:template>
387
388 <xsl:template match="informalequation">
389   <xsl:call-template name="informal.object"/>
390 </xsl:template>
391
392 <xsl:template name="floatstyle">
393   <xsl:if test="(@float and @float != '0') or @floatstyle != ''">
394     <xsl:choose>
395       <xsl:when test="@floatstyle != ''">
396         <xsl:value-of select="@floatstyle"/>
397       </xsl:when>
398       <xsl:when test="@float = '1'">
399         <xsl:value-of select="$default.float.class"/>
400       </xsl:when>
401       <xsl:otherwise>
402         <xsl:value-of select="@float"/>
403       </xsl:otherwise>
404     </xsl:choose>
405   </xsl:if>
406 </xsl:template>
407
408 <xsl:template name="floater">
409   <xsl:param name="content"/>
410   <xsl:param name="class" select="'float'"/>
411   <xsl:param name="floatstyle" select="'left'"/>
412
413   <div class="{$class}">
414     <xsl:if test="$floatstyle = 'left' or $floatstyle = 'right'">
415       <xsl:attribute name="style">
416         <xsl:text>float: </xsl:text>
417         <xsl:value-of select="$floatstyle"/>
418         <xsl:text>;</xsl:text>
419       </xsl:attribute>
420     </xsl:if>
421     <xsl:copy-of select="$content"/>
422   </div>
423 </xsl:template>
424
425 </xsl:stylesheet>