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
55
56	<!-- table row handling -->
57	<xsl:include href="table_rows.xsl" />
58	<!-- table column handling -->
59	<xsl:include href="table_columns.xsl" />
60	<!-- table cell handling -->
61	<xsl:include href="table_cells.xsl" />
62
63	<xsl:param name="tableElement" select="'table'" />
64
65	<!-- ******************* -->
66	<!-- *** main table  *** -->
67	<!-- ******************* -->
68
69
70	<xsl:template match="table:table" name="table:table">
71		<xsl:param name="globalData" />
72
73		<!-- The table will only be created if the table:scenario is active -->
74		<xsl:if test="not(table:scenario) or table:scenario/@table:is-active">
75			<xsl:call-template name="create-table">
76				<xsl:with-param name="globalData" select="$globalData" />
77			</xsl:call-template>
78		</xsl:if>
79	</xsl:template>
80
81
82
83	<xsl:template name="create-table">
84		<xsl:param name="globalData" />
85
86		<!-- by default '1', for each new sub/inner/nested table the number counts one up -->
87		<xsl:variable name="tableLevel" select="count(ancestor-or-self::table:table)" />
88		<!-- collecting all visible "table:table-row" elements of the table -->
89		<xsl:variable name="allVisibleTableRows" select="table:table-row[not(@table:visibility = 'collapse' or @table:visibility = 'filter')][count(ancestor-or-self::table:table) = $tableLevel] |
90														 table:table-header-rows/descendant::table:table-row[not(@table:visibility = 'collapse' or @table:visibility = 'filter')][count(ancestor-or-self::table:table) = $tableLevel] |
91														 table:table-row-group/descendant::table:table-row[not(@table:visibility = 'collapse' or @table:visibility = 'filter')][count(ancestor-or-self::table:table) = $tableLevel]" />
92		<!-- As the alignment of a table is by 'align' attribut is deprecated and as the CSS 'float' attribute not well displayed,
93			 we do a trick by encapsulating the table with a aligned 'div' element-->
94		<xsl:variable name="table-alignment" select="key('styles', @style:name = current()/@table:style-name)/*/@table:align" />
95		<xsl:choose>
96			<xsl:when test="string-length($table-alignment) != 0">
97				<xsl:element namespace="{$namespace}" name="div">
98					<xsl:attribute name="style">
99						<xsl:choose>
100							<xsl:when test='$table-alignment="left" or $table-alignment="margins"'>
101								<xsl:text>text-align:left</xsl:text>
102							</xsl:when>
103							<xsl:when test='$table-alignment="right"'>
104								<xsl:text>text-align:right</xsl:text>
105							</xsl:when>
106							<xsl:when test='$table-alignment="center"'>
107								<xsl:text>text-align:center</xsl:text>
108							</xsl:when>
109						</xsl:choose>
110					</xsl:attribute>
111					<xsl:call-template name="create-table-element">
112						<xsl:with-param name="globalData" select="$globalData" />
113						<xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows" />
114					</xsl:call-template>
115				</xsl:element>
116			</xsl:when>
117			<xsl:otherwise>
118				<xsl:call-template name="create-table-element">
119					<xsl:with-param name="globalData" select="$globalData" />
120					<xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows" />
121				</xsl:call-template>
122			</xsl:otherwise>
123		</xsl:choose>
124	</xsl:template>
125
126
127	<xsl:template name="create-table-element">
128		<xsl:param name="globalData" />
129		<xsl:param name="allVisibleTableRows" />
130
131		<xsl:element namespace="{$namespace}" name="{$tableElement}">
132			<xsl:attribute name="border">0</xsl:attribute>
133			<xsl:attribute name="cellspacing">0</xsl:attribute>
134			<xsl:attribute name="cellpadding">0</xsl:attribute>
135			<xsl:choose>
136				<xsl:when test='name()="table:table"'>
137					<xsl:variable name="value" select="$globalData/all-doc-styles/style[@style:name = current()/@table:style-name]/*/@style:rel-width" />
138					<xsl:if test="$value">
139						<xsl:attribute name="width">
140							<xsl:value-of select="$value" />
141						</xsl:attribute>
142					</xsl:if>
143				</xsl:when>
144				<xsl:otherwise>
145					<xsl:attribute name="width">100%</xsl:attribute>
146				</xsl:otherwise>
147			</xsl:choose>
148
149			<xsl:apply-templates select="@table:style-name">
150				<xsl:with-param name="globalData" select="$globalData" />
151			</xsl:apply-templates>
152
153			<xsl:call-template name="create-column-style-variable">
154				<xsl:with-param name="globalData" select="$globalData" />
155				<xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows" />
156			</xsl:call-template>
157		</xsl:element>
158	</xsl:template>
159
160</xsl:stylesheet>
161