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