| 1 |
<?xml version="1.0"?> |
| 2 |
<xsl:stylesheet version="1.0" |
| 3 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 4 |
xmlns="http://www.w3.org/1999/xhtml" |
| 5 |
xmlns:rtf="http://rtf2xml.sourceforge.net/" |
| 6 |
xmlns:c="calibre" |
| 7 |
extension-element-prefixes="c" |
| 8 |
exclude-result-prefixes="rtf" |
| 9 |
> |
| 10 |
|
| 11 |
<xsl:template match = "rtf:para"> |
| 12 |
<xsl:choose> |
| 13 |
<xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']| |
| 14 |
parent::rtf:paragraph-definition[@name='heading 2']| |
| 15 |
parent::rtf:paragraph-definition[@name='heading 3']| |
| 16 |
parent::rtf:paragraph-definition[@name='heading 4']| |
| 17 |
parent::rtf:paragraph-definition[@name='heading 5']| |
| 18 |
parent::rtf:paragraph-definition[@name='heading 6']| |
| 19 |
parent::rtf:paragraph-definition[@name='heading 7']| |
| 20 |
parent::rtf:paragraph-definition[@name='heading 8']| |
| 21 |
parent::rtf:paragraph-definition[@name='heading 9'] |
| 22 |
|
| 23 |
"> |
| 24 |
<xsl:variable name="head-number" select="substring(parent::rtf:paragraph-definition/@name, 9)"/> |
| 25 |
<xsl:element name="h{$head-number}"> |
| 26 |
<xsl:apply-templates/> |
| 27 |
</xsl:element> |
| 28 |
</xsl:when> |
| 29 |
<xsl:otherwise> |
| 30 |
<xsl:call-template name = "para"/> |
| 31 |
</xsl:otherwise> |
| 32 |
</xsl:choose> |
| 33 |
</xsl:template> |
| 34 |
|
| 35 |
<xsl:template match="rtf:style-group"> |
| 36 |
<xsl:apply-templates/> |
| 37 |
</xsl:template> |
| 38 |
|
| 39 |
<xsl:template match="rtf:paragraph-definition"> |
| 40 |
<xsl:choose> |
| 41 |
<xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']| |
| 42 |
parent::rtf:paragraph-definition[@name='heading 2']| |
| 43 |
parent::rtf:paragraph-definition[@name='heading 3']| |
| 44 |
parent::rtf:paragraph-definition[@name='heading 4']| |
| 45 |
parent::rtf:paragraph-definition[@name='heading 5']| |
| 46 |
parent::rtf:paragraph-definition[@name='heading 6']| |
| 47 |
parent::rtf:paragraph-definition[@name='heading 7']| |
| 48 |
parent::rtf:paragraph-definition[@name='heading 8']| |
| 49 |
parent::rtf:paragraph-definition[@name='heading 9'] |
| 50 |
|
| 51 |
"> |
| 52 |
<xsl:apply-templates/> |
| 53 |
</xsl:when> |
| 54 |
<xsl:otherwise> |
| 55 |
<xsl:element name="div"> |
| 56 |
<xsl:attribute name="class"> |
| 57 |
<xsl:value-of select="@style-number"/> |
| 58 |
</xsl:attribute> |
| 59 |
<xsl:apply-templates/> |
| 60 |
</xsl:element> |
| 61 |
</xsl:otherwise> |
| 62 |
</xsl:choose> |
| 63 |
</xsl:template> |
| 64 |
|
| 65 |
<xsl:template name = "para"> |
| 66 |
<xsl:element name = "p"> |
| 67 |
<xsl:choose> |
| 68 |
<xsl:when test = "normalize-space(.) or child::*"> |
| 69 |
<xsl:call-template name = "para-content"/> |
| 70 |
</xsl:when> |
| 71 |
<xsl:otherwise> |
| 72 |
<xsl:text> </xsl:text> |
| 73 |
</xsl:otherwise> |
| 74 |
</xsl:choose> |
| 75 |
</xsl:element> |
| 76 |
</xsl:template> |
| 77 |
|
| 78 |
<xsl:template name = "para_off"> |
| 79 |
<xsl:if test = "normalize-space(.) or child::*"> |
| 80 |
<xsl:element name = "p"> |
| 81 |
<xsl:attribute name = "class"> |
| 82 |
<xsl:value-of select = "../@style-number"/> |
| 83 |
</xsl:attribute> |
| 84 |
<xsl:call-template name = "para-content"/> |
| 85 |
</xsl:element> |
| 86 |
</xsl:if> |
| 87 |
</xsl:template> |
| 88 |
|
| 89 |
|
| 90 |
<xsl:template name = "para-content"> |
| 91 |
<xsl:apply-templates/> |
| 92 |
</xsl:template> |
| 93 |
|
| 94 |
<xsl:template name = "para-content_off"> |
| 95 |
<xsl:choose> |
| 96 |
<xsl:when test = "@italics = 'true' "> |
| 97 |
<emph rend = "paragraph-emph-italics"> |
| 98 |
<xsl:apply-templates/> |
| 99 |
</emph> |
| 100 |
</xsl:when> |
| 101 |
<xsl:when test = "@bold = 'true' "> |
| 102 |
<emph rend = "paragraph-emph-bold"> |
| 103 |
<xsl:apply-templates/> |
| 104 |
</emph> |
| 105 |
</xsl:when> |
| 106 |
<xsl:when test = "@underlined and @underlined != 'false'"> |
| 107 |
<emph rend = "paragraph-emph-underlined"> |
| 108 |
<xsl:apply-templates/> |
| 109 |
</emph> |
| 110 |
</xsl:when> |
| 111 |
<xsl:when test = "(@strike-through = 'true') |
| 112 |
or (@double-strike-through = 'true') |
| 113 |
or (@emboss = 'true') |
| 114 |
or (@engrave = 'true') |
| 115 |
or (@small-caps = 'true') |
| 116 |
or (@shadow = 'true') |
| 117 |
or (@hidden = 'true') |
| 118 |
or (@outline = 'true') |
| 119 |
"> |
| 120 |
<emph rend = "paragraph-emph"> |
| 121 |
<xsl:apply-templates/> |
| 122 |
</emph> |
| 123 |
</xsl:when> |
| 124 |
<xsl:otherwise> |
| 125 |
<xsl:apply-templates/> |
| 126 |
</xsl:otherwise> |
| 127 |
</xsl:choose> |
| 128 |
</xsl:template> |
| 129 |
|
| 130 |
<xsl:template name="make-header"> |
| 131 |
<head> |
| 132 |
<xsl:element name="meta"> |
| 133 |
<xsl:attribute name="name"> |
| 134 |
<xsl:text>generator</xsl:text> |
| 135 |
</xsl:attribute> |
| 136 |
<xsl:attribute name="content"> |
| 137 |
<xsl:text>http://calibre-ebook.com</xsl:text> |
| 138 |
</xsl:attribute> |
| 139 |
</xsl:element> |
| 140 |
|
| 141 |
<xsl:choose> |
| 142 |
<xsl:when test="/rtf:doc/rtf:preamble/rtf:doc-information"> |
| 143 |
<xsl:apply-templates select="/rtf:doc/rtf:preamble/rtf:doc-information" mode="header"/> |
| 144 |
</xsl:when> |
| 145 |
<xsl:otherwise> |
| 146 |
<xsl:call-template name="html-head"/> |
| 147 |
</xsl:otherwise> |
| 148 |
</xsl:choose> |
| 149 |
</head> |
| 150 |
</xsl:template> |
| 151 |
|
| 152 |
<xsl:template match="rtf:doc-information"/> |
| 153 |
|
| 154 |
<xsl:template match="rtf:doc-information" mode="header"> |
| 155 |
<link rel="stylesheet" type="text/css" href="styles.css"/> |
| 156 |
<xsl:if test="not(rtf:title)"> |
| 157 |
<title>unnamed</title> |
| 158 |
</xsl:if> |
| 159 |
<xsl:apply-templates/> |
| 160 |
</xsl:template> |
| 161 |
|
| 162 |
<xsl:template match="rtf:creation-time|rtf:doc-notes|rtf:author|rtf:revision-time"> |
| 163 |
<xsl:element name="meta"> |
| 164 |
<xsl:attribute name="name"> |
| 165 |
<xsl:value-of select="name(.)"/> |
| 166 |
</xsl:attribute> |
| 167 |
<xsl:attribute name="content"> |
| 168 |
<xsl:apply-templates/> |
| 169 |
</xsl:attribute> |
| 170 |
</xsl:element> |
| 171 |
</xsl:template> |
| 172 |
|
| 173 |
<xsl:template match="rtf:creation-time|rtf:revision-time"> |
| 174 |
<xsl:element name="meta"> |
| 175 |
<xsl:attribute name="name"> |
| 176 |
<xsl:value-of select="name(.)"/> |
| 177 |
</xsl:attribute> |
| 178 |
<xsl:attribute name="content"> |
| 179 |
<xsl:value-of select="@year"/> |
| 180 |
<xsl:text>-</xsl:text> |
| 181 |
<xsl:value-of select="@month"/> |
| 182 |
<xsl:text>-</xsl:text> |
| 183 |
<xsl:value-of select="@day"/> |
| 184 |
</xsl:attribute> |
| 185 |
</xsl:element> |
| 186 |
</xsl:template> |
| 187 |
|
| 188 |
<xsl:template match="rtf:operator|rtf:editing-time|rtf:number-of-pages|rtf:number-of-words|rtf:number-of-characters"/> |
| 189 |
|
| 190 |
|
| 191 |
<xsl:template match="rtf:title"> |
| 192 |
<xsl:element name="title"> |
| 193 |
<xsl:apply-templates/> |
| 194 |
</xsl:element> |
| 195 |
</xsl:template> |
| 196 |
|
| 197 |
|
| 198 |
<xsl:template name="html-head"> |
| 199 |
<title>unnamed</title> |
| 200 |
<link rel="stylesheet" type="text/css" href="styles.css"/> |
| 201 |
</xsl:template> |
| 202 |
|
| 203 |
<xsl:template name="make-css-stylesheet"> |
| 204 |
<xsl:document href="styles.css" method="text"> |
| 205 |
<xsl:for-each select="//rtf:paragraph-definition"> |
| 206 |
<xsl:if test = "generate-id(.) = generate-id(key('style-types', @style-number))"> |
| 207 |
<xsl:text>div.</xsl:text> |
| 208 |
<xsl:value-of select="@style-number"/> |
| 209 |
<xsl:text>{</xsl:text> |
| 210 |
<xsl:call-template name="parse-styles-attrs"/> |
| 211 |
<xsl:text>}
</xsl:text> |
| 212 |
</xsl:if> |
| 213 |
</xsl:for-each> |
| 214 |
<xsl:text>span.italic{font-style:italic}
</xsl:text> |
| 215 |
<xsl:text>span.no-italic{font-style:normal}
</xsl:text> |
| 216 |
<xsl:text>span.bold{font-weight:bold}
</xsl:text> |
| 217 |
<xsl:text>span.no-bold{font-weight:normal}
</xsl:text> |
| 218 |
<xsl:text>span.underline{text-decoration:underline}
</xsl:text> |
| 219 |
<xsl:text>span.no-underline{text-decoration:none}
</xsl:text> |
| 220 |
<xsl:text>span.italic-bold{font-style:italic;font-weight:bold}
</xsl:text> |
| 221 |
<xsl:text>span.italic-underline{font-style:italic;text-decoration:underline}
</xsl:text> |
| 222 |
<xsl:text>span.bold-underline{font-weight:bold;text-decoration:underline}
</xsl:text> |
| 223 |
<xsl:text>
</xsl:text> |
| 224 |
</xsl:document> |
| 225 |
</xsl:template> |
| 226 |
|
| 227 |
<xsl:template name="parse-styles-attrs"> |
| 228 |
<!--<xsl:text>position:relative;</xsl:text> |
| 229 |
<xsl:if test="@space-before"> |
| 230 |
<xsl:text>padding-top:</xsl:text> |
| 231 |
<xsl:value-of select="@space-before"/> |
| 232 |
<xsl:text>pt;</xsl:text> |
| 233 |
</xsl:if> |
| 234 |
<xsl:if test="@space-after"> |
| 235 |
<xsl:text>padding-bottom:</xsl:text> |
| 236 |
<xsl:value-of select="@space-after"/> |
| 237 |
<xsl:text>pt;</xsl:text> |
| 238 |
</xsl:if>--> |
| 239 |
<xsl:if test="@left-indent"> |
| 240 |
<xsl:text>padding-left:</xsl:text> |
| 241 |
<xsl:value-of select="@left-indent"/> |
| 242 |
<xsl:text>pt;</xsl:text> |
| 243 |
</xsl:if> |
| 244 |
<xsl:if test="@right-indent"> |
| 245 |
<xsl:text>padding-right:</xsl:text> |
| 246 |
<xsl:value-of select="@right-indent"/> |
| 247 |
<xsl:text>pt;</xsl:text> |
| 248 |
</xsl:if> |
| 249 |
<xsl:if test="@first-line-indent"> |
| 250 |
<xsl:text>text-indent:</xsl:text> |
| 251 |
<xsl:value-of select="@first-line-indent"/> |
| 252 |
<xsl:text>pt;</xsl:text> |
| 253 |
</xsl:if> |
| 254 |
<xsl:if test="@bold='true'"> |
| 255 |
<xsl:text>font-weight:</xsl:text> |
| 256 |
<xsl:value-of select="'bold'"/> |
| 257 |
<xsl:text>;</xsl:text> |
| 258 |
</xsl:if> |
| 259 |
<xsl:if test="@italics='true'"> |
| 260 |
<xsl:text>font-style:</xsl:text> |
| 261 |
<xsl:value-of select="'italic'"/> |
| 262 |
<xsl:text>;</xsl:text> |
| 263 |
</xsl:if> |
| 264 |
<xsl:if test="@underlined and @underlined != 'false'"> |
| 265 |
<xsl:text>text-decoration:underline</xsl:text> |
| 266 |
<xsl:text>;</xsl:text> |
| 267 |
</xsl:if> |
| 268 |
<!--<xsl:if test="@line-spacing"> |
| 269 |
<xsl:text>line-height:</xsl:text> |
| 270 |
<xsl:value-of select="@line-spacing"/> |
| 271 |
<xsl:text>pt;</xsl:text> |
| 272 |
</xsl:if>--> |
| 273 |
<xsl:if test="(@align = 'just')"> |
| 274 |
<xsl:text>text-align: justify;</xsl:text> |
| 275 |
</xsl:if> |
| 276 |
<xsl:if test="(@align = 'cent')"> |
| 277 |
<xsl:text>text-align: center;</xsl:text> |
| 278 |
</xsl:if> |
| 279 |
<xsl:if test="(@align = 'left')"> |
| 280 |
<xsl:text>text-align: left;</xsl:text> |
| 281 |
</xsl:if> |
| 282 |
<xsl:if test="(@align = 'right')"> |
| 283 |
<xsl:text>text-align: right;</xsl:text> |
| 284 |
</xsl:if> |
| 285 |
</xsl:template> |
| 286 |
|
| 287 |
<xsl:template match="rtf:inline"> |
| 288 |
<xsl:variable name="num-attrs" select="count(@*)"/> |
| 289 |
<xsl:choose> |
| 290 |
<xsl:when test="@footnote-marker"> |
| 291 |
<xsl:text>[</xsl:text> |
| 292 |
<xsl:value-of select="count(preceding::rtf:footnote) + 1"/> |
| 293 |
<xsl:text>]</xsl:text> |
| 294 |
</xsl:when> |
| 295 |
<xsl:when test="(@superscript)"> |
| 296 |
<xsl:element name="sup"> |
| 297 |
<xsl:element name="span"> |
| 298 |
<xsl:attribute name="class"> |
| 299 |
<c:inline-class/> |
| 300 |
</xsl:attribute> |
| 301 |
<xsl:apply-templates/> |
| 302 |
</xsl:element> |
| 303 |
</xsl:element> |
| 304 |
</xsl:when> |
| 305 |
<xsl:when test="(@underscript or @subscript)"> |
| 306 |
<xsl:element name="sub"> |
| 307 |
<xsl:element name="span"> |
| 308 |
<xsl:attribute name="class"> |
| 309 |
<c:inline-class/> |
| 310 |
</xsl:attribute> |
| 311 |
<xsl:apply-templates/> |
| 312 |
</xsl:element> |
| 313 |
</xsl:element> |
| 314 |
</xsl:when> |
| 315 |
<xsl:otherwise> |
| 316 |
<xsl:element name="span"> |
| 317 |
<xsl:attribute name="class"> |
| 318 |
<c:inline-class/> |
| 319 |
</xsl:attribute> |
| 320 |
<xsl:apply-templates/> |
| 321 |
</xsl:element> |
| 322 |
</xsl:otherwise> |
| 323 |
</xsl:choose> |
| 324 |
</xsl:template> |
| 325 |
|
| 326 |
<xsl:template match="rtf:footnote"/> |
| 327 |
|
| 328 |
<xsl:template match="rtf:footnote" mode="bottom"> |
| 329 |
<xsl:element name="div"> |
| 330 |
<xsl:attribute name="class"> |
| 331 |
<xsl:text>footnote</xsl:text> |
| 332 |
</xsl:attribute> |
| 333 |
<xsl:apply-templates/> |
| 334 |
</xsl:element> |
| 335 |
|
| 336 |
</xsl:template> |
| 337 |
|
| 338 |
<xsl:template match="rtf:list[@list-type='unordered']"> |
| 339 |
<xsl:element name="ul"> |
| 340 |
<xsl:apply-templates/> |
| 341 |
</xsl:element> |
| 342 |
</xsl:template> |
| 343 |
|
| 344 |
<xsl:template match="rtf:list[@list-type='ordered']"> |
| 345 |
<xsl:element name="ol"> |
| 346 |
<xsl:apply-templates/> |
| 347 |
</xsl:element> |
| 348 |
</xsl:template> |
| 349 |
|
| 350 |
<xsl:template match="rtf:item"> |
| 351 |
<xsl:element name="li"> |
| 352 |
<xsl:apply-templates/> |
| 353 |
</xsl:element> |
| 354 |
</xsl:template> |
| 355 |
|
| 356 |
<xsl:template match="rtf:item/rtf:style-group/rtf:paragraph-definition/rtf:para" priority="2"> |
| 357 |
<xsl:apply-templates/> |
| 358 |
</xsl:template> |
| 359 |
|
| 360 |
<xsl:template match="rtf:table"> |
| 361 |
<xsl:element name="table"> |
| 362 |
<xsl:attribute name="id"> |
| 363 |
<xsl:value-of select="generate-id(.)"/> |
| 364 |
</xsl:attribute> |
| 365 |
<xsl:apply-templates/> |
| 366 |
</xsl:element> |
| 367 |
</xsl:template> |
| 368 |
|
| 369 |
<xsl:template match="rtf:row"> |
| 370 |
<xsl:element name="tr"> |
| 371 |
<xsl:apply-templates/> |
| 372 |
</xsl:element> |
| 373 |
</xsl:template> |
| 374 |
|
| 375 |
<xsl:template match="rtf:cell"> |
| 376 |
<xsl:element name="td"> |
| 377 |
<xsl:if test="@class"> |
| 378 |
<xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute> |
| 379 |
</xsl:if> |
| 380 |
<xsl:apply-templates/> |
| 381 |
</xsl:element> |
| 382 |
</xsl:template> |
| 383 |
|
| 384 |
<!-- |
| 385 |
<xsl:include href="blocks.xsl"/> |
| 386 |
<xsl:include href="fields.xsl"/> |
| 387 |
--> |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
<xsl:output method = "xml"/> |
| 393 |
<xsl:key name="style-types" match="rtf:paragraph-definition" use="@style-number"/> |
| 394 |
|
| 395 |
|
| 396 |
<xsl:variable name = "delete-list-text">true</xsl:variable> |
| 397 |
<xsl:variable name = "delete-field-blocks">true</xsl:variable> |
| 398 |
<xsl:variable name = "delete-annotation">false</xsl:variable> |
| 399 |
|
| 400 |
<xsl:template match="/"> |
| 401 |
<xsl:call-template name="make-css-stylesheet"/> |
| 402 |
<html> |
| 403 |
<xsl:call-template name="make-header"/> |
| 404 |
<xsl:apply-templates/> |
| 405 |
</html> |
| 406 |
</xsl:template> |
| 407 |
|
| 408 |
<xsl:template match="rtf:doc"> |
| 409 |
<xsl:apply-templates/> |
| 410 |
</xsl:template> |
| 411 |
|
| 412 |
<xsl:template match="rtf:preamble"> |
| 413 |
<xsl:apply-templates/> |
| 414 |
</xsl:template> |
| 415 |
|
| 416 |
<xsl:template match="rtf:page-break"> |
| 417 |
<br style = "page-break-after:always"/> |
| 418 |
</xsl:template> |
| 419 |
|
| 420 |
<xsl:template match="rtf:hardline-break"> |
| 421 |
<br/> |
| 422 |
</xsl:template> |
| 423 |
|
| 424 |
<xsl:template match="rtf:rtf-definition|rtf:font-table|rtf:color-table|rtf:style-table|rtf:page-definition|rtf:list-table|rtf:override-table|rtf:override-list|rtf:list-text"/> |
| 425 |
|
| 426 |
<xsl:template match="rtf:body"> |
| 427 |
<xsl:element name="body"> |
| 428 |
<xsl:apply-templates/> |
| 429 |
<xsl:if test = "//rtf:footnote"> |
| 430 |
<hr/> |
| 431 |
</xsl:if> |
| 432 |
<xsl:for-each select="//rtf:footnote"> |
| 433 |
<xsl:apply-templates select="." mode="bottom"/> |
| 434 |
</xsl:for-each> |
| 435 |
</xsl:element> |
| 436 |
</xsl:template> |
| 437 |
|
| 438 |
<xsl:template match="rtf:section"> |
| 439 |
<xsl:element name="div"> |
| 440 |
<xsl:apply-templates/> |
| 441 |
</xsl:element> |
| 442 |
</xsl:template> |
| 443 |
|
| 444 |
<xsl:template match = "rtf:field-block"> |
| 445 |
<xsl:apply-templates/> |
| 446 |
</xsl:template> |
| 447 |
|
| 448 |
<xsl:template match = "rtf:field[@type='hyperlink']"> |
| 449 |
<xsl:element name ="a"> |
| 450 |
<xsl:attribute name = "href"> |
| 451 |
<xsl:choose> |
| 452 |
<xsl:when test="@argument"> |
| 453 |
<xsl:value-of select="@argument"/> |
| 454 |
</xsl:when> |
| 455 |
<xsl:otherwise> |
| 456 |
<xsl:if test = "not(contains(@link, '/'))">#</xsl:if> |
| 457 |
<xsl:value-of select = "@link"/> |
| 458 |
</xsl:otherwise> |
| 459 |
</xsl:choose> |
| 460 |
</xsl:attribute> |
| 461 |
<xsl:apply-templates/> |
| 462 |
</xsl:element> |
| 463 |
</xsl:template> |
| 464 |
|
| 465 |
<xsl:template match = "rtf:field[@type='bookmark-start']"> |
| 466 |
<xsl:element name ="a"> |
| 467 |
<xsl:attribute name = "id"> |
| 468 |
<xsl:value-of select = "@number"/> |
| 469 |
</xsl:attribute> |
| 470 |
<xsl:apply-templates/> |
| 471 |
</xsl:element> |
| 472 |
</xsl:template> |
| 473 |
|
| 474 |
<xsl:template match = "rtf:field"> |
| 475 |
<xsl:apply-templates/> |
| 476 |
</xsl:template> |
| 477 |
|
| 478 |
<xsl:template match="rtf:pict"> |
| 479 |
<img src = "{@num}"/> |
| 480 |
</xsl:template> |
| 481 |
|
| 482 |
<xsl:template match="*"> |
| 483 |
<xsl:message> |
| 484 |
<xsl:text>no match for element: "</xsl:text> |
| 485 |
<xsl:value-of select="name(.)"/> |
| 486 |
<xsl:text>" 
</xsl:text> |
| 487 |
</xsl:message> |
| 488 |
<xsl:apply-templates/> |
| 489 |
</xsl:template> |
| 490 |
|
| 491 |
</xsl:stylesheet> |