1
#########################################################################
4
# copyright 2002 Paul Henry Tremblay #
6
# This program is distributed in the hope that it will be useful, #
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
9
# General Public License for more details. #
11
# You should have received a copy of the GNU General Public License #
12
# along with this program; if not, write to the Free Software #
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #
17
#########################################################################
21
<xsl:stylesheet version="1.0"
22
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23
xmlns:html="http://www.w3.org/1999/xhtml"
24
xmlns:rtf="http://rtf2xml.sourceforge.net/"
25
exclude-result-prefixes="rtf"
28
<xsl:template match = "rtf:para">
30
<xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']|
31
parent::rtf:paragraph-definition[@name='heading 2']|
32
parent::rtf:paragraph-definition[@name='heading 3']|
33
parent::rtf:paragraph-definition[@name='heading 4']|
34
parent::rtf:paragraph-definition[@name='heading 5']|
35
parent::rtf:paragraph-definition[@name='heading 6']|
36
parent::rtf:paragraph-definition[@name='heading 7']|
37
parent::rtf:paragraph-definition[@name='heading 8']|
38
parent::rtf:paragraph-definition[@name='heading 9']
41
<xsl:variable name="head-number" select="substring(parent::rtf:paragraph-definition/@name, 9)"/>
42
<xsl:element name="h{$head-number}">
43
<xsl:apply-templates/>
47
<xsl:call-template name = "para"/>
52
<xsl:template match="rtf:style-group">
53
<xsl:apply-templates/>
56
<xsl:template match="rtf:paragraph-definition">
58
<xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']|
59
parent::rtf:paragraph-definition[@name='heading 2']|
60
parent::rtf:paragraph-definition[@name='heading 3']|
61
parent::rtf:paragraph-definition[@name='heading 4']|
62
parent::rtf:paragraph-definition[@name='heading 5']|
63
parent::rtf:paragraph-definition[@name='heading 6']|
64
parent::rtf:paragraph-definition[@name='heading 7']|
65
parent::rtf:paragraph-definition[@name='heading 8']|
66
parent::rtf:paragraph-definition[@name='heading 9']
69
<xsl:apply-templates/>
72
<xsl:element name="div">
73
<xsl:attribute name="class">
74
<xsl:value-of select="@style-number"/>
76
<xsl:apply-templates/>
82
<xsl:template name = "para">
83
<xsl:if test = "normalize-space(.) or child::*">
84
<xsl:element name = "p">
85
<xsl:call-template name = "para-content"/>
90
<xsl:template name = "para_off">
91
<xsl:if test = "normalize-space(.) or child::*">
92
<xsl:element name = "p">
93
<xsl:attribute name = "class">
94
<xsl:value-of select = "../@style-number"/>
96
<xsl:call-template name = "para-content"/>
102
<xsl:template name = "para-content">
103
<xsl:apply-templates/>
106
<xsl:template name = "para-content_off">
108
<xsl:when test = "@italics = 'true' ">
109
<emph rend = "paragraph-emph-italics">
110
<xsl:apply-templates/>
113
<xsl:when test = "@bold = 'true' ">
114
<emph rend = "paragraph-emph-bold">
115
<xsl:apply-templates/>
118
<xsl:when test = "@underlined">
119
<emph rend = "paragraph-emph-underlined">
120
<xsl:apply-templates/>
123
<xsl:when test = "(@strike-through = 'true')
124
or (@double-strike-through = 'true')
125
or (@emboss = 'true')
126
or (@engrave = 'true')
127
or (@small-caps = 'true')
128
or (@shadow = 'true')
129
or (@hidden = 'true')
130
or (@outline = 'true')
133
<emph rend = "paragraph-emph">
134
<xsl:apply-templates/>
138
<xsl:apply-templates/>
143
<xsl:template name="make-header">
145
<xsl:element name="meta">
146
<xsl:attribute name="name">
147
<xsl:text>generator</xsl:text>
149
<xsl:attribute name="content">
150
<xsl:text>http://rtf2xml.sourceforge.net/</xsl:text>
155
<xsl:when test="/rtf:doc/rtf:preamble/rtf:doc-information">
156
<xsl:apply-templates select="/rtf:doc/rtf:preamble/rtf:doc-information" mode="header"/>
159
<xsl:call-template name="html-head"/>
165
<xsl:template match="rtf:doc-information"/>
167
<xsl:template match="rtf:doc-information" mode="header">
168
<link rel="stylesheet" type="text/css" href="styles.css"/>
169
<xsl:if test="not(rtf:title)">
170
<title>unamed</title>
172
<xsl:apply-templates/>
175
<xsl:template match="rtf:creation-time|rtf:doc-notes|rtf:author|rtf:revision-time">
176
<xsl:element name="meta">
177
<xsl:attribute name="name">
178
<xsl:value-of select="name(.)"/>
180
<xsl:attribute name="content">
181
<xsl:apply-templates/>
186
<xsl:template match="rtf:creation-time|rtf:revision-time">
187
<xsl:element name="meta">
188
<xsl:attribute name="name">
189
<xsl:value-of select="name(.)"/>
191
<xsl:attribute name="content">
192
<xsl:value-of select="@year"/>
193
<xsl:text>-</xsl:text>
194
<xsl:value-of select="@month"/>
195
<xsl:text>-</xsl:text>
196
<xsl:value-of select="@day"/>
201
<xsl:template match="rtf:operator|rtf:editing-time|rtf:number-of-pages|rtf:number-of-words|rtf:number-of-characters"/>
204
<xsl:template match="rtf:title">
205
<xsl:element name="title">
206
<xsl:apply-templates/>
211
<xsl:template name="html-head">
212
<title>unnamed</title>
213
<link rel="stylesheet" type="text/css" href="styles.css"/>
216
<xsl:template name="make-css-stylesheet">
217
<xsl:document href="styles.css" method="text">
218
<xsl:for-each select="//rtf:paragraph-definition">
219
<xsl:if test = "generate-id(.) = generate-id(key('style-types', @style-number))">
220
<xsl:text>div.</xsl:text>
221
<xsl:value-of select="@style-number"/>
222
<xsl:text>{</xsl:text>
223
<xsl:call-template name="parse-styles-attrs"/>
224
<xsl:text>}
</xsl:text>
227
<xsl:text>span.italic{font-style:italic}
</xsl:text>
228
<xsl:text>span.no-italic{font-style:normal}
</xsl:text>
229
<xsl:text>span.bold{font-weight:bold}
</xsl:text>
230
<xsl:text>span.no-bold{font-weight:normal}
</xsl:text>
231
<xsl:text>span.underline{text-decoration:underline}
</xsl:text>
232
<xsl:text>span.no-underline{text-decoration:none}
</xsl:text>
233
<xsl:text>span.italic-bold{font-style:italic;font-weight:bold}
</xsl:text>
234
<xsl:text>span.italic-underline{font-style:italic;text-decoration:underline}
</xsl:text>
235
<xsl:text>span.bold-underline{font-weight:bold;text-decoration:underline}
</xsl:text>
236
<xsl:for-each select="//rtf:inline">
237
<xsl:call-template name="parse-inline"/>
242
<xsl:template name="parse-styles-attrs">
243
<xsl:text>position:relative;</xsl:text>
244
<xsl:if test="@space-before">
245
<xsl:text>padding-top:</xsl:text>
246
<xsl:value-of select="@space-before"/>
247
<xsl:text>pt;</xsl:text>
249
<xsl:if test="@space-after">
250
<xsl:text>padding-bottom:</xsl:text>
251
<xsl:value-of select="@space-after"/>
252
<xsl:text>pt;</xsl:text>
254
<xsl:if test="@left-indent">
255
<xsl:text>padding-left:</xsl:text>
256
<xsl:value-of select="@left-indent"/>
257
<xsl:text>pt;</xsl:text>
259
<xsl:if test="@right-indent">
260
<xsl:text>padding-right:</xsl:text>
261
<xsl:value-of select="@right-indent"/>
262
<xsl:text>pt;</xsl:text>
264
<xsl:if test="@first-line-indent">
265
<xsl:text>text-indent:</xsl:text>
266
<xsl:value-of select="@first-line-indent"/>
267
<xsl:text>pt;</xsl:text>
269
<xsl:if test="@bold='true'">
270
<xsl:text>font-weight:</xsl:text>
271
<xsl:value-of select="'bold'"/>
272
<xsl:text>;</xsl:text>
274
<xsl:if test="@italics='true'">
275
<xsl:text>font-style:</xsl:text>
276
<xsl:value-of select="'italic'"/>
277
<xsl:text>;</xsl:text>
279
<xsl:if test="@underline and @underline != 'false'">
280
<xsl:text>text-decoration:underline</xsl:text>
281
<xsl:text>;</xsl:text>
283
<xsl:if test="@line-spacing">
284
<xsl:text>line-height:</xsl:text>
285
<xsl:value-of select="@line-height"/>
286
<xsl:text>pt;</xsl:text>
290
<xsl:template name="parse-inline">
291
<xsl:variable name="num-attrs" select="count(@*)"/>
293
<xsl:when test="$num-attrs = 1 and @italics"/>
294
<xsl:when test="$num-attrs = 1 and @bold"/>
295
<xsl:when test="$num-attrs = 1 and @underline"/>
296
<xsl:when test="$num-attrs = 2 and @italics and @bold"/>
297
<xsl:when test="$num-attrs = 2 and @italcs and @underline"/>
298
<xsl:when test="$num-attrs = 2 and @bold and @underline"/>
300
<xsl:text>span.</xsl:text>
301
<xsl:value-of select="generate-id(.)"/>
302
<xsl:text>{</xsl:text>
303
<xsl:if test="@italics = 'true'">
304
<xsl:text>font-style:italic;</xsl:text>
306
<xsl:if test="@italics = 'false'">
307
<xsl:text>font-style:normal;</xsl:text>
309
<xsl:if test="@bold = 'true'">
310
<xsl:text>font-weight:bold;</xsl:text>
312
<xsl:if test="@bold = 'false'">
313
<xsl:text>font-weight:normal;</xsl:text>
315
<xsl:if test="@underline and @underline != 'false'">
316
<xsl:text>text-decoration:underline;</xsl:text>
318
<xsl:if test="@underline= 'false'">
319
<xsl:text>text-decoration:none;</xsl:text>
321
<xsl:if test="@strike-through = 'true'">
322
<xsl:text>text-decoration:line-through;</xsl:text>
324
<xsl:if test="@strike-through = 'false'">
325
<xsl:text>text-decoration:none;</xsl:text>
327
<xsl:if test="@font-size">
328
<xsl:text>font-size:</xsl:text>
329
<xsl:value-of select="@font-size"/>
330
<xsl:text>pt;</xsl:text>
332
<xsl:text>}</xsl:text>
337
<xsl:template match="rtf:inline">
338
<xsl:variable name="num-attrs" select="count(@*)"/>
340
<xsl:when test="@footnote-marker">
341
<xsl:text>[</xsl:text>
342
<xsl:value-of select="count(preceding::rtf:footnote) + 1"/>
343
<xsl:text>]</xsl:text>
346
<xsl:element name="span">
347
<xsl:attribute name="class">
349
<xsl:when test="$num-attrs=1 and @italics='true'">
350
<xsl:text>italic</xsl:text>
352
<xsl:when test="$num-attrs=1 and @italics='false'">
353
<xsl:text>no-italic</xsl:text>
355
<xsl:when test="$num-attrs=1 and @bold='true'">
356
<xsl:text>bold</xsl:text>
358
<xsl:when test="$num-attrs=1 and @bold='true'">
359
<xsl:text>bold</xsl:text>
361
<xsl:when test="$num-attrs=1 and @bold='false'">
362
<xsl:text>no-bold</xsl:text>
364
<xsl:when test="$num-attrs=1 and @underlined">
366
<xsl:when test="not(@underlined='false')">
367
<xsl:text>underline</xsl:text>
370
<xsl:text>no-underline</xsl:text>
374
<xsl:when test="$num-attrs=2 and @bold='true' and @italics='true'">
375
<xsl:text>italic-bold</xsl:text>
377
<xsl:when test="$num-attrs=2 and @italics='true' and @underline and @underline != 'false'">
378
<xsl:text>italic-underline</xsl:text>
380
<xsl:when test="$num-attrs=2 and @bold='true' and @underline and @underline != 'false'">
381
<xsl:text>bold-underline</xsl:text>
384
<xsl:value-of select="generate-id(.)"/>
388
<xsl:apply-templates/>
395
<xsl:template match="rtf:footnote"/>
397
<xsl:template match="rtf:footnote" mode="bottom">
398
<xsl:element name="div">
399
<xsl:attribute name="class">
400
<xsl:text>footnote</xsl:text>
402
<xsl:apply-templates/>
407
<xsl:template match="rtf:list[@list-type='unordered']">
408
<xsl:element name="ul">
409
<xsl:apply-templates/>
413
<xsl:template match="rtf:list[@list-type='ordered']">
414
<xsl:element name="ol">
415
<xsl:apply-templates/>
419
<xsl:template match="rtf:item">
420
<xsl:element name="li">
421
<xsl:apply-templates/>
425
<xsl:template match="rtf:item/rtf:style-group/rtf:paragraph-definition/rtf:para" priority="2">
426
<xsl:apply-templates/>
429
<xsl:template match="rtf:table">
430
<xsl:element name="table">
431
<xsl:attribute name="id">
432
<xsl:value-of select="generate-id(.)"/>
434
<xsl:apply-templates/>
438
<xsl:template match="rtf:row">
439
<xsl:element name="row">
440
<xsl:apply-templates/>
444
<xsl:template match="rtf:cell">
445
<xsl:element name="cell">
446
<xsl:apply-templates/>
451
<xsl:include href="blocks.xsl"/>
452
<xsl:include href="fields.xsl"/>
458
<xsl:output method = "xml"/>
460
<xsl:key name="style-types" match="rtf:paragraph-definition" use="@style-number"/>
463
<xsl:variable name = "delete-list-text">true</xsl:variable>
464
<xsl:variable name = "delete-field-blocks">true</xsl:variable>
465
<xsl:variable name = "delete-annotation">false</xsl:variable>
467
<xsl:template match="/">
468
<xsl:call-template name="make-css-stylesheet"/>
470
<xsl:call-template name="make-header"/>
471
<xsl:apply-templates/>
475
<xsl:template match="rtf:doc">
476
<xsl:apply-templates/>
479
<xsl:template match="rtf:preamble">
480
<xsl:apply-templates/>
483
<xsl:template match="rtf:page-break">
484
<xsl:element name="br">
485
<xsl:attribute name="style">page-break-after:always</xsl:attribute>
489
<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"/>
491
<xsl:template match="rtf:body">
492
<xsl:element name="body">
493
<xsl:apply-templates/>
494
<xsl:if test = "//rtf:footnote">
497
<xsl:for-each select="//rtf:footnote">
498
<xsl:apply-templates select="." mode="bottom"/>
503
<xsl:template match="rtf:section">
504
<xsl:element name="div">
505
<xsl:apply-templates/>
509
<xsl:template match = "rtf:field-block">
510
<xsl:apply-templates/>
513
<xsl:template match = "rtf:field[@type='hyperlink']">
514
<xsl:element name ="a">
515
<xsl:attribute name = "href">
516
<xsl:value-of select = "@link"/>
518
<xsl:apply-templates/>
522
<xsl:template match = "rtf:field">
523
<xsl:apply-templates/>
526
<xsl:template match="rtf:pict" />
528
<xsl:template match="*">
530
<xsl:text>no match for element: "</xsl:text>
531
<xsl:value-of select="name(.)"/>
532
<xsl:text>" 
</xsl:text>
534
<xsl:apply-templates/>
b'\\ No newline at end of file'