| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> |
| 3 |
|
| 4 |
<!--############################################################################ |
| 5 |
XSLT Stylesheet DocBook -> LaTeX |
| 6 |
############################################################################ --> |
| 7 |
|
| 8 |
<!-- Upper table and informaltable templates. They make the wrapper environment |
| 9 |
depending of the kind of table (floating, landscape, role) and call the |
| 10 |
actual newtbl engine. The $newtbl.use parameter is now removed. --> |
| 11 |
|
| 12 |
<xsl:param name="newtbl.format.thead">\bfseries% </xsl:param> |
| 13 |
<xsl:param name="newtbl.format.tbody"/> |
| 14 |
<xsl:param name="newtbl.format.tfoot"/> |
| 15 |
<xsl:param name="newtbl.bgcolor.thead"/> |
| 16 |
<xsl:param name="newtbl.default.colsep" select="'1'"/> |
| 17 |
<xsl:param name="newtbl.default.rowsep" select="'1'"/> |
| 18 |
<xsl:param name="newtbl.use.hhline" select="'0'"/> |
| 19 |
<xsl:param name="newtbl.autowidth"/> |
| 20 |
<xsl:param name="table.title.top" select="'0'"/> |
| 21 |
<xsl:param name="table.in.float" select="'1'"/> |
| 22 |
<xsl:param name="table.default.position" select="'[htbp]'"/> |
| 23 |
<xsl:param name="table.default.tabstyle"/> |
| 24 |
<xsl:param name="table.continue.caption" select="'(continued)'"/> |
| 25 |
<xsl:param name="default.table.width"/> |
| 26 |
|
| 27 |
|
| 28 |
<xsl:template match="table"> |
| 29 |
<xsl:choose> |
| 30 |
<xsl:when test="$table.in.float='1'"> |
| 31 |
<xsl:apply-templates select="." mode="float"/> |
| 32 |
</xsl:when> |
| 33 |
<xsl:otherwise> |
| 34 |
<xsl:apply-templates select="." mode="longtable"/> |
| 35 |
</xsl:otherwise> |
| 36 |
</xsl:choose> |
| 37 |
<xsl:apply-templates select="." mode="foottext"/> |
| 38 |
</xsl:template> |
| 39 |
|
| 40 |
<!-- Switch to CALS or HTML templates --> |
| 41 |
<xsl:template name="make.table.content"> |
| 42 |
<xsl:param name="tabletype">tabular</xsl:param> |
| 43 |
<xsl:param name="tablewidth">\linewidth-2\tabcolsep</xsl:param> |
| 44 |
|
| 45 |
<xsl:choose> |
| 46 |
<xsl:when test="tgroup"> |
| 47 |
<xsl:apply-templates select="tgroup" mode="newtbl"> |
| 48 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 49 |
<xsl:with-param name="tablewidth" select="$tablewidth"/> |
| 50 |
</xsl:apply-templates> |
| 51 |
</xsl:when> |
| 52 |
<xsl:otherwise> |
| 53 |
<xsl:apply-templates select="." mode="htmlTable"> |
| 54 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 55 |
<xsl:with-param name="tablewidth" select="$tablewidth"/> |
| 56 |
</xsl:apply-templates> |
| 57 |
</xsl:otherwise> |
| 58 |
</xsl:choose> |
| 59 |
</xsl:template> |
| 60 |
|
| 61 |
<!-- ==================================================================== --> |
| 62 |
|
| 63 |
<xsl:template match="table" mode="float"> |
| 64 |
<!-- do we need to change text size? --> |
| 65 |
<xsl:variable name="size"> |
| 66 |
<xsl:choose> |
| 67 |
<xsl:when test="@role='small' or @role='footnotesize' or |
| 68 |
@role='scriptsize' or @role='tiny'"> |
| 69 |
<xsl:value-of select="@role"/> |
| 70 |
</xsl:when> |
| 71 |
<xsl:otherwise> |
| 72 |
<xsl:text>normal</xsl:text> |
| 73 |
</xsl:otherwise> |
| 74 |
</xsl:choose> |
| 75 |
</xsl:variable> |
| 76 |
<!-- pgwide usefull in two column mode --> |
| 77 |
<xsl:variable name="table.env"> |
| 78 |
<xsl:text>table</xsl:text> |
| 79 |
<xsl:if test="@pgwide='1'"> |
| 80 |
<xsl:text>*</xsl:text> |
| 81 |
</xsl:if> |
| 82 |
</xsl:variable> |
| 83 |
<!-- in a float only tabular or tabularx allowed --> |
| 84 |
<xsl:variable name="tabletype"> |
| 85 |
<xsl:choose> |
| 86 |
<xsl:when test="@tabstyle='tabular' or @tabstyle='tabularx'"> |
| 87 |
<xsl:value-of select="@tabstyle"/> |
| 88 |
</xsl:when> |
| 89 |
<xsl:when test="$table.default.tabstyle='tabular' or |
| 90 |
$table.default.tabstyle='tabularx'"> |
| 91 |
<xsl:value-of select="$table.default.tabstyle"/> |
| 92 |
</xsl:when> |
| 93 |
<xsl:otherwise>tabular</xsl:otherwise> |
| 94 |
</xsl:choose> |
| 95 |
</xsl:variable> |
| 96 |
|
| 97 |
<xsl:if test="@orient='land'"> |
| 98 |
<xsl:text>\begin{landscape} </xsl:text> |
| 99 |
</xsl:if> |
| 100 |
<xsl:value-of select="concat('\begin{', $table.env, '}')"/> |
| 101 |
<!-- table placement preference --> |
| 102 |
<xsl:choose> |
| 103 |
<xsl:when test="@floatstyle != ''"> |
| 104 |
<xsl:value-of select="@floatstyle"/> |
| 105 |
</xsl:when> |
| 106 |
<xsl:otherwise> |
| 107 |
<xsl:value-of select="$table.default.position"/> |
| 108 |
</xsl:otherwise> |
| 109 |
</xsl:choose> |
| 110 |
<xsl:text> </xsl:text> |
| 111 |
<!-- title caption before the table --> |
| 112 |
<xsl:if test="$table.title.top='1'"> |
| 113 |
<xsl:apply-templates select="title|caption"/> |
| 114 |
</xsl:if> |
| 115 |
<xsl:if test="$size!='normal'"> |
| 116 |
<xsl:text>\begin{</xsl:text> |
| 117 |
<xsl:value-of select="$size"/> |
| 118 |
<xsl:text>} </xsl:text> |
| 119 |
</xsl:if> |
| 120 |
<xsl:text>\begin{center} </xsl:text> |
| 121 |
|
| 122 |
<!-- do the actual work --> |
| 123 |
<xsl:call-template name="make.table.content"> |
| 124 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 125 |
</xsl:call-template> |
| 126 |
|
| 127 |
<xsl:text> \end{center} </xsl:text> |
| 128 |
<xsl:if test="$size!='normal'"> |
| 129 |
<xsl:text>\end{</xsl:text> |
| 130 |
<xsl:value-of select="$size"/> |
| 131 |
<xsl:text>} </xsl:text> |
| 132 |
</xsl:if> |
| 133 |
<xsl:if test="$table.title.top='0'"> |
| 134 |
<xsl:apply-templates select="title|caption"/> |
| 135 |
</xsl:if> |
| 136 |
<xsl:value-of select="concat('\end{', $table.env, '} ')"/> |
| 137 |
<xsl:if test="@orient='land'"> |
| 138 |
<xsl:text>\end{landscape} </xsl:text> |
| 139 |
</xsl:if> |
| 140 |
</xsl:template> |
| 141 |
|
| 142 |
<xsl:template match="table/title|table/caption"> |
| 143 |
<xsl:text> \caption</xsl:text> |
| 144 |
<xsl:apply-templates select="." mode="format.title"/> |
| 145 |
<xsl:call-template name="label.id"> |
| 146 |
<xsl:with-param name="object" select="parent::table"/> |
| 147 |
</xsl:call-template> |
| 148 |
</xsl:template> |
| 149 |
|
| 150 |
|
| 151 |
<!-- Use the longtable features to have captions for formal tables --> |
| 152 |
<xsl:template match="table" mode="longtable"> |
| 153 |
<!-- do we need to change text size? --> |
| 154 |
<xsl:variable name="size"> |
| 155 |
<xsl:choose> |
| 156 |
<xsl:when test="@role='small' or @role='footnotesize' or |
| 157 |
@role='scriptsize' or @role='tiny'"> |
| 158 |
<xsl:value-of select="@role"/> |
| 159 |
</xsl:when> |
| 160 |
<xsl:otherwise> |
| 161 |
<xsl:text>normal</xsl:text> |
| 162 |
</xsl:otherwise> |
| 163 |
</xsl:choose> |
| 164 |
</xsl:variable> |
| 165 |
<xsl:if test="@orient='land'"> |
| 166 |
<xsl:text>\begin{landscape} </xsl:text> |
| 167 |
</xsl:if> |
| 168 |
|
| 169 |
<xsl:if test="$size!='normal'"> |
| 170 |
<xsl:text>\begin{</xsl:text> |
| 171 |
<xsl:value-of select="$size"/> |
| 172 |
<xsl:text>} </xsl:text> |
| 173 |
</xsl:if> |
| 174 |
<xsl:text>\begin{center} </xsl:text> |
| 175 |
|
| 176 |
<!-- do the actual work --> |
| 177 |
<xsl:call-template name="make.table.content"> |
| 178 |
<xsl:with-param name="tabletype" select="'longtable'"/> |
| 179 |
</xsl:call-template> |
| 180 |
|
| 181 |
<xsl:text> \end{center} </xsl:text> |
| 182 |
<xsl:if test="$size!='normal'"> |
| 183 |
<xsl:text>\end{</xsl:text> |
| 184 |
<xsl:value-of select="$size"/> |
| 185 |
<xsl:text>} </xsl:text> |
| 186 |
</xsl:if> |
| 187 |
<xsl:if test="@orient='land'"> |
| 188 |
<xsl:text>\end{landscape} </xsl:text> |
| 189 |
</xsl:if> |
| 190 |
</xsl:template> |
| 191 |
|
| 192 |
<xsl:template match="table/title|table/caption" mode="longtable"> |
| 193 |
<xsl:variable name="toc"> |
| 194 |
<xsl:apply-templates select="." mode="toc"/> |
| 195 |
</xsl:variable> |
| 196 |
<xsl:variable name="content"> |
| 197 |
<xsl:apply-templates select="." mode="content"/> |
| 198 |
</xsl:variable> |
| 199 |
<xsl:text>\caption</xsl:text> |
| 200 |
<!-- The title in the TOC --> |
| 201 |
<xsl:choose> |
| 202 |
<xsl:when test="$toc != ''"> |
| 203 |
<xsl:value-of select="$toc"/> |
| 204 |
</xsl:when> |
| 205 |
<xsl:otherwise> |
| 206 |
<xsl:text>[{</xsl:text> |
| 207 |
<xsl:value-of select="$content"/> |
| 208 |
<xsl:text>}]</xsl:text> |
| 209 |
</xsl:otherwise> |
| 210 |
</xsl:choose> |
| 211 |
<xsl:text>{</xsl:text> |
| 212 |
<xsl:value-of select="$content"/> |
| 213 |
<xsl:call-template name="label.id"> |
| 214 |
<xsl:with-param name="object" select="parent::table"/> |
| 215 |
</xsl:call-template> |
| 216 |
<xsl:text>}\tabularnewline </xsl:text> |
| 217 |
</xsl:template> |
| 218 |
|
| 219 |
<!-- ==================================================================== --> |
| 220 |
|
| 221 |
<xsl:template name="align.environment"> |
| 222 |
<xsl:param name="align"/> |
| 223 |
<xsl:param name="align-default" select="'center'"/> |
| 224 |
|
| 225 |
<xsl:choose> |
| 226 |
<xsl:when test="$align = 'left'"> |
| 227 |
<xsl:text>flushright</xsl:text> |
| 228 |
</xsl:when> |
| 229 |
<xsl:when test="$align = 'right'"> |
| 230 |
<xsl:text>flushleft</xsl:text> |
| 231 |
</xsl:when> |
| 232 |
<xsl:when test="$align = 'center'"> |
| 233 |
<xsl:text>center</xsl:text> |
| 234 |
</xsl:when> |
| 235 |
<xsl:otherwise> |
| 236 |
<xsl:value-of select="$align-default"/> |
| 237 |
</xsl:otherwise> |
| 238 |
</xsl:choose> |
| 239 |
</xsl:template> |
| 240 |
|
| 241 |
<xsl:template name="tbl.align.begin"> |
| 242 |
<xsl:param name="tabletype"/> |
| 243 |
|
| 244 |
<!-- provision for user-specified alignment --> |
| 245 |
<xsl:variable name="align" select="'center'"/> |
| 246 |
|
| 247 |
<xsl:choose> |
| 248 |
<xsl:when test="$tabletype = 'longtable'"> |
| 249 |
<xsl:choose> |
| 250 |
<xsl:when test="$align = 'left'"> |
| 251 |
<xsl:text>\raggedright</xsl:text> |
| 252 |
</xsl:when> |
| 253 |
<xsl:when test="$align = 'right'"> |
| 254 |
<xsl:text>\raggedleft</xsl:text> |
| 255 |
</xsl:when> |
| 256 |
<xsl:when test="$align = 'center'"> |
| 257 |
<xsl:text>\centering</xsl:text> |
| 258 |
</xsl:when> |
| 259 |
<xsl:when test="$align = 'justify'"></xsl:when> |
| 260 |
<xsl:otherwise> |
| 261 |
<xsl:message>Word-wrapped alignment <xsl:value-of |
| 262 |
select="$align"/> not supported</xsl:message> |
| 263 |
</xsl:otherwise> |
| 264 |
</xsl:choose> |
| 265 |
</xsl:when> |
| 266 |
<xsl:otherwise> |
| 267 |
<xsl:variable name="alignenv"> |
| 268 |
<xsl:call-template name="align.environment"> |
| 269 |
<xsl:with-param name="align" select="$align"/> |
| 270 |
</xsl:call-template> |
| 271 |
</xsl:variable> |
| 272 |
<xsl:value-of select="concat('\begin{',$alignenv,'}')"/> |
| 273 |
</xsl:otherwise> |
| 274 |
</xsl:choose> |
| 275 |
</xsl:template> |
| 276 |
|
| 277 |
<xsl:template name="tbl.align.end"> |
| 278 |
<xsl:param name="tabletype"/> |
| 279 |
|
| 280 |
<!-- provision for user-specified alignment --> |
| 281 |
<xsl:variable name="align" select="'center'"/> |
| 282 |
|
| 283 |
<xsl:if test="$tabletype != 'longtable'"> |
| 284 |
<xsl:variable name="alignenv"> |
| 285 |
<xsl:call-template name="align.environment"> |
| 286 |
<xsl:with-param name="align" select="$align"/> |
| 287 |
</xsl:call-template> |
| 288 |
</xsl:variable> |
| 289 |
<xsl:value-of select="concat('\end{',$alignenv,'}')"/> |
| 290 |
</xsl:if> |
| 291 |
</xsl:template> |
| 292 |
|
| 293 |
<!-- ==================================================================== --> |
| 294 |
|
| 295 |
<xsl:template match="informaltable"> |
| 296 |
<!-- do we need to change text size? --> |
| 297 |
<xsl:variable name="size"> |
| 298 |
<xsl:choose> |
| 299 |
<xsl:when test="@role='small' or @role='footnotesize' or |
| 300 |
@role='scriptsize' or @role='tiny'"> |
| 301 |
<xsl:value-of select="@role"/> |
| 302 |
</xsl:when> |
| 303 |
<xsl:otherwise> |
| 304 |
<xsl:text>normal</xsl:text> |
| 305 |
</xsl:otherwise> |
| 306 |
</xsl:choose> |
| 307 |
</xsl:variable> |
| 308 |
|
| 309 |
<!-- are we a nested table? --> |
| 310 |
<xsl:variable name="nested" select="ancestor::entry|ancestor::td"/> |
| 311 |
|
| 312 |
<!-- longtables cannot be nested --> |
| 313 |
<xsl:variable name="tabletype"> |
| 314 |
<xsl:choose> |
| 315 |
<xsl:when test="$nested">tabular</xsl:when> |
| 316 |
<xsl:when test="@tabstyle='tabular' or @tabstyle='tabularx'"> |
| 317 |
<xsl:value-of select="@tabstyle"/> |
| 318 |
</xsl:when> |
| 319 |
<xsl:when test="$table.default.tabstyle='tabular' or |
| 320 |
$table.default.tabstyle='tabularx'"> |
| 321 |
<xsl:value-of select="$table.default.tabstyle"/> |
| 322 |
</xsl:when> |
| 323 |
<xsl:otherwise>longtable</xsl:otherwise> |
| 324 |
</xsl:choose> |
| 325 |
</xsl:variable> |
| 326 |
|
| 327 |
<xsl:if test="@orient='land'"> |
| 328 |
<xsl:text>\begin{landscape} </xsl:text> |
| 329 |
</xsl:if> |
| 330 |
<xsl:if test="$size!='normal'"> |
| 331 |
<xsl:text>\begin{</xsl:text> |
| 332 |
<xsl:value-of select="$size"/> |
| 333 |
<xsl:text>} </xsl:text> |
| 334 |
</xsl:if> |
| 335 |
<xsl:choose> |
| 336 |
<xsl:when test="not($nested)"> |
| 337 |
<xsl:text> {</xsl:text> |
| 338 |
<!-- table alignment --> |
| 339 |
<xsl:call-template name="tbl.align.begin"> |
| 340 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 341 |
</xsl:call-template> |
| 342 |
<!-- do the actual work --> |
| 343 |
<xsl:if test="$tabletype='longtable'"> |
| 344 |
<xsl:text>\savetablecounter </xsl:text> |
| 345 |
</xsl:if> |
| 346 |
|
| 347 |
<xsl:call-template name="make.table.content"> |
| 348 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 349 |
</xsl:call-template> |
| 350 |
|
| 351 |
<xsl:if test="$tabletype='longtable'"> |
| 352 |
<xsl:text>\restoretablecounter% </xsl:text> |
| 353 |
</xsl:if> |
| 354 |
<xsl:call-template name="tbl.align.end"> |
| 355 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 356 |
</xsl:call-template> |
| 357 |
<xsl:text>} </xsl:text> |
| 358 |
</xsl:when> |
| 359 |
<xsl:otherwise> |
| 360 |
<xsl:call-template name="make.table.content"> |
| 361 |
<xsl:with-param name="tabletype" select="$tabletype"/> |
| 362 |
<xsl:with-param name="tablewidth" select="'\linewidth'"/> |
| 363 |
</xsl:call-template> |
| 364 |
</xsl:otherwise> |
| 365 |
</xsl:choose> |
| 366 |
<xsl:if test="$size!='normal'"> |
| 367 |
<xsl:text>\end{</xsl:text> |
| 368 |
<xsl:value-of select="$size"/> |
| 369 |
<xsl:text>} </xsl:text> |
| 370 |
</xsl:if> |
| 371 |
<xsl:if test="@orient='land'"> |
| 372 |
<xsl:text>\end{landscape} </xsl:text> |
| 373 |
</xsl:if> |
| 374 |
<xsl:apply-templates select="." mode="foottext"/> |
| 375 |
</xsl:template> |
| 376 |
|
| 377 |
<!-- Hook for the newtbl to decide what to do after the table head, |
| 378 |
depending on the type of table used. |
| 379 |
--> |
| 380 |
<xsl:template match="informaltable" mode="newtbl.endhead"> |
| 381 |
<xsl:param name="tabletype"/> |
| 382 |
<xsl:param name="headrows"/> |
| 383 |
<xsl:value-of select="$headrows"/> |
| 384 |
<xsl:if test="$tabletype='longtable' and $headrows!=''"> |
| 385 |
<!-- longtable endhead to put only when there's an actual head --> |
| 386 |
<xsl:text>\endhead </xsl:text> |
| 387 |
</xsl:if> |
| 388 |
</xsl:template> |
| 389 |
|
| 390 |
<xsl:template match="table" mode="newtbl.endhead"> |
| 391 |
<xsl:param name="tabletype"/> |
| 392 |
<xsl:param name="headrows"/> |
| 393 |
<xsl:choose> |
| 394 |
<xsl:when test="$tabletype='longtable'"> |
| 395 |
<!-- longtable endhead --> |
| 396 |
<xsl:choose> |
| 397 |
<xsl:when test="$table.in.float='0'"> |
| 398 |
<xsl:apply-templates select="title|caption" mode="longtable"/> |
| 399 |
<xsl:value-of select="$headrows"/> |
| 400 |
<xsl:text>\endfirsthead </xsl:text> |
| 401 |
<xsl:text>\caption[]</xsl:text> |
| 402 |
<xsl:text>{</xsl:text> |
| 403 |
<xsl:value-of select="$table.continue.caption"/> |
| 404 |
<xsl:text>}\tabularnewline </xsl:text> |
| 405 |
<xsl:value-of select="$headrows"/> |
| 406 |
<xsl:text>\endhead </xsl:text> |
| 407 |
</xsl:when> |
| 408 |
<xsl:when test="$headrows!=''"> |
| 409 |
<xsl:value-of select="$headrows"/> |
| 410 |
<xsl:text>\endhead </xsl:text> |
| 411 |
</xsl:when> |
| 412 |
</xsl:choose> |
| 413 |
</xsl:when> |
| 414 |
<xsl:otherwise> |
| 415 |
<xsl:value-of select="$headrows"/> |
| 416 |
</xsl:otherwise> |
| 417 |
</xsl:choose> |
| 418 |
</xsl:template> |
| 419 |
|
| 420 |
</xsl:stylesheet> |