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 <xsl:param name="rowElement" select="'tr'" /> 57 58 <!-- ********************************** --> 59 <!-- *** write repeating table rows *** --> 60 <!-- ********************************** --> 61 62 <!-- current node is a table:table --> 63 <xsl:template name="create-table-rows"> 64 <xsl:param name="globalData" /> 65 <xsl:param name="allVisibleTableRows" /> 66 <xsl:param name="allTableColumns" /> 67 68 <!-- Some Office Calc documents simulate a background by repeating one of the later cells until end of used space 69 (The value of "table:number-columns-repeated" is enourmous). Writing out all these cells would be fatal in time 70 and output size. Therefore, this global variable shows us the longest row with content. --> 71 <xsl:variable name="maxRowLength" select="count($allTableColumns/table:table-column)" /> 72 <xsl:if test="$debugEnabled"> 73 <xsl:message>maxRowLength: <xsl:value-of select="$maxRowLength" /></xsl:message> 74 <xsl:call-template name="table-debug-allTableColumns"> 75 <xsl:with-param name="allTableColumns" select="$allTableColumns" /> 76 </xsl:call-template> 77 </xsl:if> 78 79 <!-- a table is a table header, when it has a "table:table-header-rows" ancestor --> 80 <xsl:variable name="tableDataType"> 81 <xsl:choose> 82 <xsl:when test="ancestor::table:table-header-rows"> 83 <xsl:text>th</xsl:text> 84 </xsl:when> 85 <xsl:otherwise> 86 <xsl:text>td</xsl:text> 87 </xsl:otherwise> 88 </xsl:choose> 89 </xsl:variable> 90 91 <!-- removes repetition of rows, most probably done for background emulating --> 92 <xsl:for-each select="$allVisibleTableRows"> 93 <xsl:choose> 94 <xsl:when test="(last() or (last() - 1)) and @table:number-rows-repeated > 99"> 95 <xsl:call-template name="repeat-write-row"> 96 <xsl:with-param name="globalData" select="$globalData" /> 97 <xsl:with-param name="allTableColumns" select="$allTableColumns" /> 98 <xsl:with-param name="numberRowsRepeated" select="1" /> 99 <xsl:with-param name="maxRowLength" select="$maxRowLength" /> 100 <xsl:with-param name="tableDataType" select="$tableDataType" /> 101 </xsl:call-template> 102 </xsl:when> 103 <xsl:otherwise> 104 <xsl:call-template name="repeat-write-row"> 105 <xsl:with-param name="globalData" select="$globalData" /> 106 <xsl:with-param name="allTableColumns" select="$allTableColumns" /> 107 <xsl:with-param name="numberRowsRepeated" select="@table:number-rows-repeated" /> 108 <xsl:with-param name="maxRowLength" select="$maxRowLength" /> 109 <xsl:with-param name="tableDataType" select="$tableDataType" /> 110 </xsl:call-template> 111 </xsl:otherwise> 112 </xsl:choose> 113 </xsl:for-each> 114 </xsl:template> 115 116 117 <xsl:template name="repeat-write-row"> 118 <xsl:param name="globalData" /> 119 <xsl:param name="allTableColumns" /> 120 <xsl:param name="numberRowsRepeated" select="1" /> 121 <xsl:param name="maxRowLength" /> 122 <xsl:param name="tableDataType" /> 123 124 <xsl:choose> 125 <!-- write an entry of a row and repeat calling this method until all elements are written out --> 126 <xsl:when test="$numberRowsRepeated > 1 and table:table-cell"> 127 <xsl:call-template name="write-row"> 128 <xsl:with-param name="globalData" select="$globalData" /> 129 <xsl:with-param name="allTableColumns" select="$allTableColumns" /> 130 <xsl:with-param name="maxRowLength" select="$maxRowLength" /> 131 <xsl:with-param name="tableDataType" select="$tableDataType" /> 132 </xsl:call-template> 133 134 <!-- NOTE: take variable from the output of repeated write-row and iterate giving out the variable --> 135 <xsl:call-template name="repeat-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="numberRowsRepeated" select="$numberRowsRepeated - 1" /> 140 <xsl:with-param name="tableDataType" select="$tableDataType" /> 141 </xsl:call-template> 142 </xsl:when> 143 <!-- write a single entry of a row --> 144 <xsl:otherwise> 145 <xsl:call-template name="write-row"> 146 <xsl:with-param name="globalData" select="$globalData" /> 147 <xsl:with-param name="allTableColumns" select="$allTableColumns" /> 148 <xsl:with-param name="maxRowLength" select="$maxRowLength" /> 149 <xsl:with-param name="tableDataType" select="$tableDataType" /> 150 </xsl:call-template> 151 </xsl:otherwise> 152 </xsl:choose> 153 </xsl:template> 154 155 156 <xsl:template name="add-table-row-attributes"> 157 <xsl:param name="globalData" /> 158 159 <!-- writing the style of the row --> 160 <xsl:if test="@table:style-name"> 161 <xsl:call-template name='add-style-properties'> 162 <xsl:with-param name="globalData" select="$globalData" /> 163 </xsl:call-template> 164 </xsl:if> 165 </xsl:template> 166 167 <xsl:template name="write-row"> 168 <xsl:param name="globalData" /> 169 <xsl:param name="allTableColumns" /> 170 <xsl:param name="maxRowLength" /> 171 <xsl:param name="tableDataType" /> 172 173 174 <xsl:element namespace="{$namespace}" name="{$rowElement}"> 175 <xsl:call-template name='add-table-row-attributes'> 176 <xsl:with-param name="globalData" select="$globalData" /> 177 </xsl:call-template> 178 179 <xsl:if test="$debugEnabled"> 180 <xsl:message>'tr' element has been added!</xsl:message> 181 </xsl:if> 182 183 <xsl:apply-templates select="table:table-cell"> 184 <xsl:with-param name="globalData" select="$globalData" /> 185 <xsl:with-param name="allTableColumns" select="$allTableColumns" /> 186 <xsl:with-param name="maxRowLength" select="$maxRowLength" /> 187 <xsl:with-param name="tableDataType" select="$tableDataType" /> 188 </xsl:apply-templates> 189 190 </xsl:element> 191 </xsl:template> 192 193 194 <!-- **************************** --> 195 <!-- *** HELPER: table styles *** --> 196 <!-- **************************** --> 197 198 <xsl:template name="add-style-properties"> 199 <xsl:param name="globalData" /> 200 <xsl:param name="allTableColumns" /> 201 <xsl:param name="node-position" /> 202 203 <xsl:attribute name="class"> 204 <xsl:value-of select="translate(@table:style-name, '. %()/\+', '')" /> 205 </xsl:attribute> 206 </xsl:template> 207 208</xsl:stylesheet> 209