/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to xml.files/odt/export/common/table/table_rows.xsl

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
<!--
 
3
 
 
4
  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
5
  
 
6
  Copyright 2008 by Sun Microsystems, Inc.
 
7
 
 
8
  OpenOffice.org - a multi-platform office productivity suite
 
9
 
 
10
  $RCSfile: table_rows.xsl,v $
 
11
 
 
12
  $Revision: 1.2.62.1 $
 
13
 
 
14
  This file is part of OpenOffice.org.
 
15
 
 
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.
 
19
 
 
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).
 
25
 
 
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.
 
30
 
 
31
-->
 
32
<!--
 
33
        For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
 
34
-->
 
35
<xsl:stylesheet version="1.0"
 
36
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
37
        xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
 
38
        xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
 
39
        xmlns:dc="http://purl.org/dc/elements/1.1/"
 
40
        xmlns:dom="http://www.w3.org/2001/xml-events"
 
41
        xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
 
42
        xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
 
43
        xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
 
44
        xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
 
45
        xmlns:math="http://www.w3.org/1998/Math/MathML"
 
46
        xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
 
47
        xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
 
48
        xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
 
49
        xmlns:ooo="http://openoffice.org/2004/office"
 
50
        xmlns:oooc="http://openoffice.org/2004/calc"
 
51
        xmlns:ooow="http://openoffice.org/2004/writer"
 
52
        xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
 
53
        xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
 
54
        xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
 
55
        xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
 
56
        xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
 
57
        xmlns:xforms="http://www.w3.org/2002/xforms"
 
58
        xmlns:xlink="http://www.w3.org/1999/xlink"
 
59
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 
60
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
61
        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">
 
62
 
 
63
 
 
64
        <xsl:param name="rowElement" select="'tr'" />
 
65
 
 
66
        <!-- ********************************** -->
 
67
        <!-- *** write repeating table rows *** -->
 
68
        <!-- ********************************** -->
 
69
 
 
70
        <!-- current node is a table:table -->
 
71
        <xsl:template name="create-table-rows">
 
72
                <xsl:param name="globalData" />
 
73
                <xsl:param name="allVisibleTableRows" />
 
74
                <xsl:param name="allTableColumns" />
 
75
 
 
76
                <!-- Some Office Calc documents simulate a background by repeating one of the later cells until end of used space
 
77
                         (The value of "table:number-columns-repeated" is enourmous). Writing out all these cells would be fatal in time
 
78
                         and output size. Therefore, this global variable shows us the longest row with content. -->
 
79
                <xsl:variable name="maxRowLength" select="count($allTableColumns/table:table-column)" />
 
80
                <xsl:if test="$debugEnabled">
 
81
                        <xsl:message>maxRowLength: <xsl:value-of select="$maxRowLength" /></xsl:message>
 
82
                        <xsl:call-template name="table-debug-allTableColumns">
 
83
                                <xsl:with-param name="allTableColumns" select="$allTableColumns" />
 
84
                        </xsl:call-template>
 
85
                </xsl:if>
 
86
 
 
87
                <!-- a table is a table header, when it has a "table:table-header-rows" ancestor -->
 
88
                <xsl:variable name="tableDataType">
 
89
                        <xsl:choose>
 
90
                                <xsl:when test="ancestor::table:table-header-rows">
 
91
                                        <xsl:text>th</xsl:text>
 
92
                                </xsl:when>
 
93
                                <xsl:otherwise>
 
94
                                        <xsl:text>td</xsl:text>
 
95
                                </xsl:otherwise>
 
96
                        </xsl:choose>
 
97
                </xsl:variable>
 
98
 
 
99
                <!-- removes repetition of rows, most probably done for background emulating -->
 
100
                <xsl:for-each select="$allVisibleTableRows">
 
101
                        <xsl:choose>
 
102
                                <xsl:when test="(last() or (last() - 1)) and @table:number-rows-repeated &gt; 99">
 
103
                                        <xsl:call-template name="repeat-write-row">
 
104
                                                <xsl:with-param name="globalData"           select="$globalData" />
 
105
                                                <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
 
106
                                                <xsl:with-param name="numberRowsRepeated"   select="1" />
 
107
                                                <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
 
108
                                                <xsl:with-param name="tableDataType"        select="$tableDataType" />
 
109
                                        </xsl:call-template>
 
110
                                </xsl:when>
 
111
                                <xsl:otherwise>
 
112
                                        <xsl:call-template name="repeat-write-row">
 
113
                                                <xsl:with-param name="globalData"           select="$globalData" />
 
114
                                                <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
 
115
                                                <xsl:with-param name="numberRowsRepeated"   select="@table:number-rows-repeated" />
 
