table.xsl 11 KB

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