table_cells.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
  24. -->
  25. <xsl:stylesheet version="1.0"
  26. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  27. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  28. xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
  29. xmlns:dc="http://purl.org/dc/elements/1.1/"
  30. xmlns:dom="http://www.w3.org/2001/xml-events"
  31. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  32. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  33. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  34. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  35. xmlns:math="http://www.w3.org/1998/Math/MathML"
  36. xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  37. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  38. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  39. xmlns:ooo="http://openoffice.org/2004/office"
  40. xmlns:oooc="http://openoffice.org/2004/calc"
  41. xmlns:ooow="http://openoffice.org/2004/writer"
  42. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  43. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  44. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  45. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  46. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  47. xmlns:xforms="http://www.w3.org/2002/xforms"
  48. xmlns:xlink="http://www.w3.org/1999/xlink"
  49. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  50. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  51. xmlns:xt="http://www.jclark.com/xt"
  52. xmlns:common="http://exslt.org/common"
  53. xmlns:xalan="http://xml.apache.org/xalan"
  54. 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 xt common xalan">
  55. <!-- *********************************** -->
  56. <!-- *** write repeating table cells *** -->
  57. <!-- *********************************** -->
  58. <!-- matching cells to give out -> covered table cells are not written out -->
  59. <xsl:template match="table:table-cell">
  60. <xsl:param name="globalData" />
  61. <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  62. <xsl:param name="allTableColumns" />
  63. <xsl:param name="maxRowLength" />
  64. <xsl:param name="tableDataType" />
  65. <!-- The column position of the current cell has to be determined
  66. to get the adequate column styles during later cell creation,
  67. or hiding the cell when @table:visibility is not set to 'visible'.
  68. The position is archieved by adding up all table:number-columns-repeated of the preceding cells.
  69. Step1: creating '$precedingCells/quantity/@table:number-columns-repeated').
  70. Step2: sum(xxx:nodeset($precedingCells)/quantity) + 1 -->
  71. <xsl:variable name="precedingCells">
  72. <xsl:for-each select="preceding-sibling::*">
  73. <xsl:choose>
  74. <!-- maybe a parser is used, which reads the DTD files (e.g. Xerces),
  75. then '1' is the default for 'table:number-columns-repeated' -->
  76. <xsl:when test="not(@table:number-columns-repeated and @table:number-columns-repeated > 1)">
  77. <xsl:element name="quantity" namespace="">
  78. <xsl:text>1</xsl:text>
  79. </xsl:element>
  80. </xsl:when>
  81. <xsl:otherwise>
  82. <xsl:element name="quantity" namespace="">
  83. <xsl:value-of select="@table:number-columns-repeated" />
  84. </xsl:element>
  85. </xsl:otherwise>
  86. </xsl:choose>
  87. </xsl:for-each>
  88. </xsl:variable>
  89. <xsl:choose>
  90. <xsl:when test="function-available('common:node-set')">
  91. <xsl:call-template name="create-table-cell">
  92. <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  93. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  94. <xsl:with-param name="maxRowLength" select="$maxRowLength" />
  95. <xsl:with-param name="precedingColumns" select="sum(common:node-set($precedingCells)/*)" />
  96. <xsl:with-param name="globalData" select="$globalData" />
  97. <xsl:with-param name="tableDataType" select="$tableDataType" />
  98. </xsl:call-template>
  99. </xsl:when>
  100. <xsl:when test="function-available('xalan:nodeset')">
  101. <xsl:call-template name="create-table-cell">
  102. <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  103. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  104. <xsl:with-param name="maxRowLength" select="$maxRowLength" />
  105. <xsl:with-param name="precedingColumns" select="sum(xalan:nodeset($precedingCells)/*)" />
  106. <xsl:with-param name="globalData" select="$globalData" />
  107. <xsl:with-param name="tableDataType" select="$tableDataType" />
  108. </xsl:call-template>
  109. </xsl:when>
  110. <xsl:when test="function-available('xt:node-set')">
  111. <xsl:call-template name="create-table-cell">
  112. <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  113. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  114. <xsl:with-param name="maxRowLength" select="$maxRowLength" />
  115. <xsl:with-param name="precedingColumns" select="sum(xt:node-set($precedingCells)/*)" />
  116. <xsl:with-param name="globalData" select="$globalData" />
  117. <xsl:with-param name="tableDataType" select="$tableDataType" />
  118. </xsl:call-template>
  119. </xsl:when>
  120. <xsl:otherwise>
  121. <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:template>
  125. <!-- current node is a table:table-cell -->
  126. <xsl:template name="create-table-cell">
  127. <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  128. <xsl:param name="allTableColumns" />
  129. <xsl:param name="globalData" />
  130. <xsl:param name="maxRowLength" />
  131. <xsl:param name="precedingColumns" select="0" />
  132. <xsl:param name="tableDataType" />
  133. <xsl:variable name="columnPosition" select="$precedingColumns + 1" />
  134. <xsl:if test="$debugEnabled">
  135. <xsl:message>
  136. <xsl:text>
  137. table:table-cell #</xsl:text>
  138. <xsl:value-of select="$columnPosition" />
  139. <xsl:text> has been entered with node value: </xsl:text>
  140. <xsl:value-of select="." />
  141. <xsl:text>
  142. table:number-columns-repeated: </xsl:text>
  143. <xsl:value-of select="@table:number-columns-repeated" />
  144. <xsl:text>
  145. maxRowLength: </xsl:text>
  146. <xsl:value-of select="$maxRowLength" />
  147. </xsl:message>
  148. </xsl:if>
  149. <!-- only non hidden column will be given out -->
  150. <xsl:variable name="currentTableColumn" select="$allTableColumns/table:table-column[position() = $columnPosition]" />
  151. <xsl:if test="$currentTableColumn[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]">
  152. <xsl:choose>
  153. <!-- if parser reads DTD the default is set to '1' -->
  154. <xsl:when test="@table:number-columns-repeated > 1">
  155. <!-- writes multiple entries of a cell -->
  156. <xsl:call-template name="repeat-write-cell">
  157. <xsl:with-param name="globalData" select="$globalData" />
  158. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  159. <xsl:with-param name="columnPosition" select="$columnPosition" />
  160. <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
  161. <xsl:with-param name="maxRowLength" select="$maxRowLength" />
  162. <xsl:with-param name="numberColumnsRepeated" select="@table:number-columns-repeated" />
  163. <xsl:with-param name="tableDataType" select="$tableDataType" />
  164. </xsl:call-template>
  165. </xsl:when>
  166. <xsl:otherwise>
  167. <!-- writes an entry of a cell -->
  168. <xsl:call-template name="write-cell">
  169. <xsl:with-param name="globalData" select="$globalData" />
  170. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  171. <xsl:with-param name="columnPosition" select="$columnPosition" />
  172. <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
  173. <xsl:with-param name="maxRowLength" select="$maxRowLength" />
  174. <xsl:with-param name="tableDataType" select="$tableDataType" />
  175. </xsl:call-template>
  176. </xsl:otherwise>
  177. </xsl:choose>
  178. </xsl:if>
  179. </xsl:template>
  180. <xsl:template name="repeat-write-cell">
  181. <xsl:param name="globalData" />
  182. <xsl:param name="allTableColumns" />
  183. <xsl:param name="columnPosition" />
  184. <xsl:param name="currentTableColumn" />
  185. <xsl:param name="maxRowLength" />
  186. <xsl:param name="numberColumnsRepeated" />
  187. <xsl:param name="tableDataType" />
  188. <xsl:choose>
  189. <!-- This is the current workaround for the flood of cells, simulation background by repeating cell -->
  190. <xsl:when test="$numberColumnsRepeated > 1 and $maxRowLength > $columnPosition">
  191. <!-- writes an entry of a cell -->
  192. <xsl:call-template name="write-cell">
  193. <xsl:with-param name="globalData" select="$globalData" />
  194. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  195. <xsl:with-param name="columnPosition" select="$columnPosition" />
  196. <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
  197. <xsl:with-param name="tableDataType" select="$tableDataType" />
  198. </xsl:call-template>
  199. <!-- repeat calling this method until all elements written out -->
  200. <xsl:if test="$debugEnabled">
  201. <xsl:message>+++++++++ cell repetition +++++++++</xsl:message>
  202. </xsl:if>
  203. <xsl:call-template name="repeat-write-cell">
  204. <xsl:with-param name="globalData" select="$globalData" />
  205. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  206. <xsl:with-param name="columnPosition" select="$columnPosition + 1" />
  207. <xsl:with-param name="currentTableColumn" select="$allTableColumns/table:table-column[position() = ($columnPosition + 1)]" />
  208. <xsl:with-param name="maxRowLength" select="$maxRowLength" />
  209. <xsl:with-param name="numberColumnsRepeated" select="$numberColumnsRepeated - 1" />
  210. <xsl:with-param name="tableDataType" select="$tableDataType" />
  211. </xsl:call-template>
  212. </xsl:when>
  213. <xsl:otherwise>
  214. <!-- This is the current workaround for the flood of cells, simulation background by repeating cell -->
  215. <!-- When the maxRowLength is reached a last entry of a cell is written -->
  216. <xsl:call-template name="write-cell">
  217. <xsl:with-param name="globalData" select="$globalData" />
  218. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  219. <xsl:with-param name="columnPosition" select="$columnPosition" />
  220. <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
  221. <xsl:with-param name="tableDataType" select="$tableDataType" />
  222. </xsl:call-template>
  223. </xsl:otherwise>
  224. </xsl:choose>
  225. </xsl:template>
  226. <xsl:template name="write-cell">
  227. <xsl:param name="globalData" />
  228. <xsl:param name="allTableColumns" />
  229. <xsl:param name="columnPosition" />
  230. <xsl:param name="currentTableColumn" />
  231. <xsl:param name="tableDataType" />
  232. <!-- a non hidden column will be give out -->
  233. <xsl:choose>
  234. <xsl:when test="$currentTableColumn[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]">
  235. <xsl:call-template name="create-table-cell-content">
  236. <xsl:with-param name="globalData" select="$globalData" />
  237. <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  238. <xsl:with-param name="columnPosition" select="$columnPosition" />
  239. <xsl:with-param name="currentTableColumn" select="$currentTableColumn" />
  240. <xsl:with-param name="tableDataType" select="$tableDataType" />
  241. </xsl:call-template>
  242. </xsl:when>
  243. <!-- a hidden column -->
  244. <xsl:otherwise>
  245. <xsl:if test="$debugEnabled">
  246. <xsl:message>table column is hidden!</xsl:message>
  247. </xsl:if>
  248. </xsl:otherwise>
  249. </xsl:choose>
  250. </xsl:template>
  251. </xsl:stylesheet>