htmltbl.xsl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. version="1.0">
  5. <!-- ********************************************************************
  6. $Id$
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <!-- ==================================================================== -->
  13. <xsl:attribute-set name="th.style">
  14. <xsl:attribute name="font-weight">bold</xsl:attribute>
  15. </xsl:attribute-set>
  16. <!-- Outputs an fo:table only, not the caption -->
  17. <xsl:template match="table|informaltable" mode="htmlTable">
  18. <xsl:variable name="numcols">
  19. <xsl:call-template name="widest-html-row">
  20. <xsl:with-param name="rows" select=".//tr"/>
  21. </xsl:call-template>
  22. </xsl:variable>
  23. <xsl:variable name="prop-columns"
  24. select=".//col[contains(@width, '%')] |
  25. .//colgroup[contains(@width, '%')]"/>
  26. <xsl:variable name="table.width">
  27. <xsl:call-template name="table.width"/>
  28. </xsl:variable>
  29. <fo:table xsl:use-attribute-sets="table.table.properties">
  30. <xsl:choose>
  31. <xsl:when test="$fop.extensions != 0 or
  32. $passivetex.extensions != 0">
  33. <xsl:attribute name="table-layout">fixed</xsl:attribute>
  34. </xsl:when>
  35. </xsl:choose>
  36. <xsl:attribute name="width">
  37. <xsl:choose>
  38. <xsl:when test="@width">
  39. <xsl:value-of select="@width"/>
  40. </xsl:when>
  41. <xsl:when test="$table.width">
  42. <xsl:value-of select="$table.width"/>
  43. </xsl:when>
  44. <xsl:otherwise>100%</xsl:otherwise>
  45. </xsl:choose>
  46. </xsl:attribute>
  47. <xsl:call-template name="make-html-table-columns">
  48. <xsl:with-param name="count" select="$numcols"/>
  49. </xsl:call-template>
  50. <xsl:apply-templates select="thead" mode="htmlTable"/>
  51. <xsl:apply-templates select="tfoot" mode="htmlTable"/>
  52. <xsl:choose>
  53. <xsl:when test="tbody">
  54. <xsl:apply-templates select="tbody" mode="htmlTable"/>
  55. </xsl:when>
  56. <xsl:otherwise>
  57. <fo:table-body start-indent="0pt" end-indent="0pt">
  58. <xsl:apply-templates select="tr" mode="htmlTable"/>
  59. </fo:table-body>
  60. </xsl:otherwise>
  61. </xsl:choose>
  62. </fo:table>
  63. </xsl:template>
  64. <xsl:template match="caption" mode="htmlTable">
  65. <!-- Handled by formal.object.heading -->
  66. </xsl:template>
  67. <xsl:template name="widest-html-row">
  68. <xsl:param name="rows" select="''"/>
  69. <xsl:param name="count" select="0"/>
  70. <xsl:choose>
  71. <xsl:when test="count($rows) = 0">
  72. <xsl:value-of select="$count"/>
  73. </xsl:when>
  74. <xsl:otherwise>
  75. <xsl:choose>
  76. <xsl:when test="$count &gt; count($rows[1]/*)">
  77. <xsl:call-template name="widest-html-row">
  78. <xsl:with-param name="rows" select="$rows[position() &gt; 1]"/>
  79. <xsl:with-param name="count" select="$count"/>
  80. </xsl:call-template>
  81. </xsl:when>
  82. <xsl:otherwise>
  83. <xsl:call-template name="widest-html-row">
  84. <xsl:with-param name="rows" select="$rows[position() &gt; 1]"/>
  85. <xsl:with-param name="count" select="count($rows[1]/*)"/>
  86. </xsl:call-template>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. </xsl:template>
  92. <xsl:template name="make-html-table-columns">
  93. <xsl:param name="count" select="0"/>
  94. <xsl:param name="number" select="1"/>
  95. <xsl:choose>
  96. <xsl:when test="col|colgroup/col">
  97. <xsl:for-each select="col|colgroup/col">
  98. <fo:table-column>
  99. <xsl:attribute name="column-number">
  100. <xsl:number from="table|informaltable" level="any" format="1"/>
  101. </xsl:attribute>
  102. <xsl:if test="@width">
  103. <xsl:attribute name="column-width">
  104. <xsl:choose>
  105. <xsl:when test="$fop.extensions != 0 and
  106. contains(@width, '%')">
  107. <xsl:value-of select="concat('proportional-column-width(',
  108. substring-before(@width, '%'),
  109. ')')"/>
  110. </xsl:when>
  111. <xsl:otherwise>
  112. <xsl:value-of select="@width"/>
  113. </xsl:otherwise>
  114. </xsl:choose>
  115. </xsl:attribute>
  116. </xsl:if>
  117. </fo:table-column>
  118. </xsl:for-each>
  119. </xsl:when>
  120. <xsl:when test="$fop.extensions != 0">
  121. <xsl:if test="$number &lt;= $count">
  122. <fo:table-column column-number="{$number}"
  123. column-width="{6.5 div $count}in"/>
  124. <xsl:call-template name="make-html-table-columns">
  125. <xsl:with-param name="count" select="$count"/>
  126. <xsl:with-param name="number" select="$number + 1"/>
  127. </xsl:call-template>
  128. </xsl:if>
  129. </xsl:when>
  130. </xsl:choose>
  131. </xsl:template>
  132. <xsl:template match="tbody" mode="htmlTable">
  133. <fo:table-body border-bottom-width="0.25pt"
  134. border-bottom-style="solid"
  135. border-bottom-color="black"
  136. start-indent="0pt"
  137. end-indent="0pt">
  138. <xsl:apply-templates mode="htmlTable"/>
  139. </fo:table-body>
  140. </xsl:template>
  141. <xsl:template match="td" mode="htmlTable">
  142. <xsl:variable name="bgcolor">
  143. <xsl:call-template name="pi.dbfo_bgcolor"/>
  144. </xsl:variable>
  145. <fo:table-cell xsl:use-attribute-sets="table.cell.padding">
  146. <xsl:call-template name="table.cell.properties">
  147. <xsl:with-param name="bgcolor.pi" select="$bgcolor"/>
  148. <xsl:with-param name="rowsep.inherit" select="0"/>
  149. <xsl:with-param name="colsep.inherit" select="0"/>
  150. </xsl:call-template>
  151. <fo:block>
  152. <xsl:call-template name="table.cell.block.properties"/>
  153. <xsl:apply-templates/>
  154. </fo:block>
  155. </fo:table-cell>
  156. </xsl:template>
  157. <xsl:template match="tfoot" mode="htmlTable">
  158. <fo:table-footer start-indent="0pt"
  159. end-indent="0pt">
  160. <xsl:apply-templates mode="htmlTable"/>
  161. </fo:table-footer>
  162. </xsl:template>
  163. <xsl:template match="th" mode="htmlTable">
  164. <xsl:variable name="bgcolor">
  165. <xsl:call-template name="pi.dbfo_bgcolor"/>
  166. </xsl:variable>
  167. <fo:table-cell xsl:use-attribute-sets="th.style table.cell.padding">
  168. <xsl:call-template name="table.cell.properties">
  169. <xsl:with-param name="bgcolor.pi" select="$bgcolor"/>
  170. <xsl:with-param name="rowsep.inherit" select="0"/>
  171. <xsl:with-param name="colsep.inherit" select="0"/>
  172. </xsl:call-template>
  173. <fo:block>
  174. <xsl:call-template name="table.cell.block.properties"/>
  175. <xsl:apply-templates/>
  176. </fo:block>
  177. </fo:table-cell>
  178. </xsl:template>
  179. <xsl:template match="thead" mode="htmlTable">
  180. <fo:table-header border-bottom-width="0.25pt"
  181. border-bottom-style="solid"
  182. border-bottom-color="black"
  183. start-indent="0pt"
  184. end-indent="0pt"
  185. font-weight="bold">
  186. <xsl:apply-templates mode="htmlTable"/>
  187. </fo:table-header>
  188. </xsl:template>
  189. <xsl:template match="tr" mode="htmlTable">
  190. <fo:table-row>
  191. <xsl:call-template name="table.row.properties"/>
  192. <xsl:apply-templates mode="htmlTable"/>
  193. </fo:table-row>
  194. </xsl:template>
  195. </xsl:stylesheet>