1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22
23
24<!--
25	For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
26-->
27<xsl:stylesheet version="1.0"
28	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29	xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
30	xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
31	xmlns:dc="http://purl.org/dc/elements/1.1/"
32	xmlns:dom="http://www.w3.org/2001/xml-events"
33	xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
34	xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
35	xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
36	xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
37	xmlns:math="http://www.w3.org/1998/Math/MathML"
38	xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
39	xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
40	xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
41	xmlns:ooo="http://openoffice.org/2004/office"
42	xmlns:oooc="http://openoffice.org/2004/calc"
43	xmlns:ooow="http://openoffice.org/2004/writer"
44	xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
45	xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
46	xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
47	xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
48	xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
49	xmlns:xforms="http://www.w3.org/2002/xforms"
50	xmlns:xlink="http://www.w3.org/1999/xlink"
51	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
52	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
53	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"
54	xmlns="http://www.w3.org/1999/xhtml">
55
56
57
58	<!-- current node is a table:table -->
59	<xsl:template name="create-table-children">
60		<xsl:param name="globalData" />
61		<xsl:param name="allVisibleTableRows" />
62		<xsl:param name="allTableColumns" />
63
64		<xsl:element name="colgroup">
65			<xsl:for-each select="$allTableColumns/table:table-column">
66				<xsl:if test="not(@table:visibility = 'collapse' or @table:visibility = 'filter')">
67					<xsl:element name="col">
68						<xsl:variable name="value" select="$globalData/all-doc-styles/style[@style:name = current()/@table:style-name]/*/@style:column-width" />
69						<xsl:if test="$value">
70							<xsl:attribute name="width">
71								<!-- using the absolute width, problems with the relative in browser (in OOo style:rel-column-width) -->
72								<xsl:call-template name="convert2px">
73									<xsl:with-param name="value" select="$globalData/all-doc-styles/style[@style:name = current()/@table:style-name]/*/@style:column-width" />
74								</xsl:call-template>
75							</xsl:attribute>
76						</xsl:if>
77					</xsl:element>
78					<!-- *** the column-style ***
79					<xsl:attribute name="width">
80						<xsl:variable name="currentColumnStyleName" select="$allTableColumns/table:table-column[position() = $columnPosition]/@table:style-name" />
81						<xsl:value-of select="$globalData/all-doc-styles/style[@style:name = $currentColumnStyleName]/*/@style:column-width" />
82					</xsl:attribute>-->
83				</xsl:if>
84			</xsl:for-each>
85		</xsl:element>
86
87		<xsl:call-template name="create-table-rows">
88			<xsl:with-param name="globalData"           select="$globalData" />
89			<xsl:with-param name="allVisibleTableRows"  select="$allVisibleTableRows" />
90			<xsl:with-param name="allTableColumns"      select="$allTableColumns" />
91		</xsl:call-template>
92	</xsl:template>
93
94
95
96	<!-- Creating the content of a table content using CSS styles -->
97	<xsl:template name="create-table-cell-content">
98		<xsl:param name="tableDataType" />
99		<xsl:param name="globalData" />
100		<xsl:param name="allTableColumns" />
101		<xsl:param name="columnPosition" />
102		<xsl:param name="currentTableColumn" />
103
104		<xsl:element name="{$tableDataType}">
105
106			<!-- if parser reads DTD the default is set to '1' -->
107			<xsl:if test="@table:number-columns-spanned and @table:number-columns-spanned > 1">
108				<xsl:attribute name="colspan">
109					<xsl:value-of select="@table:number-columns-spanned" />
110				</xsl:attribute>
111			</xsl:if>
112			<!-- if parser reads DTD the default is set to '1' -->
113			<xsl:if test="@table:number-rows-spanned and @table:number-rows-spanned > 1">
114				<xsl:attribute name="rowspan">
115					<xsl:value-of select="@table:number-rows-spanned" />
116				</xsl:attribute>
117			</xsl:if>
118
119
120			<!-- *** the cell-style *** -->
121			<!-- The cell style has no conclusion with the column style, so we switch the order/priorities due to browser issues
122
123				The cell-style depends on two attributes:
124
125				1) table:style-name - the style properties of cell. When they exist, a default alignement (cp. below) will be added for the
126									  case of no alignment in the style exist.
127
128				2) office:value-type - the value type of the table-cell giving the default alignments.
129									  By default a string value is left aligned, all other are aligned:right.
130			-->
131			<xsl:choose>
132				<xsl:when test="@table:style-name">
133					<xsl:call-template name="set-styles">
134						<xsl:with-param name="globalData" select="$globalData" />
135						<xsl:with-param name="styleName" select="@table:style-name" />
136						<xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
137					</xsl:call-template>
138				</xsl:when>
139				<xsl:otherwise>
140					<!-- Cells without a style use the 'table:default-cell-style-name'
141						 when there is no default cell style specified for the current column. -->
142					<xsl:variable name="defaultCellStyleName" select="$currentTableColumn/@table:default-cell-style-name" />
143					<xsl:choose>
144						<xsl:when test="$defaultCellStyleName">
145							<xsl:call-template name="set-styles">
146								<xsl:with-param name="globalData" select="$globalData" />
147								<xsl:with-param name="styleName" select="$defaultCellStyleName" />
148								<xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
149							</xsl:call-template>
150						</xsl:when>
151						<xsl:otherwise>
152							<!-- No cell style exists, nor a default table cell style for the column -->
153							<xsl:attribute name="style">
154								<!-- sets cell alignment dependent of cell value type -->
155								<xsl:call-template name="set-cell-alignment" />
156							</xsl:attribute>
157						</xsl:otherwise>
158					</xsl:choose>
159				</xsl:otherwise>
160			</xsl:choose>
161
162			<xsl:if test="$debugEnabled">
163				<xsl:message>A table cell '<xsl:value-of select="$tableDataType" />' element has been added!</xsl:message>
164			</xsl:if>
165
166			<!-- empty cell tags produce problems with width CSS style on itself other table cells as well
167				therefore an non breakable space (&nbsp;/&#160;) have been inserted.-->
168			<xsl:choose>
169				<xsl:when test="node()">
170					<xsl:call-template name="apply-styles-and-content">
171						<xsl:with-param name="globalData" select="$globalData" />
172					</xsl:call-template>
173				</xsl:when>
174				<xsl:otherwise>
175					<xsl:call-template name="apply-styles-and-content">
176						<xsl:with-param name="globalData" select="$globalData" />
177					</xsl:call-template>
178					<xsl:text>&#160;</xsl:text>
179				</xsl:otherwise>
180			</xsl:choose>
181
182		</xsl:element>
183	</xsl:template>
184
185
186	<!-- Sets the cell alignment by the 'office:value-type' of the 'table:table-cell'.
187		 Strings have a left alignment, other values right -->
188	<xsl:template name="set-cell-alignment">
189		<xsl:choose>
190			<xsl:when test="@office:value-type and not(@office:value-type = 'string')">text-align:right; </xsl:when>
191			<xsl:otherwise>text-align:left;</xsl:otherwise>
192		</xsl:choose>
193	</xsl:template>
194
195
196
197	<!-- Sets styles of a cell -->
198	<xsl:template name="set-styles">
199		<xsl:param name="globalData" />
200		<xsl:param name="styleName" />
201		<xsl:param name="currentTableColumn" />
202
203		<xsl:attribute name="style">
204			<!-- sets cell alignment dependent of cell value type -->
205			<xsl:call-template name="set-cell-alignment" />
206
207			<!-- set column style (disjunct of cell style) -->
208			<xsl:value-of select="$globalData/all-styles/style[@style:name = $currentTableColumn/@table:style-name]/final-properties" />
209
210	   </xsl:attribute>
211
212	   <!-- cell style header -->
213	   <xsl:attribute name="class">
214		   <xsl:value-of select="translate($styleName, '.,;: %()[]/\+', '_____________')"/>
215	   </xsl:attribute>
216	</xsl:template>
217</xsl:stylesheet>
218
219