table.xsl 7.8 KB

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