/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/xhtml/table.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.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
        xmlns="http://www.w3.org/1999/xhtml">
 
63
 
 
64
 
 
65
 
 
66
        <!-- current node is a table:table -->
 
67
        <xsl:template name="create-table-children">
 
68
                <xsl:param name="globalData" />
 
69
                <xsl:param name="allVisibleTableRows" />
 
70
                <xsl:param name="allTableColumns" />
 
71
 
 
72
                <xsl:element name="colgroup">
 
73
                        <xsl:for-each select="$allTableColumns/table:table-column">
 
74
                                <xsl:if test="not(@table:visibility = 'collapse' or @table:visibility = 'filter')">
 
75
                                        <xsl:element name="col">
 
76
                                                <xsl:variable name="value" select="$globalData/all-doc-styles/style[@style:name = current()/@table:style-name]/*/@style:column-width" />
 
77
                                                <xsl:if test="$value">
 
78
                                                        <xsl:attribute name="width">
 
79
                                                                <!-- using the absolute width, problems with the relative in browser (in OOo style:rel-column-width) -->
 
80
                                                                <xsl:call-template name="convert2px">
 
81
                                                                        <xsl:with-param name="value" select="$globalData/all-doc-styles/style[@style:name = current()/@table:style-name]/*/@style:column-width" />
 
82
                                                                </xsl:call-template>
 
83
                                                        </xsl:attribute>
 
84
                                                </xsl:if>
 
85
                                        </xsl:element>
 
86
                                        <!-- *** the column-style ***
 
87
                                        <xsl:attribute name="width">
 
88
                                                <xsl:variable name="currentColumnStyleName" select="$allTableColumns/table:table-column[position() = $columnPosition]/@table:style-name" />
 
89
                                                <xsl:value-of select="$globalData/all-doc-styles/style[@style:name = $currentColumnStyleName]/*/@style:column-width" />
 
90
                                        </xsl:attribute>-->
 
91
                                </xsl:if>
 
92
                        </xsl:for-each>
 
93
                </xsl:element>
 
94
 
 
95
                <xsl:call-template name="create-table-rows">
 
96
                        <xsl:with-param name="globalData"           select="$globalData" />
 
97
                        <xsl:with-param name="allVisibleTableRows"  select="$allVisibleTableRows" />
 
98
                        <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
 
99
                </xsl:call-template>
 
100
        </xsl:template>
 
101
 
 
102
 
 
103
 
 
104
        <!-- Creating the content of a table content using CSS styles -->
 
105
        <xsl:template name="create-table-cell-content">
 
106
                <xsl:param name="tableDataType" />
 
107
                <xsl:param name="globalData" />
 
108
                <xsl:param name="allTableColumns" />
 
109
                <xsl:param name="columnPosition" />
 
110
                <xsl:param name="currentTableColumn" />
 
111
 
 
112
                <xsl:element name="{$tableDataType}">
 
113
 
 
114
                        <!-- if parser reads DTD the default is set to '1' -->
 
115
                        <xsl:if test="@table:number-columns-spanned and @table:number-columns-spanned > 1">
 
116
                                <xsl:attribute name="colspan">
 
117
                                        <xsl:value-of select="@table:number-columns-spanned" />
 
118
                                </xsl:attribute>
 
119
                        </xsl:if>
 
120
                        <!-- if parser reads DTD the default is set to '1' -->
 
121
                        <xsl:if test="@table:number-rows-spanned and @table:number-rows-spanned > 1">
 
122
                                <xsl:attribute name="rowspan">
 
123
                                        <xsl:value-of select="@table:number-rows-spanned" />
 
124
                                </xsl:attribute>
 
125
                        </xsl:if>
 
126
 
 
127
 
 
128
                        <!-- *** the cell-style *** -->
 
129
                        <!-- The cell style has no conclusion with the column style, so we switch the order/priorities due to browser issues
 
130
 
 
131
                                The cell-style depends on two attributes:
 
132
 
 
133
                                1) table:style-name - the style properties of cell. When they exist, a default alignement (cp. below) will be added for the
 
134
                                                                          case of no alignment in the style exist.
 
135
 
 
136
                                2) office:value-type - the value type of the table-cell giving the default alignments.
 
137
                                                                          By default a string value is left aligned, all other are aligned:right.
 
138
                        -->
 
139
                        <xsl:choose>
 
140
                                <xsl:when test="@table:style-name">
 
141
                                        <xsl:call-template name="set-styles">
 
