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<!-- ******************************************************************** 7 $Id: htmltbl.xsl,v 1.9 2006/05/04 07:11:00 bobstayton Exp $ 8 ******************************************************************** 9 10 This file is part of the XSL DocBook Stylesheet distribution. 11 See /README or http://nwalsh.com/docbook/xsl/ for copyright 12 and other information. 13 14 ******************************************************************** --> 15 16<!-- ==================================================================== --> 17 18<xsl:attribute-set name="th.style"> 19 <xsl:attribute name="font-weight">bold</xsl:attribute> 20</xsl:attribute-set> 21 22<!-- Outputs an fo:table only, not the caption --> 23<xsl:template match="table|informaltable" mode="htmlTable"> 24 25 <xsl:variable name="numcols"> 26 <xsl:call-template name="widest-html-row"> 27 <xsl:with-param name="rows" select=".//tr"/> 28 </xsl:call-template> 29 </xsl:variable> 30 31 <xsl:variable name="prop-columns" 32 select=".//col[contains(@width, '%')] | 33 .//colgroup[contains(@width, '%')]"/> 34 35 <xsl:variable name="table.width"> 36 <xsl:call-template name="table.width"/> 37 </xsl:variable> 38 39 <fo:table xsl:use-attribute-sets="table.table.properties"> 40 <xsl:choose> 41 <xsl:when test="$fop.extensions != 0 or 42 $passivetex.extensions != 0"> 43 <xsl:attribute name="table-layout">fixed</xsl:attribute> 44 </xsl:when> 45 </xsl:choose> 46 <xsl:attribute name="width"> 47 <xsl:choose> 48 <xsl:when test="@width"> 49 <xsl:value-of select="@width"/> 50 </xsl:when> 51 <xsl:when test="$table.width"> 52 <xsl:value-of select="$table.width"/> 53 </xsl:when> 54 <xsl:otherwise>100%</xsl:otherwise> 55 </xsl:choose> 56 </xsl:attribute> 57 <xsl:call-template name="make-html-table-columns"> 58 <xsl:with-param name="count" select="$numcols"/> 59 </xsl:call-template> 60 <xsl:apply-templates select="thead" mode="htmlTable"/> 61 <xsl:apply-templates select="tfoot" mode="htmlTable"/> 62 <xsl:choose> 63 <xsl:when test="tbody"> 64 <xsl:apply-templates select="tbody" mode="htmlTable"/> 65 </xsl:when> 66 <xsl:otherwise> 67 <fo:table-body start-indent="0pt" end-indent="0pt"> 68 <xsl:apply-templates select="tr" mode="htmlTable"/> 69 </fo:table-body> 70 </xsl:otherwise> 71 </xsl:choose> 72 </fo:table> 73 74</xsl:template> 75 76<xsl:template match="caption" mode="htmlTable"> 77 <!-- Handled by formal.object.heading --> 78</xsl:template> 79 80<xsl:template name="widest-html-row"> 81 <xsl:param name="rows" select="''"/> 82 <xsl:param name="count" select="0"/> 83 <xsl:choose> 84 <xsl:when test="count($rows) = 0"> 85 <xsl:value-of select="$count"/> 86 </xsl:when> 87 <xsl:otherwise> 88 <xsl:choose> 89 <xsl:when test="$count > count($rows[1]/*)"> 90 <xsl:call-template name="widest-html-row"> 91 <xsl:with-param name="rows" select="$rows[position() > 1]"/> 92 <xsl:with-param name="count" select="$count"/> 93 </xsl:call-template> 94 </xsl:when> 95 <xsl:otherwise> 96 <xsl:call-template name="widest-html-row"> 97 <xsl:with-param name="rows" select="$rows[position() > 1]"/> 98 <xsl:with-param name="count" select="count($rows[1]/*)"/> 99 </xsl:call-template> 100 </xsl:otherwise> 101 </xsl:choose> 102 </xsl:otherwise> 103 </xsl:choose> 104</xsl:template> 105 106<xsl:template name="make-html-table-columns"> 107 <xsl:param name="count" select="0"/> 108 <xsl:param name="number" select="1"/> 109 110 <xsl:choose> 111 <xsl:when test="col|colgroup/col"> 112 <xsl:for-each select="col|colgroup/col"> 113 <fo:table-column> 114 <xsl:attribute name="column-number"> 115 <xsl:number from="table|informaltable" level="any" format="1"/> 116 </xsl:attribute> 117 <xsl:if test="@width"> 118 <xsl:attribute name="column-width"> 119 <xsl:choose> 120 <xsl:when test="$fop.extensions != 0 and 121 contains(@width, '%')"> 122 <xsl:value-of select="concat('proportional-column-width(', 123 substring-before(@width, '%'), 124 ')')"/> 125 </xsl:when> 126 <xsl:otherwise> 127 <xsl:value-of select="@width"/> 128 </xsl:otherwise> 129 </xsl:choose> 130 </xsl:attribute> 131 </xsl:if> 132 </fo:table-column> 133 </xsl:for-each> 134 </xsl:when> 135 <xsl:when test="$fop.extensions != 0"> 136 <xsl:if test="$number <= $count"> 137 <fo:table-column column-number="{$number}" 138 column-width="{6.5 div $count}in"/> 139 <xsl:call-template name="make-html-table-columns"> 140 <xsl:with-param name="count" select="$count"/> 141 <xsl:with-param name="number" select="$number + 1"/> 142 </xsl:call-template> 143 </xsl:if> 144 </xsl:when> 145 </xsl:choose> 146</xsl:template> 147 148<xsl:template match="tbody" mode="htmlTable"> 149 <fo:table-body border-bottom-width="0.25pt" 150 border-bottom-style="solid" 151 border-bottom-color="black" 152 start-indent="0pt" 153 end-indent="0pt"> 154 <xsl:apply-templates mode="htmlTable"/> 155 </fo:table-body> 156</xsl:template> 157 158<xsl:template match="td" mode="htmlTable"> 159 <xsl:variable name="bgcolor"> 160 <xsl:call-template name="dbfo-attribute"> 161 <xsl:with-param name="pis" select="processing-instruction('dbfo')"/> 162 <xsl:with-param name="attribute" select="'bgcolor'"/> 163 </xsl:call-template> 164 </xsl:variable> 165 <fo:table-cell xsl:use-attribute-sets="table.cell.padding"> 166 <xsl:call-template name="table.cell.properties"> 167 <xsl:with-param name="bgcolor.pi" select="$bgcolor"/> 168 <xsl:with-param name="rowsep.inherit" select="0"/> 169 <xsl:with-param name="colsep.inherit" select="0"/> 170 </xsl:call-template> 171 <fo:block> 172 <xsl:call-template name="table.cell.block.properties"/> 173 <xsl:apply-templates/> 174 </fo:block> 175 </fo:table-cell> 176</xsl:template> 177 178<xsl:template match="tfoot" mode="htmlTable"> 179 <fo:table-footer start-indent="0pt" 180 end-indent="0pt"> 181 <xsl:apply-templates mode="htmlTable"/> 182 </fo:table-footer> 183</xsl:template> 184 185<xsl:template match="th" mode="htmlTable"> 186 <xsl:variable name="bgcolor"> 187 <xsl:call-template name="dbfo-attribute"> 188 <xsl:with-param name="pis" select="processing-instruction('dbfo')"/> 189 <xsl:with-param name="attribute" select="'bgcolor'"/> 190 </xsl:call-template> 191 </xsl:variable> 192 193 <fo:table-cell xsl:use-attribute-sets="th.style table.cell.padding"> 194 <xsl:call-template name="table.cell.properties"> 195 <xsl:with-param name="bgcolor.pi" select="$bgcolor"/> 196 <xsl:with-param name="rowsep.inherit" select="0"/> 197 <xsl:with-param name="colsep.inherit" select="0"/> 198 </xsl:call-template> 199 <fo:block> 200 <xsl:call-template name="table.cell.block.properties"/> 201 <xsl:apply-templates/> 202 </fo:block> 203 </fo:table-cell> 204</xsl:template> 205 206<xsl:template match="thead" mode="htmlTable"> 207 <fo:table-header border-bottom-width="0.25pt" 208 border-bottom-style="solid" 209 border-bottom-color="black" 210 start-indent="0pt" 211 end-indent="0pt" 212 font-weight="bold"> 213 <xsl:apply-templates mode="htmlTable"/> 214 </fo:table-header> 215</xsl:template> 216 217<xsl:template match="tr" mode="htmlTable"> 218 <xsl:variable name="bgcolor"> 219 <xsl:call-template name="dbfo-attribute"> 220 <xsl:with-param name="pis" select="processing-instruction('dbfo')"/> 221 <xsl:with-param name="attribute" select="'bgcolor'"/> 222 </xsl:call-template> 223 </xsl:variable> 224 225 <fo:table-row> 226 <xsl:if test="$bgcolor != ''"> 227 <xsl:attribute name="background-color"> 228 <xsl:value-of select="$bgcolor"/> 229 </xsl:attribute> 230 </xsl:if> 231 <xsl:apply-templates mode="htmlTable"/> 232 </fo:table-row> 233</xsl:template> 234 235</xsl:stylesheet> 236