File size: 14,038 Bytes
8c763fb | 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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
version="1.0">
<xsl:template match="/">
<HTML>
<BODY style = "margin-top: 0; margin-left: 4; margin-bottom: 0; margin-right: 0;">
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>
<!-- CALS table -->
<!-- a priority of 10 insures that this template has a higher priority
than any templates not explicitly assigned on-->
<xsl:template match='tgroup|entrytbl' priority='10'>
<table>
<!-- handle table width -->
<!-- if the table uses proportional column widths, its width should be 100%;
otherwise, it should not be set -->
<xsl:if test='colspec[contains(@colwidth,"*") or not(@colwidth)]'>
<xsl:attribute name='width'>100%</xsl:attribute>
</xsl:if>
<!-- handle table frame attribute -->
<xsl:attribute name='style'>
border-collapse: collapse;
border-width: 1px;
border-color: black;
<xsl:variable name='frame' select='ancestor::table/@frame'/>
<xsl:choose>
<xsl:when test='$frame="sides"'>
border-left-style: solid;
border-right-style: solid;
border-top-style: hidden;
border-bottom-style: hidden;
</xsl:when>
<xsl:when test='$frame="topbot"'>
border-left-style: none;
border-right-style: none;
border-top-style: hidden;
border-bottom-style: hidden;
</xsl:when>
<xsl:when test='$frame="top"'>
border-left-style: hidden;
border-right-style: hidden;
border-top-style: solid;
border-bottom-style: hidden;
</xsl:when>
<xsl:when test='$frame="bottom"'>
border-left-style: hidden;
border-right-style: hidden;
border-top-style: hidden;
border-bottom-style: solid;
</xsl:when>
<xsl:when test='$frame="none"'>
border-left-style: hidden;
border-right-style: hidden;
border-top-style: hidden;
border-bottom-style: hidden;
</xsl:when>
<xsl:otherwise>
border-left-style: solid;
border-right-style: solid;
border-top-style: solid;
border-bottom-style: solid;
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<!-- transform colspecs -->
<xsl:for-each select='colspec'>
<col>
<!-- handle width property -->
<xsl:variable name='colwidth' select='@colwidth'/>
<xsl:choose>
<!-- "*" or empty colwidth attributes are equivalent to "1*" -->
<!-- mixed measure colwidths are handled as if they were "1*" -->
<xsl:when test='contains($colwidth,"+") or not($colwidth) or $colwidth="*"'>
<xsl:attribute name='width'>1*</xsl:attribute>
</xsl:when>
<xsl:when test='contains($colwidth,"*")'>
<xsl:attribute name='width'><xsl:value-of select='$colwidth'/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">width:
<xsl:choose>
<xsl:when test='contains($colwidth,"pi")'>
<!-- CALS and CSS use different abbreviations for picas -->
<xsl:value-of select='translate($colwidth,"i","c")'/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$colwidth'/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</col>
</xsl:for-each>
<!-- transform rows -->
<xsl:for-each select='thead|tfoot|tbody'>
<xsl:copy>
<xsl:for-each select='row'>
<tr>
<!-- transform cells -->
<xsl:for-each select='entry|entrytbl'>
<xsl:call-template name='transformCALSCell'/>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name='transformCALSCell'>
<td>
<!-- handle horizontal extension of the cell -->
<xsl:variable name='spanname' select='@spanname'/>
<xsl:variable name='namest' select='@namest'/>
<xsl:variable name='nameend' select='@nameend'/>
<xsl:choose>
<xsl:when test='$spanname'>
<xsl:variable name='spanspec' select='ancestor::*[spanspec][1]/spanspec[@spanname=$spanname]'/>
<xsl:variable name='namest_2' select='$spanspec/@namest'/>
<xsl:variable name='nameend_2' select='$spanspec/@nameend'/>
<xsl:variable name='startColumn' select='count(ancestor::*[colspec][1]/colspec[@colname=$namest_2]/preceding-sibling::*)'/>
<xsl:variable name='endColumn' select='count(ancestor::*[colspec][1]/colspec[@colname=$nameend_2]/preceding-sibling::*)'/>
<xsl:attribute name='colspan'><xsl:value-of select='$endColumn - $startColumn + 1'/></xsl:attribute>
</xsl:when>
<xsl:when test='$namest and $nameend'>
<xsl:variable name='startColumn' select='count(ancestor::*[colspec][1]/colspec[@colname=$namest]/preceding-sibling::*)'/>
<xsl:variable name='endColumn' select='count(ancestor::*[colspec][1]/colspec[@colname=$nameend]/preceding-sibling::*)'/>
<xsl:attribute name='colspan'><xsl:value-of select='$endColumn - $startColumn + 1'/></xsl:attribute>
</xsl:when>
</xsl:choose>
<!-- handle vertical extension of the cell -->
<xsl:variable name='morerows' select='@morerows'/>
<xsl:if test='$morerows'>
<xsl:attribute name='rowspan'><xsl:value-of select='$morerows+1'/></xsl:attribute>
</xsl:if>
<!-- handle horizontal alignment -->
<xsl:call-template name='findInheritedAttribute'>
<xsl:with-param name='attributeName'>align</xsl:with-param>
</xsl:call-template>
<xsl:call-template name='findInheritedAttribute'>
<xsl:with-param name='attributeName'>char</xsl:with-param>
</xsl:call-template>
<xsl:call-template name='findInheritedAttribute'>
<xsl:with-param name='attributeName'>charoff</xsl:with-param>
</xsl:call-template>
<!-- handle vertical alignment -->
<xsl:variable name='valign' select='ancestor-or-self::*[@valign][1]/@valign'/>
<xsl:attribute name='valign'>
<xsl:choose>
<xsl:when test='$valign'>
<xsl:value-of select='$valign'/>
</xsl:when>
<xsl:otherwise>
<!-- the default vertical alignment depends on whether
this cell is the table header, footer or body -->
<xsl:choose>
<xsl:when test='parent::*/parent::thead'>
bottom
</xsl:when>
<xsl:otherwise>
top
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<!-- handle borders -->
<xsl:attribute name='style'>
border-width: 1px;
border-color: black;
<xsl:call-template name='findInheritedAttribute'>
<xsl:with-param name='attributeName'>colsep</xsl:with-param>
</xsl:call-template>
<xsl:call-template name='findInheritedAttribute'>
<xsl:with-param name='attributeName'>rowsep</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<!-- transform cell content -->
<xsl:apply-templates select='.'/>
</td>
</xsl:template>
<!-- If the context node is an entry or entrytbl, searches for the value of an
inherited attribute by following the normal inheritance path. If a
value is found, calls transformInheritedAttribute with attributeName
passes as is and attributeValue set to the found value; otherwise, calls
transformInheritedAttribute with attributeValue set to the empty string.
Parameter attributeName is the name of the attribute found.
-->
<xsl:template name='findInheritedAttribute'>
<xsl:param name='attributeName'/>
<xsl:variable name='colname' select='@colname'/>
<xsl:variable name='colname_colspec' select='ancestor::*[colspec][1]/colspec[@colname=$colname]'/>
<xsl:variable name='namest' select='@namest'/>
<xsl:variable name='namest_colspec' select='ancestor::*[colspec][1]/colspec[@colname=$namest]'/>
<xsl:variable name='spanname' select='@spanname'/>
<xsl:variable name='spanspec' select='ancestor::*[spanspec][1]/spanspec[@spanname=$spanname]'/>
<xsl:variable name='span_namest' select='$spanspec/@namest'/>
<xsl:variable name='span_colspec' select='ancestor::*[colspec][1]/colspec[@colname=$span_namest]'/>
<xsl:choose>
<!-- start by looking at the context node -->
<xsl:when test='@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<!-- next, look at the containing row -->
<xsl:when test='parent::*/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='parent::*/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<!-- next, look at the spanspec -->
<xsl:when test='$spanspec/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='$spanspec/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<!-- next, look at the colspec -->
<!-- (at most one of colname_colspec, span_colspec, namest_colspec will be non-empty -->
<xsl:when test='$colname_colspec/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='$colname_colspec/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<xsl:when test='$span_colspec/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='$span_colspec/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<xsl:when test='$namest_colspec/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='$namest_colspec/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<!-- next, look at the tgroup or entrytbl -->
<xsl:when test='parent::*/parent::*/parent::*/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='parent::*/parent::*/parent::*/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<!-- next, look at the table -->
<xsl:when test='ancestor::table[1]/@*[local-name()=$attributeName]'>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='ancestor::table[1]/@*[local-name()=$attributeName]'/>
</xsl:call-template>
</xsl:when>
<!-- it wasn't found -->
<xsl:otherwise>
<xsl:call-template name='transformInheritedAttribute'>
<xsl:with-param name='attributeName' select='$attributeName'/>
<xsl:with-param name='attributeValue' select='""'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Transforms a CALS table attribute found using findInheritedAttribute
into an HTML table attribute.
Parameter attributeName is the name of the found attribute. Parameter
attributeValue is its value.
-->
<xsl:template name='transformInheritedAttribute'>
<xsl:param name='attributeName'/>
<xsl:param name='attributeValue'/>
<xsl:choose>
<!-- transform colsep -->
<!-- colseps are transformed while outputting a style attribute -->
<xsl:when test='$attributeName = "colsep"'>
<xsl:choose>
<xsl:when test='$attributeValue = "0"'>
border-right-style: none;
</xsl:when>
<xsl:otherwise>
border-right-style: solid;
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- transform rowsep -->
<!-- rowseps are transformed while outputting a style attribute -->
<xsl:when test='$attributeName = "rowsep"'>
<xsl:choose>
<xsl:when test='$attributeValue = "0"'>
border-bottom-style: none;
</xsl:when>
<xsl:otherwise>
border-bottom-style: solid;
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- transform align -->
<!-- default to left if no value is specified -->
<xsl:when test='$attributeName = "align"'>
<xsl:attribute name='align'>
<xsl:choose>
<xsl:when test='$attributeValue'>
<xsl:value-of select="$attributeValue"/>
</xsl:when>
<xsl:otherwise>
left
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:when>
<!-- transform char -->
<!-- default to no char attribute if no value is specified -->
<xsl:when test='$attributeName = "char"'>
<xsl:if test='$attributeValue'>
<xsl:attribute name='char'>
<xsl:value-of select="$attributeValue"/>
</xsl:attribute>
</xsl:if>
</xsl:when>
<!-- transform charoff -->
<!-- default to 50% if no value is specified -->
<xsl:when test='$attributeName = "charoff"'>
<xsl:attribute name='charoff'>
<xsl:choose>
<xsl:when test='$attributeValue'>
<!-- CALS charoffs are implicitly percentages -->
<xsl:value-of select="$attributeValue"/>%
</xsl:when>
<xsl:otherwise>
50%
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|