142
                                                <xsl:with-param name="globalData" select="$globalData" />
 
143
                                                <xsl:with-param name="styleName" select="@table:style-name" />
 
144
                                                <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
 
145
                                        </xsl:call-template>
 
146
                                </xsl:when>
 
147
                                <xsl:otherwise>
 
148
                                        <!-- Cells without a style use the 'table:default-cell-style-name'
 
149
                                                 when there is no default cell style specified for the current column. -->
 
150
                                        <xsl:variable name="defaultCellStyleName" select="$currentTableColumn/@table:default-cell-style-name" />
 
151
                                        <xsl:choose>
 
152
                                                <xsl:when test="$defaultCellStyleName">
 
153
                                                        <xsl:call-template name="set-styles">
 
154
                                                                <xsl:with-param name="globalData" select="$globalData" />
 
155
                                                                <xsl:with-param name="styleName" select="$defaultCellStyleName" />
 
156
                                                                <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
 
157
                                                        </xsl:call-template>
 
158
                                                </xsl:when>
 
159
                                                <xsl:otherwise>
 
160
                                                        <!-- No cell style exists, nor a default table cell style for the column -->
 
161
                                                        <xsl:attribute name="style">
 
162
                                                                <!-- sets cell alignment dependent of cell value type -->
 
163
                                                                <xsl:call-template name="set-cell-alignment" />
 
164
                                                        </xsl:attribute>
 
165
                                                </xsl:otherwise>
 
166
                                        </xsl:choose>
 
167
                                </xsl:otherwise>
 
168
                        </xsl:choose>
 
169
 
 
170
                        <xsl:if test="$debugEnabled">
 
171
                                <xsl:message>A table cell '<xsl:value-of select="$tableDataType" />' element has been added!</xsl:message>
 
172
                        </xsl:if>
 
173
 
 
174
                        <!-- empty cell tags produce problems with width CSS style on itself other table cells as well
 
175
                                therefore an non breakable space (&nbsp;/&#160;) have been inserted.-->
 
176
                        <xsl:choose>
 
177
                                <xsl:when test="node()">
 
178
                                        <xsl:call-template name="apply-styles-and-content">
 
179
                                                <xsl:with-param name="globalData" select="$globalData" />
 
180
                                        </xsl:call-template>
 
181
                                </xsl:when>
 
182
                                <xsl:otherwise>
 
183
                                        <xsl:call-template name="apply-styles-and-content">
 
184
                                                <xsl:with-param name="globalData" select="$globalData" />
 
185
                                        </xsl:call-template>
 
186
                                        <xsl:text>&#160;</xsl:text>
 
187
                                </xsl:otherwise>
 
188
                        </xsl:choose>
 
189
 
 
190
                </xsl:element>
 
191
        </xsl:template>
 
192
 
 
193
 
 
194
        <!-- Sets the cell alignment by the 'office:value-type' of the 'table:table-cell'.
 
195
                 Strings have a left alignment, other values right -->
 
196
        <xsl:template name="set-cell-alignment">
 
197
                <xsl:choose>
 
198
                        <xsl:when test="@office:value-type and not(@office:value-type = 'string')">text-align:right; </xsl:when>
 
199
                        <xsl:otherwise>text-align:left;</xsl:otherwise>
 
200
                </xsl:choose>
 
201
        </xsl:template>
 
202
 
 
203
 
 
204
 
 
205
        <!-- Sets styles of a cell -->
 
206
        <xsl:template name="set-styles">
 
207
                <xsl:param name="globalData" />
 
208
                <xsl:param name="styleName" />
 
209
                <xsl:param name="currentTableColumn" />
 
210
 
 
211
                <xsl:attribute name="style">
 
212
                        <!-- sets cell alignment dependent of cell value type -->
 
213
                        <xsl:call-template name="set-cell-alignment" />
 
214
 
 
215
                        <!-- set column style (disjunct of cell style) -->
 
216
                        <xsl:value-of select="$globalData/all-styles/style[@style:name = $currentTableColumn/@table:style-name]/final-properties" />
 
217
 
 
218
           </xsl:attribute>
 
219
 
 
220
           <!-- cell style header -->
 
221
           <xsl:attribute name="class">
 
222
                   <xsl:value-of select="translate($styleName, '.,;: %()[]/\+', '_____________')"/>
 
223
           </xsl:attribute>
 
224
        </xsl:template>
 
225
</xsl:stylesheet>
 
226