1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
<?xml version='1.0'?>
<!--####################################################################
| $Id: db2latex-mw-table.xsl 120 2004-03-26 20:19:43Z mw $
| $Author: mw $
+ ################################################################# -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc" version='1.0'>
<xsl:template name="table.format.tabularx">
<xsl:param name="cols" select="1"/>
<xsl:param name="i" select="1"/>
<xsl:param name="colsep" select="1"/>
<!-- sum of numeric portions in 1*-like colwidths -->
<xsl:param name="starfactor" select="0"/>
<xsl:choose>
<!-- Out of the recursive iteration -->
<xsl:when test="$i > $cols"></xsl:when>
<!-- There are still columns to count -->
<xsl:otherwise>
<xsl:variable name="userwidth">
<xsl:choose>
<xsl:when test="./colspec[@colnum=$i]">
<xsl:value-of select="./colspec[@colnum=$i]/@colwidth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="./colspec[position()=$i]/@colwidth"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="useralign">
<xsl:choose>
<xsl:when test="./colspec[@colnum=$i]">
<xsl:value-of select="./colspec[@colnum=$i]/@align"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="./colspec[position()=$i]/@align"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="width">
<xsl:variable name="cells" select="thead/row/entry[$i]|tbody/row/entry[$i]"/>
<xsl:choose>
<xsl:when test="string-length($userwidth)=0 and count($cells//itemizedlist|$cells//orderedlist|$cells//variablelist)>0">
<!-- In these specific circumstances, we MUST use a line-wrapped column
and yet the user hasn't specified one. -->
<xsl:value-of select="'1*'"/>
</xsl:when>
<xsl:otherwise>
<!-- In the general case, we just do what the user wants (may even
have no pre-specified width). -->
<xsl:value-of select="$userwidth"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Try to take heed of colspecs -->
<xsl:choose>
<xsl:when test="$width!=''">
<xsl:text>>{</xsl:text>
<xsl:if test="contains($width,'*')">
<!-- see tabularx documentation -->
<xsl:text>\hsize=</xsl:text>
<xsl:value-of select="substring-before($width,'*') * $starfactor" />
<xsl:text>\hsize</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="$useralign='left'"><xsl:text>\RaggedRight</xsl:text></xsl:when>
<xsl:when test="$useralign='right'"><xsl:text>\RaggedLeft</xsl:text></xsl:when>
<xsl:when test="$useralign='center'"><xsl:text>\Centering</xsl:text></xsl:when>
<xsl:when test="$useralign='char' and $latex.use.dcolumn='1'">
<xsl:variable name="char" select="(./colspec[@colnum=$i]/@char|./colspec[position()=$i]/@char)[1]"/>
<xsl:choose>
<xsl:when test="$char=''"><xsl:text>d</xsl:text></xsl:when>
<xsl:otherwise>D{<xsl:value-of select="$char"/>}{<xsl:value-of select="$char"/>}{-1}</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$useralign!=''"><xsl:message>Table column '<xsl:value-of select="$useralign"/>' alignment is not supported.</xsl:message></xsl:when>
</xsl:choose>
<xsl:text>}</xsl:text>
<xsl:choose>
<xsl:when test="contains($width,'*')">
<xsl:text>X</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>p{</xsl:text><xsl:value-of select="$width" /><xsl:text>}</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$i<$cols and $colsep='1'">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$useralign='left'"><xsl:text>l</xsl:text></xsl:when>
<xsl:when test="$useralign='right'"><xsl:text>r</xsl:text></xsl:when>
<xsl:when test="$useralign='center'"><xsl:text>c</xsl:text></xsl:when>
<xsl:when test="$useralign='justify'"><xsl:text>X</xsl:text></xsl:when>
<xsl:when test="$useralign='char' and $latex.use.dcolumn='1'">
<xsl:variable name="char" select="(./colspec[@colnum=$i]/@char|./colspec[position()=$i]/@char)[1]"/>
<xsl:choose>
<xsl:when test="$char=''"><xsl:text>d</xsl:text></xsl:when>
<xsl:otherwise>D{<xsl:value-of select="$char"/>}{<xsl:value-of select="$char"/>}{-1}</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:text>c</xsl:text>
<xsl:if test="$useralign!=''">
<xsl:message>Table column '<xsl:value-of select="$useralign"/>' alignment is not supported.</xsl:message>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$i<$cols and $colsep='1'">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<!-- Recursive for next column -->
<xsl:call-template name="table.format.tabularx">
<xsl:with-param name="i" select="$i+1"/>
<!-- Added by MW, 2003-10-19 -->
<xsl:with-param name="colsep" select="$colsep"/>
<xsl:with-param name="cols" select="$cols"/>
<xsl:with-param name="starfactor" select="$starfactor"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="tgroup">
<xsl:variable name="align" select="@align"/>
<!-- Changed by MW, 2003-10-19 -->
<xsl:variable name="colsep">
<xsl:choose>
<xsl:when test="string-length(@colsep)<1">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@colsep"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="frame">
<xsl:choose>
<xsl:when test="string-length(../@frame)<1">all</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../@frame"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="colspecs" select="./colspec"/>
<xsl:variable name="usex">
<xsl:choose>
<xsl:when test="$latex.use.ltxtable='1'">
<xsl:text>0</xsl:text>
</xsl:when>
<!-- if there are lists within cells, we need tabularx -->
<xsl:when test="$latex.use.tabularx=1 and (descendant::itemizedlist|descendant::orderedlist|descendant::variablelist)">
<xsl:text>1</xsl:text>
</xsl:when>
<!-- if there are instances of 1*-style colwidths, we need tabularx -->
<xsl:when test="$latex.use.tabularx=1 and contains(colspec/@colwidth,'*')">
<xsl:text>1</xsl:text>
</xsl:when>
<!-- if there are colspecs with 'justify' alignment and no explicit width, we need tabularx -->
<xsl:when test="$latex.use.tabularx=1 and count(colspec[@align='justify'])>0">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="useminipage">
<!-- Hack to get around LaTeX issue with tabular (not necessary with tabularx).
This is NOT a good solution, and has problems of its own, but at least the footnotes
do not actually disappear (which is what would otherwise happen). -->
<xsl:if test="count(.//footnote)!=0">1</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="$usex='1'">
<xsl:text>\begin{tabularx}{\linewidth}{</xsl:text>
</xsl:when>
<xsl:when test="$latex.use.ltxtable='1'">
<xsl:text>\begin{longtable}{</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$useminipage='1'"><xsl:text>\begin{minipage}{\linewidth} </xsl:text></xsl:if>
<xsl:text>\begin{tabular}{</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$frame='all' or $frame='sides'">
<xsl:text>|</xsl:text>
</xsl:if>
<xsl:variable name="cols">
<xsl:choose>
<xsl:when test="@cols">
<xsl:value-of select="@cols"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(tbody/row[1]/entry)"/>
<xsl:message>Warning: table lacks cols attribute. Assuming <xsl:value-of select="count(tbody/row[1]/entry)"/>.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$usex=1">
<xsl:call-template name="table.format.tabularx">
<xsl:with-param name="cols" select="$cols"/>
<!-- Changed by MW, 2003-10-19 -->
<xsl:with-param name="colsep" select="$colsep"/>
<xsl:with-param name="starfactor">
<xsl:call-template name="generate.starfactor">
<xsl:with-param name="cols" select="$cols"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="table.format.tabular">
<xsl:with-param name="cols" select="$cols"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$frame='all' or $frame='sides'">
<xsl:text>|</xsl:text>
</xsl:if>
<xsl:text>} </xsl:text>
<xsl:if test="$frame!='sides' and $frame!='none' and $frame!='bottom'">
<xsl:text>\hline </xsl:text>
</xsl:if>
<!-- APPLY TEMPLATES -->
<xsl:choose>
<xsl:when test="$latex.use.ltxtable='1'">
<xsl:apply-templates select="thead"/>
<xsl:apply-templates select="tfoot"/>
<xsl:apply-templates select="tbody"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="thead"/>
<xsl:apply-templates select="tbody"/>
<xsl:apply-templates select="tfoot"/>
</xsl:otherwise>
</xsl:choose>
<!-- -->
<xsl:if test="$frame!='sides' and $frame!='none' and $frame!='top'">
<xsl:text>\hline </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="$usex=1">
<xsl:text>\end{tabularx} </xsl:text>
</xsl:when>
<xsl:when test="$latex.use.ltxtable='1'">
<xsl:text>\end{longtable} </xsl:text>
<!-- catcode touchup ARGH -->
<xsl:call-template name="generate.latex.cell.separator">
<xsl:with-param name="which" select="'post'"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>\end{tabular} </xsl:text>
<xsl:if test="$useminipage='1'"><xsl:text>\end{minipage} </xsl:text></xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- this lets us specify vertical space between rows -->
<xsl:template match="tbody/row">
<xsl:apply-templates/>
<xsl:text> \tabularnewline</xsl:text>
<xsl:if test="contains(@role,'db2latex:rowvspace')">
<!-- FIXME: let user specify amount of vert. spcace -->
<xsl:text>[1ex]</xsl:text>
</xsl:if>
<xsl:text> </xsl:text>
<xsl:call-template name="generate.table.row.separator"/>
</xsl:template>
<xsl:template name="table.row.separator">
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
|