Debian Codegraph @

xslt/mallard/html/mal2html-table.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:mal="http://projectmallard.org/1.0/"
19 xmlns:ui="http://projectmallard.org/ui/1.0/"
20 xmlns:uix="http://projectmallard.org/experimental/ui/"
21 xmlns:str="http://exslt.org/strings"
22 xmlns="http://www.w3.org/1999/xhtml"
23 exclude-result-prefixes="mal ui uix str"
24 version="1.0">
25
26 <!--!!==========================================================================
27 Mallard to HTML - Table Elements
28
29 REMARK: Describe this module
30 -->
31
32
33 <!-- == Matched Templates == -->
34
35 <!-- = table = -->
36 <xsl:template mode="mal2html.block.mode" match="mal:table">
37 <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if != ''">
38 <xsl:variable name="cols" select="mal:col | mal:colgroup/mal:col"/>
39 <xsl:variable name="style">
40 <xsl:if test="@frame and @frame != 'none'">
41 <xsl:choose>
42 <xsl:when test="@frame = 'all'">
43 <xsl:text>border-style: solid;</xsl:text>
44 </xsl:when>
45 <xsl:otherwise>
46 <xsl:for-each select="str:split(@frame)">
47 <xsl:choose>
48 <xsl:when test=". = 'top'">
49 <xsl:text>border-top-style: solid;</xsl:text>
50 </xsl:when>
51 <xsl:when test=". = 'bottom'">
52 <xsl:text>border-bottom-style: solid;</xsl:text>
53 </xsl:when>
54 <xsl:when test=". = 'left'">
55 <xsl:text>border-left-style: solid;</xsl:text>
56 </xsl:when>
57 <xsl:when test=". = 'right'">
58 <xsl:text>border-right-style: solid;</xsl:text>
59 </xsl:when>
60 </xsl:choose>
61 </xsl:for-each>
62 </xsl:otherwise>
63 </xsl:choose>
64 </xsl:if>
65 </xsl:variable>
66 <xsl:variable name="rowrules">
67 <xsl:choose>
68 <xsl:when test="not(@rules) or @rules = 'none'">
69 <xsl:text>none</xsl:text>
70 </xsl:when>
71 <xsl:when test="@rules = 'all'">
72 <xsl:text>all</xsl:text>
73 </xsl:when>
74 <xsl:when test="@rules = 'groups'">
75 <xsl:text>groups</xsl:text>
76 </xsl:when>
77 <xsl:otherwise>
78 <xsl:for-each select="str:split(@rules)">
79 <xsl:choose>
80 <xsl:when test=". = 'rows'">
81 <xsl:text>all</xsl:text>
82 </xsl:when>
83 <xsl:when test=". = 'rowgroups'">
84 <xsl:text>groups</xsl:text>
85 </xsl:when>
86 </xsl:choose>
87 </xsl:for-each>
88 </xsl:otherwise>
89 </xsl:choose>
90 </xsl:variable>
91 <xsl:variable name="colrules">
92 <xsl:choose>
93 <xsl:when test="not(@rules) or @rules = 'none'">
94 <xsl:text>none</xsl:text>
95 </xsl:when>
96 <xsl:when test="@rules = 'all'">
97 <xsl:text>all</xsl:text>
98 </xsl:when>
99 <xsl:when test="@rules = 'groups'">
100 <xsl:text>groups</xsl:text>
101 </xsl:when>
102 <xsl:otherwise>
103 <xsl:for-each select="str:split(@rules)">
104 <xsl:choose>
105 <xsl:when test=". = 'cols'">
106 <xsl:text>all</xsl:text>
107 </xsl:when>
108 <xsl:when test=". = 'colgroups'">
109 <xsl:text>groups</xsl:text>
110 </xsl:when>
111 </xsl:choose>
112 </xsl:for-each>
113 </xsl:otherwise>
114 </xsl:choose>
115 </xsl:variable>
116 <xsl:variable name="rowshade">
117 <xsl:choose>
118 <xsl:when test="not(@shade) or @shade = 'none'">
119 <xsl:text>none</xsl:text>
120 </xsl:when>
121 <xsl:when test="@shade = 'all'">
122 <xsl:text>all</xsl:text>
123 </xsl:when>
124 <xsl:when test="@shade = 'groups'">
125 <xsl:text>groups</xsl:text>
126 </xsl:when>
127 <xsl:otherwise>
128 <xsl:for-each select="str:split(@shade)">
129 <xsl:choose>
130 <xsl:when test=". = 'rows'">
131 <xsl:text>all</xsl:text>
132 </xsl:when>
133 <xsl:when test=". = 'rowgroups'">
134 <xsl:text>groups</xsl:text>
135 </xsl:when>
136 </xsl:choose>
137 </xsl:for-each>
138 </xsl:otherwise>
139 </xsl:choose>
140 </xsl:variable>
141 <xsl:variable name="colshade">
142 <xsl:choose>
143 <xsl:when test="not(@shade) or @shade = 'none'">
144 <xsl:text>none</xsl:text>
145 </xsl:when>
146 <xsl:when test="@shade = 'all'">
147 <xsl:text>all</xsl:text>
148 </xsl:when>
149 <xsl:when test="@shade = 'groups'">
150 <xsl:text>groups</xsl:text>
151 </xsl:when>
152 <xsl:otherwise>
153 <xsl:for-each select="str:split(@shade)">
154 <xsl:choose>
155 <xsl:when test=". = 'cols'">
156 <xsl:text>all</xsl:text>
157 </xsl:when>
158 <xsl:when test=". = 'colgroups'">
159 <xsl:text>groups</xsl:text>
160 </xsl:when>
161 </xsl:choose>
162 </xsl:for-each>
163 </xsl:otherwise>
164 </xsl:choose>
165 </xsl:variable>
166 <div>
167 <xsl:call-template name="html.class.attr">
168 <xsl:with-param name="class">
169 <xsl:text>table</xsl:text>
170 <xsl:for-each select="str:tokenize(@style)">
171 <xsl:value-of select="concat(' style-', .)"/>
172 </xsl:for-each>
173 <xsl:text> </xsl:text>
174 <xsl:call-template name="mal2html.ui.expander.class"/>
175 <xsl:if test="$if != 'true'">
176 <xsl:text> if-if </xsl:text>
177 <xsl:value-of select="$if"/>
178 </xsl:if>
179 </xsl:with-param>
180 </xsl:call-template>
181 <xsl:call-template name="mal2html.ui.expander.data"/>
182 <div class="inner">
183 <xsl:apply-templates mode="mal2html.block.mode" select="mal:title[1]"/>
184 <div class="region">
185 <xsl:apply-templates mode="mal2html.block.mode" select="mal:desc[1]"/>
186 <table class="table">
187 <xsl:if test="$style != ''">
188 <xsl:attribute name="style">
189 <xsl:value-of select="$style"/>
190 </xsl:attribute>
191 </xsl:if>
192 <xsl:apply-templates select="mal:thead">
193 <xsl:with-param name="cols" select="$cols"/>
194 <xsl:with-param name="rowrules" select="$rowrules"/>
195 <xsl:with-param name="colrules" select="$colrules"/>
196 <xsl:with-param name="rowshade" select="$rowshade"/>
197 <xsl:with-param name="colshade" select="$colshade"/>
198 </xsl:apply-templates>
199 <xsl:apply-templates select="mal:tfoot">
200 <xsl:with-param name="cols" select="$cols"/>
201 <xsl:with-param name="rowrules" select="$rowrules"/>
202 <xsl:with-param name="colrules" select="$colrules"/>
203 <xsl:with-param name="rowshade" select="$rowshade"/>
204 <xsl:with-param name="colshade" select="$colshade"/>
205 </xsl:apply-templates>
206 <xsl:apply-templates select="mal:tr[1] | mal:tbody">
207 <xsl:with-param name="cols" select="$cols"/>
208 <xsl:with-param name="rowrules" select="$rowrules"/>
209 <xsl:with-param name="colrules" select="$colrules"/>
210 <xsl:with-param name="rowshade" select="$rowshade"/>
211 <xsl:with-param name="colshade" select="$colshade"/>
212 </xsl:apply-templates>
213 </table>
214 </div>
215 </div>
216 </div>
217 </xsl:if>
218 </xsl:template>
219
220 <!-- = tbody = -->
221 <xsl:template match="mal:tbody">
222 <xsl:param name="cols"/>
223 <xsl:param name="rowrules"/>
224 <xsl:param name="colrules"/>
225 <xsl:param name="rowshade"/>
226 <xsl:param name="colshade"/>
227 <tbody>
228 <xsl:call-template name="html.class.attr"/>
229 <xsl:call-template name="html.lang.attrs"/>
230 <xsl:apply-templates select="mal:tr[1]">
231 <xsl:with-param name="cols" select="$cols"/>
232 <xsl:with-param name="rowrules" select="$rowrules"/>
233 <xsl:with-param name="colrules" select="$colrules"/>
234 <xsl:with-param name="rowshade" select="$rowshade"/>
235 <xsl:with-param name="colshade" select="$colshade"/>
236 </xsl:apply-templates>
237 </tbody>
238 </xsl:template>
239
240 <!-- = thead = -->
241 <xsl:template match="mal:thead">
242 <xsl:param name="cols"/>
243 <xsl:param name="rowrules"/>
244 <xsl:param name="colrules"/>
245 <xsl:param name="rowshade"/>
246 <xsl:param name="colshade"/>
247 <thead>
248 <xsl:call-template name="html.class.attr"/>
249 <xsl:call-template name="html.lang.attrs"/>
250 <xsl:apply-templates select="mal:tr[1]">
251 <xsl:with-param name="cols" select="$cols"/>
252 <xsl:with-param name="rowrules" select="$rowrules"/>
253 <xsl:with-param name="colrules" select="$colrules"/>
254 <xsl:with-param name="rowshade" select="$rowshade"/>
255 <xsl:with-param name="colshade" select="$colshade"/>
256 </xsl:apply-templates>
257 </thead>
258 </xsl:template>
259
260 <!-- = tfoot = -->
261 <xsl:template match="mal:tfoot">
262 <xsl:param name="cols"/>
263 <xsl:param name="rowrules"/>
264 <xsl:param name="colrules"/>
265 <xsl:param name="rowshade"/>
266 <xsl:param name="colshade"/>
267 <tfoot>
268 <xsl:call-template name="html.class.attr"/>
269 <xsl:call-template name="html.lang.attrs"/>
270 <xsl:apply-templates select="mal:tr[1]">
271 <xsl:with-param name="cols" select="$cols"/>
272 <xsl:with-param name="rowrules" select="$rowrules"/>
273 <xsl:with-param name="colrules" select="$colrules"/>
274 <xsl:with-param name="rowshade" select="$rowshade"/>
275 <xsl:with-param name="colshade" select="$colshade"/>
276 </xsl:apply-templates>
277 </tfoot>
278 </xsl:template>
279
280 <!-- = tr = -->
281 <xsl:template match="mal:tr">
282 <xsl:param name="cols"/>
283 <xsl:param name="rowrules"/>
284 <xsl:param name="colrules"/>
285 <xsl:param name="rowshade"/>
286 <xsl:param name="colshade"/>
287 <xsl:param name="rowspans">
288 <xsl:for-each select="mal:td | mal:th">
289 <xsl:text>0:</xsl:text>
290 <xsl:if test="@colspan">
291 <xsl:call-template name="utils.repeat_string">
292 <xsl:with-param name="string" select="'0:'"/>
293 <xsl:with-param name="number" select="number(@colspan) - 1"/>
294 </xsl:call-template>
295 </xsl:if>
296 </xsl:for-each>
297 </xsl:param>
298 <xsl:variable name="trpos" select="count(preceding-sibling::mal:tr) + 1"/>
299 <xsl:variable name="shaderow">
300 <xsl:choose>
301 <xsl:when test="$rowshade = 'all'">
302 <xsl:choose>
303 <xsl:when test="../self::mal:table">
304 <xsl:value-of select="($trpos + 1) mod 2"/>
305 </xsl:when>
306 <xsl:otherwise>
307 <xsl:variable name="bodies"
308 select="../preceding-sibling::mal:tbody |
309 ../preceding-sibling::mal:thead "/>
310 <xsl:variable name="trcount" select="count($bodies/mal:tr) + $trpos"/>
311 <xsl:value-of select="($trcount + 1) mod 2"/>
312 </xsl:otherwise>
313 </xsl:choose>
314 </xsl:when>
315 <xsl:when test="$rowshade = 'groups'">
316 <xsl:variable name="bodies"
317 select="../preceding-sibling::mal:tbody |
318 ../preceding-sibling::mal:thead "/>
319 <xsl:value-of select="count($bodies) mod 2"/>
320 </xsl:when>
321 </xsl:choose>
322 </xsl:variable>
323 <tr>
324 <xsl:call-template name="html.class.attr">
325 <xsl:with-param name="class">
326 <xsl:if test="$shaderow = 1">
327 <xsl:text>shade</xsl:text>
328 </xsl:if>
329 </xsl:with-param>
330 </xsl:call-template>
331 <xsl:apply-templates select="mal:td | mal:th">
332 <xsl:with-param name="cols" select="$cols"/>
333 <xsl:with-param name="rowrules" select="$rowrules"/>
334 <xsl:with-param name="colrules" select="$colrules"/>
335 <xsl:with-param name="rowshade" select="$rowshade"/>
336 <xsl:with-param name="colshade" select="$colshade"/>
337 <xsl:with-param name="rowspans" select="$rowspans"/>
338 </xsl:apply-templates>
339 </tr>
340 <xsl:apply-templates select="following-sibling::mal:tr[1]">
341 <xsl:with-param name="cols" select="$cols"/>
342 <xsl:with-param name="rowrules" select="$rowrules"/>
343 <xsl:with-param name="colrules" select="$colrules"/>
344 <xsl:with-param name="rowshade" select="$rowshade"/>
345 <xsl:with-param name="colshade" select="$colshade"/>
346 <xsl:with-param name="rowspans">
347 <xsl:call-template name="rowspans">
348 <xsl:with-param name="spans" select="str:split($rowspans, ':')"/>
349 </xsl:call-template>
350 </xsl:with-param>
351 </xsl:apply-templates>
352 </xsl:template>
353
354 <!--#* rowspans -->
355 <xsl:template name="rowspans">
356 <xsl:param name="spans"/>
357 <xsl:param name="pos" select="1"/>
358 <xsl:param name="td" select="(mal:td | mal:th)[1]"/>
359 <xsl:param name="times" select="1"/>
360 <xsl:variable name="span" select="number($spans[$pos])"/>
361
362 <xsl:choose>
363 <xsl:when test="$span &gt; 1">
364 <xsl:value-of select="$span - 1"/>
365 <xsl:text>:</xsl:text>
366 <xsl:if test="$pos &lt; count($spans)">
367 <xsl:call-template name="rowspans">
368 <xsl:with-param name="spans" select="$spans"/>
369 <xsl:with-param name="pos" select="$pos + 1"/>
370 <xsl:with-param name="td" select="$td"/>
371 </xsl:call-template>
372 </xsl:if>
373 </xsl:when>
374 <xsl:otherwise>
375 <xsl:variable name="rowspan">
376 <xsl:choose>
377 <xsl:when test="$td/@rowspan">
378 <xsl:value-of select="number($td/@rowspan)"/>
379 </xsl:when>
380 <xsl:otherwise>
381 <xsl:value-of select="1"/>
382 </xsl:otherwise>
383 </xsl:choose>
384 </xsl:variable>
385 <xsl:variable name="colspan">
386 <xsl:choose>
387 <xsl:when test="$td/@colspan">
388 <xsl:value-of select="number($td/@colspan)"/>
389 </xsl:when>
390 <xsl:otherwise>
391 <xsl:value-of select="1"/>
392 </xsl:otherwise>
393 </xsl:choose>
394 </xsl:variable>
395 <xsl:call-template name="utils.repeat_string">
396 <xsl:with-param name="string">
397 <xsl:value-of select="$rowspan - 1"/>
398 <xsl:text>:</xsl:text>
399 </xsl:with-param>
400 <xsl:with-param name="number" select="$colspan"/>
401 </xsl:call-template>
402 <xsl:variable name="nextpos" select="$pos + $colspan"/>
403 <xsl:if test="$nextpos &lt;= count($spans)">
404 <xsl:call-template name="rowspans">
405 <xsl:with-param name="spans" select="$spans"/>
406 <xsl:with-param name="pos" select="$nextpos"/>
407 <xsl:with-param name="td" select="($td/following-sibling::mal:td | $td/following-sibling::mal:th)[1]"/>
408 </xsl:call-template>
409 </xsl:if>
410 </xsl:otherwise>
411 </xsl:choose>
412 </xsl:template>
413
414 <!-- = td | th = -->
415 <xsl:template match="mal:td | mal:th">
416 <xsl:param name="cols"/>
417 <xsl:param name="rowrules"/>
418 <xsl:param name="colrules"/>
419 <xsl:param name="rowshade"/>
420 <xsl:param name="colshade"/>
421 <xsl:param name="rowspans"/>
422 <xsl:variable name="trpos" select="count(../preceding-sibling::mal:tr) + 1"/>
423 <xsl:variable name="tdcnt" select="count(preceding-sibling::mal:td) + count(preceding-sibling::mal:th) + 1"/>
424 <xsl:variable name="spans" select="str:split($rowspans, ':')"/>
425 <xsl:variable name="tdstr">
426 <xsl:for-each select="$spans[. = '0'][$tdcnt]/preceding-sibling::*[not(. = '0')]">
427 <xsl:text>.</xsl:text>
428 </xsl:for-each>
429 <xsl:for-each select="preceding-sibling::mal:td | preceding-sibling::mal:th">
430 <xsl:text>.</xsl:text>
431 <xsl:if test="@colspan">
432 <xsl:call-template name="utils.repeat_string">
433 <xsl:with-param name="string" select="'.'"/>
434 <xsl:with-param name="number" select="number(@colspan) - 1"/>
435 </xsl:call-template>
436 </xsl:if>
437 </xsl:for-each>
438 </xsl:variable>
439 <xsl:variable name="tdpos" select="string-length($tdstr) + 1"/>
440 <xsl:variable name="shadecol">
441 <xsl:choose>
442 <xsl:when test="$colshade = 'all'">
443 <xsl:value-of select="($tdpos + 1) mod 2"/>
444 </xsl:when>
445 <xsl:when test="$colshade = 'groups'">
446 <xsl:if test="count($cols) &gt;= $tdpos">
447 <xsl:variable name="col" select="$cols[$tdpos]"/>
448 <xsl:if test="$col/../self::mal:colgroup">
449 <xsl:value-of
450 select="count($col/../preceding-sibling::mal:colgroup) mod 2"/>
451 </xsl:if>
452 </xsl:if>
453 <!-- FIXME -->
454 </xsl:when>
455 </xsl:choose>
456 </xsl:variable>
457 <xsl:variable name="style">
458 <xsl:choose>
459 <xsl:when test="$rowrules = 'all'">
460 <xsl:choose>
461 <xsl:when test="../../self::mal:table">
462 <xsl:if test="$trpos != 1">
463 <xsl:text>border-top-style: solid;</xsl:text>
464 </xsl:if>
465 </xsl:when>
466 <xsl:when test="$trpos != 1 or
467 ../../preceding-sibling::mal:thead or
468 ../../preceding-sibling::mal:tbody ">
469 <xsl:text>border-top-style: solid;</xsl:text>
470 </xsl:when>
471 </xsl:choose>
472 </xsl:when>
473 <xsl:when test="$rowrules = 'groups'">
474 <xsl:if test="$trpos = 1">
475 <xsl:choose>
476 <xsl:when test="../../self::mal:tbody">
477 <xsl:if test="../../../mal:thead | ../../preceding-sibling::mal:tbody">
478 <xsl:text>border-top-style: solid;</xsl:text>
479 </xsl:if>
480 </xsl:when>
481 <xsl:when test="../../self::mal:tfoot">
482 <xsl:text>border-top-style: solid;</xsl:text>
483 </xsl:when>
484 </xsl:choose>
485 </xsl:if>
486 </xsl:when>
487 </xsl:choose>
488 <xsl:choose>
489 <xsl:when test="$tdpos = 1"/>
490 <xsl:when test="$colrules = 'all'">
491 <xsl:text>border-left-style: solid;</xsl:text>
492 </xsl:when>
493 <xsl:when test="$colrules = 'groups'">
494 <xsl:if test="count($cols) &gt;= $tdpos">
495 <xsl:variable name="col" select="$cols[$tdpos]"/>
496 <xsl:if test="$col/../self::mal:colgroup and
497 not($col/preceding-sibling::mal:col)">
498 <xsl:text>border-left-style: solid;</xsl:text>
499 </xsl:if>
500 </xsl:if>
501 </xsl:when>
502 </xsl:choose>
503 </xsl:variable>
504 <xsl:element name="{local-name(.)}" namespace="{$html.namespace}">
505 <xsl:call-template name="html.class.attr">
506 <xsl:with-param name="class">
507 <xsl:if test="$shadecol = 1">
508 <xsl:text>shade</xsl:text>
509 </xsl:if>
510 </xsl:with-param>
511 </xsl:call-template>
512 <xsl:if test="$style != ''">
513 <xsl:attribute name="style">
514 <xsl:value-of select="$style"/>
515 </xsl:attribute>
516 </xsl:if>
517 <xsl:if test="@colspan">
518 <xsl:attribute name="colspan">
519 <xsl:value-of select="@colspan"/>
520 </xsl:attribute>
521 </xsl:if>
522 <xsl:if test="@rowspan">
523 <xsl:attribute name="rowspan">
524 <xsl:value-of select="@rowspan"/>
525 </xsl:attribute>
526 </xsl:if>
527 <xsl:if test="self::mal:th/@scope">
528 <xsl:attribute name="scope">
529 <xsl:value-of select="@scope"/>
530 </xsl:attribute>
531 </xsl:if>
532 <xsl:apply-templates mode="mal2html.block.mode"/>
533 </xsl:element>
534 </xsl:template>
535
536 </xsl:stylesheet>