116
                                                <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
 
117
                                                <xsl:with-param name="tableDataType"        select="$tableDataType" />
 
118
                                        </xsl:call-template>
 
119
                                </xsl:otherwise>
 
120
                        </xsl:choose>
 
121
                </xsl:for-each>
 
122
        </xsl:template>
 
123
 
 
124
 
 
125
        <xsl:template name="repeat-write-row">
 
126
                <xsl:param name="globalData" />
 
127
                <xsl:param name="allTableColumns" />
 
128
                <xsl:param name="numberRowsRepeated" select="1" />
 
129
                <xsl:param name="maxRowLength" />
 
130
                <xsl:param name="tableDataType" />
 
131
 
 
132
                <xsl:choose>
 
133
                        <!-- write an entry of a row and repeat calling this method until all elements are written out -->
 
134
                        <xsl:when test="$numberRowsRepeated > 1 and table:table-cell">
 
135
                                <xsl:call-template name="write-row">
 
136
                                        <xsl:with-param name="globalData"       select="$globalData" />
 
137
                                        <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
 
138
                                        <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
 
139
                                        <xsl:with-param name="tableDataType"    select="$tableDataType" />
 
140
                                </xsl:call-template>
 
141
 
 
142
                                <!-- NOTE: take variable from the output of repeated write-row and iterate giving out the variable -->
 
143
                                <xsl:call-template name="repeat-write-row">
 
144
                                        <xsl:with-param name="globalData"           select="$globalData" />
 
145
                                        <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
 
146
                                        <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
 
147
                                        <xsl:with-param name="numberRowsRepeated"   select="$numberRowsRepeated - 1" />
 
148
                                        <xsl:with-param name="tableDataType"        select="$tableDataType" />
 
149
                                </xsl:call-template>
 
150
                        </xsl:when>
 
151
                        <!-- write a single entry of a row -->
 
152
                        <xsl:otherwise>
 
153
                                <xsl:call-template name="write-row">
 
154
                                        <xsl:with-param name="globalData"           select="$globalData" />
 
155
                                        <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
 
156
                                        <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
 
157
                                        <xsl:with-param name="tableDataType"        select="$tableDataType" />
 
158
                                </xsl:call-template>
 
159
                        </xsl:otherwise>
 
160
                </xsl:choose>
 
161
        </xsl:template>
 
162
 
 
163
 
 
164
        <xsl:template name="add-table-row-attributes">
 
165
                <xsl:param name="globalData" />
 
166
 
 
167
                <!-- writing the style of the row -->
 
168
                <xsl:if test="@table:style-name">
 
169
                        <xsl:call-template name='add-style-properties'>
 
170
                                <xsl:with-param name="globalData" select="$globalData" />
 
171
                        </xsl:call-template>
 
172
                </xsl:if>
 
173
        </xsl:template>
 
174
 
 
175
        <xsl:template name="write-row">
 
176
                <xsl:param name="globalData" />
 
177
                <xsl:param name="allTableColumns" />
 
178
                <xsl:param name="maxRowLength" />
 
179
                <xsl:param name="tableDataType" />
 
180
 
 
181
 
 
182
                <xsl:element namespace="{$namespace}" name="{$rowElement}">
 
183
                        <xsl:call-template name='add-table-row-attributes'>
 
184
                                <xsl:with-param name="globalData" select="$globalData" />
 
185
                        </xsl:call-template>
 
186
 
 
187
                        <xsl:if test="$debugEnabled">
 
188
                                <xsl:message>'tr' element has been added!</xsl:message>
 
189
                        </xsl:if>
 
190
 
 
191
                        <xsl:apply-templates select="table:table-cell">
 
192
                                <xsl:with-param name="globalData"       select="$globalData" />
 
193
                                <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
 
194
                                <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
 
195
                                <xsl:with-param name="tableDataType"    select="$tableDataType" />
 
196
                        </xsl:apply-templates>
 
197
 
 
198
                </xsl:element>
 
199
        </xsl:template>
 
200
 
 
201
 
 
202
        <!-- **************************** -->
 
203
        <!-- *** HELPER: table styles *** -->
 
204
        <!-- **************************** -->
 
205
 
 
206
        <xsl:template name="add-style-properties">
 
207
                <xsl:param name="globalData" />
 
208
                <xsl:param name="allTableColumns" />
 
209
                <xsl:param name="node-position" />
 
210
 
 
211
                <xsl:attribute name="class">
 
212
                        <xsl:value-of select="translate(@table:style-name, '. %()/\+', '')" />
 
213
                </xsl:attribute>
 
214
        </xsl:template>
 
215
 
 
216
</xsl:stylesheet>