~ubuntu-branches/ubuntu/lucid/gnome-doc-utils/lucid

« back to all changes in this revision

Viewing changes to xslt/mallard/html/mal2html-table.xsl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-06-15 11:03:13 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20090615110313-b4vn2m00muam19tc
Tags: 0.17.1-0ubuntu1
* New upstream release: (LP: #387210)
  - Integrated Mallard support
  - Fix file-not-found warnings from config.status (Christian Persch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, write to the
 
15
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
16
02111-1307, USA.
 
17
-->
 
18
 
 
19
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
20
                xmlns:mal="http://projectmallard.org/1.0/"
 
21
                xmlns:str="http://exslt.org/strings"
 
22
                xmlns="http://www.w3.org/1999/xhtml"
 
23
                extension-element-prefixes="str"
 
24
                version="1.0">
 
25
 
 
26
<!--!!==========================================================================
 
27
Mallard to HTML - Table Elements
 
28
 
 
29
REMARK: Describe this module
 
30
-->
 
31
 
 
32
 
 
33
<!--**==========================================================================
 
34
mal2html.table.css
 
35
Outputs CSS that controls the appearance of tables
 
36
 
 
37
REMARK: Describe this template
 
38
-->
 
39
<xsl:template name="mal2html.table.css">
 
40
<xsl:text>
 
41
table.table {
 
42
  border-collapse: collapse;
 
43
  border-color: #555753;
 
44
  border-width: 1px;
 
45
}
 
46
table.table td {
 
47
  padding: 0.1em 0.5em 0.1em 0.5em;
 
48
  border-color: #888a85;
 
49
  border-width: 1px;
 
50
  vertical-align: top;
 
51
}
 
52
</xsl:text>
 
53
</xsl:template>
 
54
 
 
55
 
 
56
<!-- == Matched Templates == -->
 
57
 
 
58
<!-- = table = -->
 
59
<xsl:template mode="mal2html.block.mode" match="mal:table">
 
60
  <xsl:variable name="cols" select="mal:col | mal:colgroup/mal:col"/>
 
61
  <xsl:variable name="style">
 
62
    <xsl:if test="@frame and @frame != 'none'">
 
63
      <xsl:choose>
 
64
        <xsl:when test="@frame = 'all'">
 
65
          <xsl:text>border-style: solid;</xsl:text>
 
66
        </xsl:when>
 
67
        <xsl:otherwise>
 
68
          <xsl:for-each select="str:split(@frame)">
 
69
            <xsl:choose>
 
70
              <xsl:when test=". = 'top'">
 
71
                <xsl:text>border-top-style: solid;</xsl:text>
 
72
              </xsl:when>
 
73
              <xsl:when test=". = 'bottom'">
 
74
                <xsl:text>border-bottom-style: solid;</xsl:text>
 
75
              </xsl:when>
 
76
              <xsl:when test=". = 'left'">
 
77
                <xsl:text>border-left-style: solid;</xsl:text>
 
78
              </xsl:when>
 
79
              <xsl:when test=". = 'right'">
 
80
                <xsl:text>border-right-style: solid;</xsl:text>
 
81
              </xsl:when>
 
82
            </xsl:choose>
 
83
          </xsl:for-each>
 
84
        </xsl:otherwise>
 
85
      </xsl:choose>
 
86
    </xsl:if>
 
87
  </xsl:variable>
 
88
  <xsl:variable name="rowrules">
 
89
    <xsl:choose>
 
90
      <xsl:when test="not(@rules) or @rules = 'none'">
 
91
        <xsl:text>none</xsl:text>
 
92
      </xsl:when>
 
93
      <xsl:when test="@rules = 'all'">
 
94
        <xsl:text>all</xsl:text>
 
95
      </xsl:when>
 
96
      <xsl:when test="@rules = 'groups'">
 
97
        <xsl:text>groups</xsl:text>
 
98
      </xsl:when>
 
99
      <xsl:otherwise>
 
100
        <xsl:for-each select="str:split(@rules)">
 
101
          <xsl:choose>
 
102
            <xsl:when test=". = 'rows'">
 
103
              <xsl:text>all</xsl:text>
 
104
            </xsl:when>
 
105
            <xsl:when test=". = 'rowgroups'">
 
106
              <xsl:text>groups</xsl:text>
 
107
            </xsl:when>
 
108
          </xsl:choose>
 
109
        </xsl:for-each>
 
110
      </xsl:otherwise>
 
111
    </xsl:choose>
 
112
  </xsl:variable>
 
113
  <xsl:variable name="colrules">
 
114
    <xsl:choose>
 
115
      <xsl:when test="not(@rules) or @rules = 'none'">
 
116
        <xsl:text>none</xsl:text>
 
117
      </xsl:when>
 
118
      <xsl:when test="@rules = 'all'">
 
119
        <xsl:text>all</xsl:text>
 
120
      </xsl:when>
 
121
      <xsl:when test="@rules = 'groups'">
 
122
        <xsl:text>groups</xsl:text>
 
123
      </xsl:when>
 
124
      <xsl:otherwise>
 
125
        <xsl:for-each select="str:split(@rules)">
 
126
          <xsl:choose>
 
127
            <xsl:when test=". = 'cols'">
 
128
              <xsl:text>all</xsl:text>
 
129
            </xsl:when>
 
130
            <xsl:when test=". = 'colgroups'">
 
131
              <xsl:text>groups</xsl:text>
 
132
            </xsl:when>
 
133
          </xsl:choose>
 
134
        </xsl:for-each>
 
135
      </xsl:otherwise>
 
136
    </xsl:choose>
 
137
  </xsl:variable>
 
138
  <xsl:variable name="rowshade">
 
139
    <xsl:choose>
 
140
      <xsl:when test="not(@shade) or @shade = 'none'">
 
141
        <xsl:text>none</xsl:text>
 
142
      </xsl:when>
 
143
      <xsl:when test="@shade = 'all'">
 
144
        <xsl:text>all</xsl:text>
 
145
      </xsl:when>
 
146
      <xsl:when test="@shade = 'groups'">
 
147
        <xsl:text>groups</xsl:text>
 
148
      </xsl:when>
 
149
      <xsl:otherwise>
 
150
        <xsl:for-each select="str:split(@shade)">
 
151
          <xsl:choose>
 
152
            <xsl:when test=". = 'rows'">
 
153
              <xsl:text>all</xsl:text>
 
154
            </xsl:when>
 
155
            <xsl:when test=". = 'rowgroups'">
 
156
              <xsl:text>groups</xsl:text>
 
157
            </xsl:when>
 
158
          </xsl:choose>
 
159
        </xsl:for-each>
 
160
      </xsl:otherwise>
 
161
    </xsl:choose>
 
162
  </xsl:variable>
 
163
  <xsl:variable name="colshade">
 
164
    <xsl:choose>
 
165
      <xsl:when test="not(@shade) or @shade = 'none'">
 
166
        <xsl:text>none</xsl:text>
 
167
      </xsl:when>
 
168
      <xsl:when test="@shade = 'all'">
 
169
        <xsl:text>all</xsl:text>
 
170
      </xsl:when>
 
171
      <xsl:when test="@shade = 'groups'">
 
172
        <xsl:text>groups</xsl:text>
 
173
      </xsl:when>
 
174
      <xsl:otherwise>
 
175
        <xsl:for-each select="str:split(@shade)">
 
176
          <xsl:choose>
 
177
            <xsl:when test=". = 'cols'">
 
178
              <xsl:text>all</xsl:text>
 
179
            </xsl:when>
 
180
            <xsl:when test=". = 'colgroups'">
 
181
              <xsl:text>groups</xsl:text>
 
182
            </xsl:when>
 
183
          </xsl:choose>
 
184
        </xsl:for-each>
 
185
      </xsl:otherwise>
 
186
    </xsl:choose>
 
187
  </xsl:variable>
 
188
  <div>
 
189
    <xsl:attribute name="class">
 
190
      <xsl:text>table</xsl:text>
 
191
      <xsl:if test="not(preceding-sibling::*)">
 
192
        <xsl:text> first-child</xsl:text>
 
193
      </xsl:if>
 
194
    </xsl:attribute>
 
195
    <table class="table">
 
196
      <xsl:if test="$style != ''">
 
197
        <xsl:attribute name="style">
 
198
          <xsl:value-of select="$style"/>
 
199
        </xsl:attribute>
 
200
      </xsl:if>
 
201
      <xsl:apply-templates select="mal:thead">
 
202
        <xsl:with-param name="cols" select="$cols"/>
 
203
        <xsl:with-param name="rowrules" select="$rowrules"/>
 
204
        <xsl:with-param name="colrules" select="$colrules"/>
 
205
        <xsl:with-param name="rowshade" select="$rowshade"/>
 
206
        <xsl:with-param name="colshade" select="$colshade"/>
 
207
      </xsl:apply-templates>
 
208
      <xsl:apply-templates select="mal:tfoot">
 
209
        <xsl:with-param name="cols" select="$cols"/>
 
210
        <xsl:with-param name="rowrules" select="$rowrules"/>
 
211
        <xsl:with-param name="colrules" select="$colrules"/>
 
212
        <xsl:with-param name="rowshade" select="$rowshade"/>
 
213
        <xsl:with-param name="colshade" select="$colshade"/>
 
214
      </xsl:apply-templates>
 
215
      <xsl:apply-templates select="mal:tr | mal:tbody">
 
216
        <xsl:with-param name="cols" select="$cols"/>
 
217
        <xsl:with-param name="rowrules" select="$rowrules"/>
 
218
        <xsl:with-param name="colrules" select="$colrules"/>
 
219
        <xsl:with-param name="rowshade" select="$rowshade"/>
 
220
        <xsl:with-param name="colshade" select="$colshade"/>
 
221
      </xsl:apply-templates>
 
222
    </table>
 
223
  </div>
 
224
</xsl:template>
 
225
 
 
226
<!-- = tbody = -->
 
227
<xsl:template match="mal:tbody">
 
228
  <xsl:param name="cols"/>
 
229
  <xsl:param name="rowrules"/>
 
230
  <xsl:param name="colrules"/>
 
231
  <xsl:param name="rowshade"/>
 
232
  <xsl:param name="colshade"/>
 
233
  <tbody>
 
234
    <xsl:apply-templates select="mal:tr">
 
235
      <xsl:with-param name="cols" select="$cols"/>
 
236
      <xsl:with-param name="rowrules" select="$rowrules"/>
 
237
      <xsl:with-param name="colrules" select="$colrules"/>
 
238
      <xsl:with-param name="rowshade" select="$rowshade"/>
 
239
      <xsl:with-param name="colshade" select="$colshade"/>
 
240
    </xsl:apply-templates>
 
241
  </tbody>
 
242
</xsl:template>
 
243
 
 
244
<!-- = thead = -->
 
245
<xsl:template match="mal:thead">
 
246
  <xsl:param name="cols"/>
 
247
  <xsl:param name="rowrules"/>
 
248
  <xsl:param name="colrules"/>
 
249
  <xsl:param name="rowshade"/>
 
250
  <xsl:param name="colshade"/>
 
251
  <thead>
 
252
    <xsl:apply-templates select="mal:tr">
 
253
      <xsl:with-param name="cols" select="$cols"/>
 
254
      <xsl:with-param name="rowrules" select="$rowrules"/>
 
255
      <xsl:with-param name="colrules" select="$colrules"/>
 
256
      <xsl:with-param name="rowshade" select="$rowshade"/>
 
257
      <xsl:with-param name="colshade" select="$colshade"/>
 
258
    </xsl:apply-templates>
 
259
  </thead>
 
260
</xsl:template>
 
261
 
 
262
<!-- = tfoot = -->
 
263
<xsl:template match="mal:tfoot">
 
264
  <xsl:param name="cols"/>
 
265
  <xsl:param name="rowrules"/>
 
266
  <xsl:param name="colrules"/>
 
267
  <xsl:param name="rowshade"/>
 
268
  <xsl:param name="colshade"/>
 
269
  <tfoot>
 
270
    <xsl:apply-templates select="mal:tr">
 
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
  <tr>
 
288
    <xsl:apply-templates select="mal:td">
 
289
      <xsl:with-param name="cols" select="$cols"/>
 
290
      <xsl:with-param name="rowrules" select="$rowrules"/>
 
291
      <xsl:with-param name="colrules" select="$colrules"/>
 
292
      <xsl:with-param name="rowshade" select="$rowshade"/>
 
293
      <xsl:with-param name="colshade" select="$colshade"/>
 
294
    </xsl:apply-templates>
 
295
  </tr>
 
296
</xsl:template>
 
297
 
 
298
<!-- = td = -->
 
299
<xsl:template match="mal:td">
 
300
  <xsl:param name="cols"/>
 
301
  <xsl:param name="rowrules"/>
 
302
  <xsl:param name="colrules"/>
 
303
  <xsl:param name="rowshade"/>
 
304
  <xsl:param name="colshade"/>
 
305
  <xsl:variable name="trpos" select="count(../preceding-sibling::mal:tr) + 1"/>
 
306
  <xsl:variable name="tdpos" select="count(preceding-sibling::mal:td) + 1"/>
 
307
  <!-- FIXME: this all breaks with rowspan/colspan -->
 
308
  <xsl:variable name="shaderow">
 
309
    <xsl:choose>
 
310
      <xsl:when test="$rowshade = 'all'">
 
311
        <xsl:choose>
 
312
          <xsl:when test="../../self::mal:table">
 
313
            <xsl:value-of select="($trpos + 1) mod 2"/>
 
314
          </xsl:when>
 
315
          <xsl:otherwise>
 
316
            <xsl:variable name="bodies"
 
317
                          select="../../preceding-sibling::mal:tbody |
 
318
                                  ../../preceding-sibling::mal:thead "/>
 
319
            <xsl:variable name="trcount" select="count($bodies/mal:tr) + $trpos"/>
 
320
            <xsl:value-of select="($trcount + 1) mod 2"/>
 
321
          </xsl:otherwise>
 
322
        </xsl:choose>
 
323
      </xsl:when>
 
324
      <xsl:when test="$rowshade = 'groups'">
 
325
        <xsl:variable name="bodies"
 
326
                      select="../../preceding-sibling::mal:tbody |
 
327
                              ../../preceding-sibling::mal:thead "/>
 
328
        <xsl:value-of select="count($bodies) mod 2"/>
 
329
      </xsl:when>
 
330
    </xsl:choose>
 
331
  </xsl:variable>
 
332
  <xsl:variable name="shadecol">
 
333
    <xsl:choose>
 
334
      <xsl:when test="$colshade = 'all'">
 
335
        <xsl:value-of select="($tdpos + 1) mod 2"/>
 
336
      </xsl:when>
 
337
      <xsl:when test="$colshade = 'groups'">
 
338
        <xsl:if test="count($cols) &gt;= $tdpos">
 
339
          <xsl:variable name="col" select="$cols[$tdpos]"/>
 
340
          <xsl:if test="$col/../self::mal:colgroup">
 
341
            <xsl:value-of
 
342
                select="count($col/../preceding-sibling::mal:colgroup) mod 2"/>
 
343
          </xsl:if>
 
344
        </xsl:if>
 
345
        <!-- FIXME -->
 
346
      </xsl:when>
 
347
    </xsl:choose>
 
348
  </xsl:variable>
 
349
  <xsl:variable name="style">
 
350
    <xsl:choose>
 
351
      <xsl:when test="$rowrules = 'all'">
 
352
        <xsl:choose>
 
353
          <xsl:when test="../../self::mal:table">
 
354
            <xsl:if test="$trpos != 1">
 
355
              <xsl:text>border-top-style: solid;</xsl:text>
 
356
            </xsl:if>
 
357
          </xsl:when>
 
358
          <xsl:when test="$trpos != 1 or
 
359
                          ../../preceding-sibling::mal:thead or
 
360
                          ../../preceding-sibling::mal:tbody ">
 
361
            <xsl:text>border-top-style: solid;</xsl:text>
 
362
          </xsl:when>
 
363
        </xsl:choose>
 
364
      </xsl:when>
 
365
      <xsl:when test="$rowrules = 'groups'">
 
366
        <xsl:if test="$trpos = 1">
 
367
          <xsl:choose>
 
368
            <xsl:when test="../../self::mal:tbody">
 
369
              <xsl:if test="../../../mal:thead | ../../preceding-sibling::mal:tbody">
 
370
                <xsl:text>border-top-style: solid;</xsl:text>
 
371
              </xsl:if>
 
372
            </xsl:when>
 
373
            <xsl:when test="../../self::mal:tfoot">
 
374
              <xsl:text>border-top-style: solid;</xsl:text>
 
375
            </xsl:when>
 
376
          </xsl:choose>
 
377
        </xsl:if>
 
378
      </xsl:when>
 
379
    </xsl:choose>
 
380
    <xsl:choose>
 
381
      <xsl:when test="$tdpos = 1"/>
 
382
      <xsl:when test="$colrules = 'all'">
 
383
        <xsl:text>border-left-style: solid;</xsl:text>
 
384
      </xsl:when>
 
385
      <xsl:when test="$colrules = 'groups'">
 
386
        <xsl:if test="count($cols) &gt;= $tdpos">
 
387
          <xsl:variable name="col" select="$cols[$tdpos]"/>
 
388
          <xsl:if test="$col/../self::mal:colgroup and
 
389
                        not($col/preceding-sibling::mal:col)">
 
390
            <xsl:text>border-left-style: solid;</xsl:text>
 
391
          </xsl:if>
 
392
        </xsl:if>
 
393
      </xsl:when>
 
394
    </xsl:choose>
 
395
    <xsl:choose>
 
396
      <xsl:when test="$shaderow = 1 and $shadecol = 1">
 
397
        <xsl:text>background-color: #d3d7cf;</xsl:text>
 
398
      </xsl:when>
 
399
      <xsl:when test="$shaderow = 1 or $shadecol = 1">
 
400
        <xsl:text>background-color: #eeeeec;</xsl:text>
 
401
      </xsl:when>
 
402
    </xsl:choose>
 
403
  </xsl:variable>
 
404
  <td>
 
405
    <xsl:if test="$style != ''">
 
406
      <xsl:attribute name="style">
 
407
        <xsl:value-of select="$style"/>
 
408
      </xsl:attribute>
 
409
    </xsl:if>
 
410
    <xsl:if test="@colspan">
 
411
      <xsl:attribute name="colspan">
 
412
        <xsl:value-of select="@colspan"/>
 
413
      </xsl:attribute>
 
414
    </xsl:if>
 
415
    <xsl:if test="@rowspan">
 
416
      <xsl:attribute name="rowspan">
 
417
        <xsl:value-of select="@rowspan"/>
 
418
      </xsl:attribute>
 
419
    </xsl:if>
 
420
    <xsl:apply-templates mode="mal2html.block.mode"/>
 
421
  </td>
 
422
</xsl:template>
 
423
 
 
424
</xsl:stylesheet>