1
<?xml version="1.0" encoding="UTF-8"?>
4
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
Copyright 2008 by Sun Microsystems, Inc.
8
OpenOffice.org - a multi-platform office productivity suite
10
$RCSfile: table_of_content.xsl,v $
14
This file is part of OpenOffice.org.
16
OpenOffice.org is free software: you can redistribute it and/or modify
17
it under the terms of the GNU Lesser General Public License version 3
18
only, as published by the Free Software Foundation.
20
OpenOffice.org is distributed in the hope that it will be useful,
21
but WITHOUT ANY WARRANTY; without even the implied warranty of
22
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
GNU Lesser General Public License version 3 for more details
24
(a copy is included in the LICENSE file that accompanied this code).
26
You should have received a copy of the GNU Lesser General Public License
27
version 3 along with OpenOffice.org. If not, see
28
<http://www.openoffice.org/license.html>
29
for a copy of the LGPLv3 License.
33
For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
35
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://xml.apache.org/xslt/java" xmlns:sxg="http://www.jclark.com/xt/java/org.openoffice.xslt.OOoMasterDocument" xmlns:common="http://exslt.org/common" xmlns:xt="http://www.jclark.com/xt" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi java sxg xt common xalan">
37
<!-- ****************************** -->
38
<!-- *** Table of Content *** -->
39
<!-- ****************************** -->
41
<xsl:param name="currentChildContentRef" />
42
<xsl:param name="contentTableHeadings" />
43
<xsl:param name="contentTableURL" />
44
<xsl:template match="text:table-of-content">
45
<xsl:param name="globalData"/>
48
<xsl:with-param name="globalData" select="$globalData"/>
49
</xsl:apply-templates>
53
<xsl:template match="text:index-body">
54
<xsl:param name="globalData"/>
57
<xsl:when test="*/text:tab">
58
<xsl:call-template name="createIndexBodyTable">
59
<xsl:with-param name="globalData" select="$globalData"/>
64
<xsl:with-param name="globalData" select="$globalData"/>
65
</xsl:apply-templates>
70
<xsl:template match="text:index-title" mode="content-table">
71
<xsl:param name="globalData"/>
74
<xsl:with-param name="globalData" select="$globalData"/>
75
</xsl:apply-templates>
78
<xsl:template name="createIndexBodyTable">
79
<xsl:param name="globalData"/>
80
<xsl:variable name="allStyleTabStops-RTF">
81
<xsl:element name="style:tab-stops">
82
<xsl:call-template name="get-tab-stops">
83
<xsl:with-param name="globalData" select="$globalData"/>
84
<xsl:with-param name="styleName" select="current()/@text:style-name"/>
87
Currently only the style of text:index-body is recognized, but not of a paragraph child containing the text:tab element!
88
<xsl:with-param name="styleName" select="descendant-or-self::*/@text:style-name"/>
90
The column width needs to be tabstop plus fo:margin-left paragraph-properties
95
<xsl:element namespace="{$namespace}" name="table">
97
<xsl:attribute name="border">0</xsl:attribute>
98
<xsl:attribute name="cellspacing">0</xsl:attribute>
99
<xsl:attribute name="cellpadding">0</xsl:attribute>
100
<xsl:variable name="value" select="$globalData/all-doc-styles/style[@style:name = current()/@table:style-name]/*/@style:rel-width"/>
101
<xsl:if test="$value">
102
<xsl:attribute name="width">
103
<xsl:value-of select="$value"/>
106
<xsl:attribute name="class">
107
<xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
110
<xsl:element namespace="{$namespace}" name="colgroup">
112
<xsl:when test="function-available('common:node-set')">
113
<xsl:call-template name="create-col-element">
114
<xsl:with-param name="lastNodePosition" select="count(common:node-set($allStyleTabStops-RTF)/style:tab-stops/style:tab-stop)"/>
115
<xsl:with-param name="allStyleTabStops" select="common:node-set($allStyleTabStops-RTF)"/>
118
<xsl:when test="function-available('xalan:nodeset')">
119
<xsl:call-template name="create-col-element">
120
<xsl:with-param name="lastNodePosition" select="count(xalan:nodeset($allStyleTabStops-RTF)/style:tab-stops/style:tab-stop)"/>
121
<xsl:with-param name="allStyleTabStops" select="xalan:nodeset($allStyleTabStops-RTF)"/>
124
<xsl:when test="function-available('xt:node-set')">
125
<xsl:call-template name="create-col-element">
126
<xsl:with-param name="lastNodePosition" select="count(xt:node-set($allStyleTabStops-RTF)/style:tab-stops/style:tab-stop)"/>
127
<xsl:with-param name="allStyleTabStops" select="xt:node-set($allStyleTabStops-RTF)"/>
131
<xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
136
<!-- add table data -->
138
<xsl:when test="function-available('common:node-set')">
139
<xsl:apply-templates mode="content-table">
140
<xsl:with-param name="globalData" select="$globalData"/>
141
<xsl:with-param name="allStyleTabStops" select="common:node-set($allStyleTabStops-RTF)"/>
142
</xsl:apply-templates>
144
<xsl:when test="function-available('xalan:nodeset')">
145
<xsl:apply-templates mode="content-table">
146
<xsl:with-param name="globalData" select="$globalData"/>
147
<xsl:with-param name="allStyleTabStops" select="xalan:nodeset($allStyleTabStops-RTF)"/>
148
</xsl:apply-templates>
150
<xsl:when test="function-available('xt:node-set')">
151
<xsl:apply-templates mode="content-table">
152
<xsl:with-param name="globalData" select="$globalData"/>
153
<xsl:with-param name="allStyleTabStops" select="xt:node-set($allStyleTabStops-RTF)"/>
154
</xsl:apply-templates>
157
<xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
165
<!-- ************************************************ -->
166
<!-- *** Create Table for Content Table Paragraph *** -->
167
<!-- ************************************************ -->
169
<!-- Usually the paragraph in a content-table are ordered by tab-stops, which can not be displayed correctly by XHTML/CSS
170
Therefore they will be simulated by a table -->
171
<xsl:template match="text:p" mode="content-table">
172
<xsl:param name="globalData"/>
173
<xsl:param name="allStyleTabStops"/>
175
<!-- all elements before the first tabStop -->
176
<xsl:variable name="testNo-RTF">
177
<xsl:apply-templates select="node()" mode="cell-content"/>
181
<xsl:when test="function-available('common:node-set')">
182
<xsl:variable name="tabNodePositions" select="common:node-set($testNo-RTF)"/>
183
<xsl:element namespace="{$namespace}" name="tr">
184
<xsl:call-template name="create-td-elements">
185
<xsl:with-param name="lastNodePosition" select="count($allStyleTabStops/style:tab-stops/style:tab-stop)"/>
186
<xsl:with-param name="position" select="1"/>
187
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
188
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
189
<xsl:with-param name="globalData" select="$globalData"/>
193
<xsl:when test="function-available('xalan:nodeset')">
194
<xsl:variable name="tabNodePositions" select="xalan:nodeset($testNo-RTF)"/>
195
<xsl:element namespace="{$namespace}" name="tr">
196
<xsl:call-template name="create-td-elements">
197
<xsl:with-param name="lastNodePosition" select="count($allStyleTabStops/style:tab-stops/style:tab-stop)"/>
198
<xsl:with-param name="position" select="1"/>
199
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
200
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
201
<xsl:with-param name="globalData" select="$globalData"/>
205
<xsl:when test="function-available('xt:node-set')">
206
<xsl:variable name="tabNodePositions" select="xt:node-set($testNo-RTF)"/>
207
<xsl:element namespace="{$namespace}" name="tr">
208
<xsl:call-template name="create-td-elements">
209
<xsl:with-param name="lastNodePosition" select="count($allStyleTabStops/style:tab-stops/style:tab-stop)"/>
210
<xsl:with-param name="position" select="1"/>
211
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
212
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
213
<xsl:with-param name="globalData" select="$globalData"/>
218
<xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
223
<!-- Gathering all style:tab-stops from a style-hierarchy as siblings -->
224
<xsl:template name="get-tab-stops">
225
<xsl:param name="globalData"/>
226
<xsl:param name="styleName"/>
227
<xsl:variable name="tabStyle" select="key('styles', $styleName)"/>
229
<xsl:if test="$tabStyle/*/style:tab-stops/style:tab-stop/@style:position">
230
<xsl:for-each select="$tabStyle/*/style:tab-stops/style:tab-stop">
231
<xsl:copy-of select="."/>
235
<xsl:if test="$tabStyle/@style:parent-style-name">
236
<xsl:call-template name="get-tab-stops">
237
<xsl:with-param name="globalData" select="$globalData"/>
238
<xsl:with-param name="styleName" select="$tabStyle/@style:parent-style-name"/>
243
<xsl:template name="create-col-element">
244
<xsl:param name="lastNodePosition"/>
245
<xsl:param name="allStyleTabStops"/>
247
<xsl:for-each select="$allStyleTabStops/style:tab-stops/style:tab-stop">
248
<xsl:element namespace="{$namespace}" name="col">
249
<xsl:attribute name="style">
250
<xsl:text>width: </xsl:text>
252
<xsl:when test="contains(@style:position, 'cm')">
253
<xsl:call-template name="create-cell-width">
254
<xsl:with-param name="width" select="number(substring-before(@style:position,'cm'))"/>
255
<xsl:with-param name="unit" select="'cm'"/>
256
<xsl:with-param name="position" select="position() - 1"/>
257
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
260
<xsl:when test="contains(@style:position, 'in')">
261
<xsl:call-template name="create-cell-width">
262
<xsl:with-param name="width" select="number(substring-before(@style:position,'in'))"/>
263
<xsl:with-param name="unit" select="'in'"/>
264
<xsl:with-param name="position" select="position() - 1"/>
265
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
268
<xsl:when test="contains(@style:position, 'ch')">
269
<xsl:call-template name="create-cell-width">
270
<xsl:with-param name="width" select="number(substring-before(@style:position,'ch'))"/>
271
<xsl:with-param name="unit" select="'ch'"/>
272
<xsl:with-param name="position" select="position() - 1"/>
273
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
276
<xsl:when test="contains(@style:position, 'pt')">
277
<xsl:call-template name="create-cell-width">
278
<xsl:with-param name="width" select="number(substring-before(@style:position,'pt'))"/>
279
<xsl:with-param name="unit" select="'pt'"/>
280
<xsl:with-param name="position" select="position() - 1"/>
281
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
294
1) style:type of style:tab-stop is 'right' and earlier tabStop is not right
295
-> Earlier text-nodes and following text-nodes, will be put into an inner table, with two TD first aligned left, with proceding textnodes, the latter aligned right.
297
2) style:type is 'right' and earlier tabStop is right
298
-> following text-nodes, will be put into a right aligned TD
300
3) style:type is 'non-right' and earlier tabStop 'non-right' as well
301
-> put the preceding tab stops into a TD (left aligned is default)
303
4) first style:type would have no right preceding tabStop
304
-> works well with first sceanrios 1 and 3
306
5) last style:type would be a special case, if it would be left aligned, but this won't happen in our case.. :D
309
- text:styleposition 'center' will not be matched in our case (effort for nothing), there will be only 'right' and not 'right'
310
- If the last tabStop is not from text:stylepostion 'right', the length of the last cell is undefined and a document length must be found.
311
Not happens in our master document case. Also the algorithm below would have to be expanded (cp. scenario 5).
314
<xsl:template name="create-td-elements">
315
<xsl:param name="globalData"/>
316
<xsl:param name="lastNodePosition"/>
317
<xsl:param name="position"/>
318
<xsl:param name="allStyleTabStops"/>
319
<xsl:param name="tabNodePositions"/>
321
<xsl:variable name="currentTabStop" select="$allStyleTabStops/style:tab-stops/style:tab-stop[$position]"/>
322
<xsl:variable name="earlierTabStop" select="$allStyleTabStops/style:tab-stops/style:tab-stop[$position - 1]"/>
324
<xsl:when test="not($currentTabStop/@style:position) and not($earlierTabStop/@style:position)">
325
<!-- in case no TAB STOP is being set -->
326
<xsl:element namespace="{$namespace}" name="td">
327
<xsl:element namespace="{$namespace}" name="p">
328
<xsl:if test="$position = 1">
329
<xsl:attribute name="class">
330
<xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
333
<xsl:apply-templates mode="content-table">
334
<xsl:with-param name="globalData" select="$globalData"/>
335
</xsl:apply-templates>
341
<xsl:when test="$currentTabStop/@style:type = 'right'">
343
<xsl:when test="$earlierTabStop/@style:type = 'right'">
345
2) style:type is 'right' and earlier tabStop is right
346
-> following text-nodes, will be put into a right aligned TD -->
347
<xsl:element namespace="{$namespace}" name="td">
348
<xsl:attribute name="style">
349
<xsl:text>align: right</xsl:text>
351
<xsl:element namespace="{$namespace}" name="p">
352
<xsl:if test="$position = 1">
353
<xsl:attribute name="class">
354
<xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
357
<xsl:call-template name="grab-cell-content-before-tab-stop">
358
<xsl:with-param name="globalData" select="$globalData"/>
359
<xsl:with-param name="endingTabStopPosition" select="$position + 1"/>
360
<xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
361
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
367
<xsl:element namespace="{$namespace}" name="td">
368
<xsl:element namespace="{$namespace}" name="p">
369
<xsl:if test="$position = 1">
370
<xsl:attribute name="class">
371
<xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
374
<xsl:call-template name="grab-cell-content-before-tab-stop">
375
<xsl:with-param name="globalData" select="$globalData"/>
376
<xsl:with-param name="endingTabStopPosition" select="$position"/>
377
<xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
378
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
387
<xsl:when test="$earlierTabStop/@style:type = 'right'"></xsl:when>
390
3) style:type is 'non-right' and earlier tabStop 'non-right' as well
391
-> put the preceding tab stops into a TD (left aligned is default) -->
392
<xsl:element namespace="{$namespace}" name="p">
393
<xsl:if test="$position = 1">
394
<xsl:attribute name="class">
395
<xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
398
<xsl:element namespace="{$namespace}" name="td">
399
<xsl:call-template name="grab-cell-content-before-tab-stop">
400
<xsl:with-param name="globalData" select="$globalData"/>
401
<xsl:with-param name="endingTabStopPosition" select="$position"/>
402
<xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
403
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
412
<xsl:if test="$position != $lastNodePosition">
413
<xsl:call-template name="create-td-elements">
414
<xsl:with-param name="globalData" select="$globalData"/>
415
<xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
416
<xsl:with-param name="position" select="$position + 1"/>
417
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
418
<xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
425
<xsl:template name="grab-cell-content-before-tab-stop">
426
<xsl:param name="globalData"/>
427
<xsl:param name="endingTabStopPosition"/>
428
<xsl:param name="tabNodePositions"/>
429
<xsl:param name="lastNodePosition"/>
432
<xsl:when test="$endingTabStopPosition = 1">
433
<xsl:apply-templates mode="content-table" select="node()[position() < $tabNodePositions/tab-stop-node-position[$endingTabStopPosition]]">
434
<xsl:with-param name="globalData" select="$globalData"/>
435
</xsl:apply-templates>
437
<xsl:when test="$endingTabStopPosition > $lastNodePosition">
438
<xsl:apply-templates mode="content-table" select="node()[position() > $tabNodePositions/tab-stop-node-position[$endingTabStopPosition - 1]]">
439
<xsl:with-param name="globalData" select="$globalData"/>
440
</xsl:apply-templates>
443
<xsl:variable name="nodesOfNextColumn" select="node()[position() < $tabNodePositions/tab-stop-node-position[$endingTabStopPosition]][position() > $tabNodePositions/tab-stop-node-position[$endingTabStopPosition - 1]]"/>
445
<xsl:when test="$nodesOfNextColumn != ''">
446
<xsl:apply-templates mode="content-table" select="$nodesOfNextColumn">
447
<xsl:with-param name="globalData" select="$globalData"/>
448
</xsl:apply-templates>
451
<xsl:apply-templates mode="content-table">
452
<xsl:with-param name="globalData" select="$globalData"/>
453
</xsl:apply-templates>
460
<!-- As the span width will be mapped to column width, the preceding span widths have to be substracted -->
461
<xsl:template name="create-cell-width">
462
<xsl:param name="width"/>
463
<xsl:param name="unit"/>
464
<xsl:param name="position"/>
465
<xsl:param name="allStyleTabStops"/>
468
<!-- beyond second width -->
469
<xsl:when test="$position > 1">
470
<xsl:call-template name="create-cell-width">
471
<xsl:with-param name="width" select="$width - number(substring-before($allStyleTabStops/style:tab-stops/style:tab-stop[$position]/@style:position,$unit))"/>
472
<xsl:with-param name="unit" select="$unit"/>
473
<xsl:with-param name="position" select="$position - 1"/>
474
<xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
477
<!-- second width -->
478
<xsl:when test="$position = 1">
479
<xsl:value-of select="concat($width - number(substring-before($allStyleTabStops/style:tab-stops/style:tab-stop[$position]/@style:position,$unit)), $unit)"/>
483
<xsl:value-of select="concat($width, $unit)"/>
489
<!-- ************************************** -->
490
<!-- CREATION OF A CONTENT TABLE LINK -->
491
<!-- ************************************** -->
494
<!-- content table link -->
495
<xsl:template match="text:a" mode="content-table">
496
<xsl:param name="globalData"/>
499
<!-- heuristic assumption that first in a content table row, there is numbering (if at all) and than the text, furthermore that a tab will separate the to be neglected page number -->
500
<xsl:when test="text:tab">
501
<xsl:element namespace="{$namespace}" name="a">
502
<xsl:attribute name="href">
503
<xsl:text>#</xsl:text>
504
<xsl:value-of select="translate(text()[1], '.,;: %()[]/\+', '_____________')"/>
506
<xsl:value-of select="text()[1]"/>
514
<xsl:template match="text:s" mode="content-table">
515
<xsl:call-template name="write-breakable-whitespace">
516
<xsl:with-param name="whitespaces" select="@text:c"/>
521
<!-- ******************** -->
522
<!-- *** Common Rules *** -->
523
<!-- ******************** -->
525
<xsl:template match="*" mode="content-table">
526
<xsl:param name="globalData"/>
528
<xsl:apply-templates select=".">
529
<xsl:with-param name="globalData" select="$globalData"/>
530
</xsl:apply-templates>
533
<xsl:template match="*" mode="cell-content">
534
<xsl:if test="name() = 'text:tab' or *[name() = 'text:tab']">
535
<xsl:element name="tab-stop-node-position" namespace="">
536
<xsl:value-of select="position()"/>