/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to xml.files/odt/export/odt2mediawiki.xsl

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
 
 
3
<!-- 
 
4
        odt2wiki: OpenDocument to WikiMedia transformation
 
5
    Copyright (C) 2007  Bernhard Haumacher (haui at haumacher dot de)
 
6
 
 
7
    This program is free software; you can redistribute it and/or modify
 
8
    it under the terms of the GNU General Public License as published by
 
9
    the Free Software Foundation; either version 2 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License along
 
18
    with this program; if not, write to the Free Software Foundation, Inc.,
 
19
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 
20
-->
 
21
<stylesheet version="1.0" 
 
22
        xmlns="http://www.w3.org/1999/XSL/Transform"
 
23
 
 
24
        xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
 
25
        xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
 
26
        xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
 
27
        xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
 
28
        xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
 
29
        xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
 
30
        xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
 
31
        xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
 
32
        xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
 
33
        xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
 
34
        xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
 
35
        xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
 
36
        xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
 
37
        xmlns:xlink="http://www.w3.org/1999/xlink" 
 
38
        xmlns:dc="http://purl.org/dc/elements/1.1/" 
 
39
        xmlns:math="http://www.w3.org/1998/Math/MathML" 
 
40
        xmlns:dom="http://www.w3.org/2001/xml-events" 
 
41
        xmlns:xforms="http://www.w3.org/2002/xforms" 
 
42
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 
43
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
44
>
 
45
        
 
46
        <!-- 
 
47
                == Customization options ==
 
48
        -->
 
49
 
 
50
        <!-- Constant defining the newline token. -->
 
51
        <param name="NL" select="'&#10;'"/>
 
52
 
 
53
        <!-- String that a tabulator is expanded with in preformatted paragraphs. -->
 
54
        <param name="CODE_TAB_REPLACEMENT">
 
55
                <variable name="document-value"
 
56
                        select="/office:document/office:meta/meta:user-defined[@meta:name='CODE_TAB_REPLACEMENT']"/>
 
57
                <choose>
 
58
                        <when test="boolean($document-value)">
 
59
                                <value-of select="$document-value"/>
 
60
                        </when>
 
61
                        
 
62
                        <otherwise>
 
63
                                <value-of select="'    '"/>
 
64
                        </otherwise>
 
65
                </choose>
 
66
        </param>
 
67
        
 
68
        <!-- 
 
69
                Switch that suppresses separation of paragraphs with empty lines. 
 
70
                (Set to 1 to activate) -->
 
71
        <param name="CODE_JOIN_PARAGRAPHS" 
 
72
                select="boolean(string(/office:document/office:meta/meta:user-defined[@meta:name='CODE_JOIN_PARAGRAPHS']) != 'false')"/>
 
73
        
 
74
        <param name="CODE_STYLES">
 
75
                <variable name="document-value"
 
76
                        select="/office:document/office:meta/meta:user-defined[@meta:name='CODE_STYLES']"/>
 
77
                <choose>
 
78
                        <when test="boolean($document-value)">
 
79
                                <value-of select="$document-value"/>
 
80
                        </when>
 
81
                        
 
82
                        <otherwise>
 
83
                                <value-of select="''"/>
 
84
                        </otherwise>
 
85
                </choose>
 
86
        </param>
 
87
 
 
88
        <!-- 
 
89
                == Wiki style constants == 
 
90
        -->
 
91
        
 
92
        <!-- Bold character style. -->
 
93
        <variable name="BOLD_BIT" select="1"/>
 
94
 
 
95
        <!-- Italic character style. -->
 
96
        <variable name="ITALIC_BIT" select="2"/>
 
97
 
 
98
        <!-- Subscript character style. -->
 
99
        <variable name="SUBSCRIPT_BIT" select="4"/>
 
100
 
 
101
        <!-- Superscript character style. -->
 
102
        <variable name="SUPERSCRIPT_BIT" select="8"/>
 
103
 
 
104
        <!-- Typewriter character style. -->
 
105
        <variable name="TYPEWRITER_BIT" select="16"/>
 
106
        
 
107
        <!-- Preformatted text paragraph style. -->
 
108
        <variable name="CODE_BIT" select="32"/>
 
109
 
 
110
        <!-- Centered paragraph style. -->
 
111
        <variable name="CENTER_BIT" select="64"/>
 
112
 
 
113
        <!-- Right aligned paragraph style. -->
 
114
        <variable name="RIGHT_BIT" select="128"/>
 
115
        
 
116
        <!-- Constant defining the empty style. -->
 
117
        <variable name="NO_STYLE" select="0"/>
 
118
 
 
119
 
 
120
 
 
121
        <output 
 
122
                method="text" 
 
123
                media-type="text/plain" 
 
124
                encoding="UTF-8"
 
125
        />
 
126
 
 
127
 
 
128
        <!-- 
 
129
                == Reference resolution == 
 
130
        -->
 
131
 
 
132
        <key
 
133
                name="style-ref"
 
134
                match="//style:style"
 
135
                use="@style:name"
 
136
        />
 
137
 
 
138
        <key
 
139
                name="list-style-ref"
 
140
                match="//text:list-style"
 
141
                use="@style:name"
 
142
        />
 
143
        
 
144
        <key
 
145
                name="font-face-ref"
 
146
                match="//style:font-face"
 
147
                use="@style:name"
 
148
        />
 
149
        
 
150
        <key
 
151
                name="reference-resolution"
 
152
                match="//text:reference-mark | //text:reference-mark-start"
 
153
                use="@text:name"
 
154
        />
 
155
 
 
156
 
 
157
        <!-- 
 
158
                Multiple pages (draw only)
 
159
        -->
 
160
 
 
161
        <template match="draw:page">
 
162
                <value-of select="concat('&#10;&lt;!-- Page ', @draw:name, '--&gt;&#10;')"/>
 
163
                <apply-templates/>
 
164
                <value-of select="'&#10;----&#10;&#10;'"/>
 
165
        </template>
 
166
 
 
167
 
 
168
        <!-- 
 
169
                == Lists == 
 
170
        -->
 
171
 
 
172
        <template match="text:list">
 
173
                <!-- 
 
174
                        Check, whether this list is used to implement the outline numbering 
 
175
                        for headings. Such list must not be exported, because within the wiki, 
 
176
                        automatic outline numbering is performed. An outline list has a single 
 
177
                        text:h element as its single leaf grandchild. 
 
178
                        
 
179
                        This method of section numbering seems not to be used when creating new
 
180
                        documents with OpenOffice.org 2.2, but the document containing the 
 
181
                        OpenDocument specification version 1.1 uses such numbering through nested 
 
182
                        lists.
 
183
                        -->
 
184
                <choose>
 
185
                        <when test="boolean(./descendant::node()[not(./self::text:list) and not(./self::text:list-item) and not(./ancestor-or-self::text:h)])">
 
186
                                <apply-templates/>
 
187
                        </when>
 
188
                        
 
189
                        <otherwise>
 
190
                                <apply-templates select=".//text:h"/>
 
191
                        </otherwise>
 
192
                </choose>
 
193
        </template>
 
194
        
 
195
        <template match="text:list-item">
 
196
                <if test="position() &gt; 1 or boolean(ancestor::text:list-item)">
 
197
                        <value-of select="$NL"/>
 
198
                </if>
 
199
                <variable name="list-style" 
 
200
                        select="key('list-style-ref',ancestor::text:list[boolean(@text:style-name)][1]/@text:style-name)"/>
 
201
                <call-template name="mk-list-token">
 
202
                        <with-param name="list-style" select="$list-style"/>
 
203
                        <with-param name="level" select="count(ancestor::text:list)"/>
 
204
                </call-template>
 
205
                <text> </text>
 
206
                <apply-templates/>
 
207
                <if test="position() = last() and not(boolean(ancestor::text:list-item))">
 
208
                        <!-- End of (potentially nested) list is marked with a double newline. -->
 
209
                        <value-of select="$NL"/>
 
210
                        <value-of select="$NL"/>
 
211
                </if>
 
212
        </template>
 
213
        
 
214
        <template name="mk-list-token">
 
215
                <param name="list-style"/>
 
216
                <param name="level"/>
 
217
                
 
218
                <if test="$level &gt; 1">
 
219
                        <call-template name="mk-list-token">
 
220
                                <with-param name="list-style" select="$list-style"/>
 
221
                                <with-param name="level" select="$level - 1"/>
 
222
                        </call-template>
 
223
                </if>
 
224
 
 
225
                <variable name="number-style" select="$list-style/text:list-level-style-number[@text:level=$level]"/>
 
226
                <variable name="bullet-style" select="$list-style/text:list-level-style-bullet[@text:level=$level]"/>
 
227
                <choose>
 
228
                        <when test="boolean($number-style)">
 
229
                                <choose>
 
230
                                        <when test="string-length($number-style/@style:num-format) &gt; 0">
 
231
                                                <text>#</text>
 
232
                                        </when>
 
233
                                        <otherwise>
 
234
                                                <text>:</text>
 
235
                                        </otherwise>
 
236
                                </choose>
 
237
                        </when>
 
238
                        <when test="boolean($bullet-style)">
 
239
                                <text>*</text>
 
240
                        </when>
 
241
                </choose>
 
242
        </template>
 
243
 
 
244
 
 
245
        <!-- 
 
246
                == Headings ==
 
247
        -->
 
248
 
 
249
        <template match="text:h">
 
250
                <if test="string-length(.) &gt; 0">
 
251
                        <variable name="token">
 
252
                                <call-template name="mk-heading-prefix">
 
253
                                        <with-param name="level" select="@text:outline-level"/>
 
254
                                </call-template>
 
255
                        </variable>
 
256
                        <value-of select="$token"/>
 
257
                        <text> </text>
 
258
                        <apply-templates/>
 
259
                        <text> </text>
 
260
                        <value-of select="$token"/>
 
261
                        <value-of select="$NL"/>
 
262
                </if>
 
263
        </template>
 
264
 
 
265
        <template match="text:index-title">
 
266
                <text>== </text>
 
267
                <apply-templates/>
 
268
                <text> ==</text>
 
269
                <value-of select="$NL"/>
 
270
        </template>
 
271
 
 
272
        <!-- 
 
273
                Function generating a wiki heading prefix.
 
274
                
 
275
                @param level
 
276
                        The heading level. The value must be between 1 and 5.
 
277
        -->
 
278
        <template name="mk-heading-prefix">
 
279
                <param name="level"/>
 
280
                <choose>
 
281
                        <when test="$level &gt; 5">
 
282
                                <call-template name="mk-heading-prefix">
 
283
                                        <with-param name="level" select="5"/>
 
284
                                </call-template>
 
285
                        </when>
 
286
                        <when test="$level &gt; 0">
 
287
                                <text>=</text>
 
288
                                <call-template name="mk-heading-prefix">
 
289
                                        <with-param name="level" select="$level - 1"/>
 
290
                                </call-template>
 
291
                        </when>
 
292
                </choose>
 
293
        </template>
 
294
 
 
295
        <!-- 
 
296
                Funktion generating a token consisting of the given character 
 
297
                repeated 'level' times.
 
298
                
 
299
                @param level
 
300
                        The lengh of the result.
 
301
                @param char
 
302
                        The character that should be repeated 'level' times.
 
303
        -->
 
304
        <template name="mk-token">
 
305
                <param name="level"/>
 
306
                <param name="char"/>
 
307
                <if test="$level &gt; 0">
 
308
                        <value-of select="$char"/>
 
309
                        <call-template name="mk-token">
 
310
                                <with-param name="level" select="$level - 1"/>
 
311
                                <with-param name="char" select="$char"/>
 
312
                        </call-template>
 
313
                </if>
 
314
        </template>
 
315
        
 
316
        
 
317
        <!-- 
 
318
                == Tables ==
 
319
         -->
 
320
 
 
321
        <template match="table:table">
 
322
                <text>&#10;</text>
 
323
                <text>{| class="prettytable"</text>
 
324
                <text>&#10;</text>
 
325
                <apply-templates/>
 
326
                <text>&#10;</text>
 
327
                <text>|}</text>
 
328
                <text>&#10;</text>
 
329
        </template>
 
330
 
 
331
        <template match="table:table-header-rows">
 
332
                <apply-templates/>
 
333
        </template>
 
334
 
 
335
        <template match="table:table-row[position() &lt; last()] | table:table-header-rows/table:table-row">
 
336
                <apply-templates/>
 
337
                <text>&#10;</text>
 
338
                <text>|-</text>
 
339
                <text>&#10;</text>
 
340
        </template>
 
341
 
 
342
        <template match="table:table-row">
 
343
                <apply-templates/>
 
344
        </template>
 
345
 
 
346
        <template match="table:table-header-rows//table:table-cell">
 
347
                <text>! </text>
 
348
                <if test="@table:number-columns-spanned">
 
349
                        <text>colspan="</text>
 
350
                        <value-of select="@table:number-columns-spanned"/>
 
351
                        <text>" | </text>
 
352
                </if>
 
353
                <apply-templates/>
 
354
                <value-of select="$NL"/>
 
355
        </template>
 
356
 
 
357
        <template match="table:table-cell">
 
358
                <text>| </text>
 
359
                <if test="@table:number-columns-spanned">
 
360
                        <text>colspan="</text>
 
361
                        <value-of select="@table:number-columns-spanned"/>
 
362
                        <text>" | </text>
 
363
                </if>
 
364
                <apply-templates/>
 
365
                <value-of select="$NL"/>
 
366
        </template>
 
367
 
 
368
 
 
369
        <!-- 
 
370
                == WikiMath == 
 
371
         -->
 
372
 
 
373
        <template match="text:span[@text:style-name='WikiMath']">
 
374
                <value-of select="'&lt;math&gt;'"/>
 
375
                <apply-templates/>
 
376
                <value-of select="'&lt;/math&gt;'"/>
 
377
        </template>
 
378
 
 
379
 
 
380
        <!-- 
 
381
                == Native links == 
 
382
         -->
 
383
 
 
384
        <template match="text:a">
 
385
                <variable name="link-ref" select="@xlink:href"/>
 
386
                <choose>
 
387
                        <when test="string-length($link-ref) &gt; 0">
 
388
                                <variable name="link-label" select="string(.)"/>
 
389
                                <text>[</text>
 
390
                                <value-of select="$link-ref"/>
 
391
                                <text> </text>
 
392
                                <value-of select="$link-label"/>
 
393
                                <text>]</text>
 
394
                        </when>
 
395
                        
 
396
                        <otherwise>
 
397
                                <apply-templates/>
 
398
                        </otherwise>
 
399
                </choose>
 
400
        </template>
 
401
 
 
402
 
 
403
        <!-- 
 
404
                == WikiLink == 
 
405
         -->
 
406
 
 
407
        <template match="text:span[@text:style-name='WikiLink']">
 
408
                <value-of select="'[['"/>
 
409
                <variable name="link-def" select="string(.)"/>
 
410
                <variable name="link-label" select="normalize-space(substring-before($link-def, '['))"/>
 
411
                <variable name="link-ref" select="normalize-space(substring-before(substring-after($link-def, '['), ']'))"/>
 
412
                <choose>
 
413
                        <when test="boolean($link-ref)">
 
414
                        <value-of select="concat($link-ref, '|', $link-label)"/>
 
415
                </when>
 
416
                <otherwise>
 
417
                        <value-of select="$link-def"/>
 
418
                </otherwise>
 
419
                </choose>
 
420
                <value-of select="']]'"/>
 
421
        </template>
 
422
        
 
423
        
 
424
        <!-- 
 
425
                == Paragraphs == 
 
426
         -->
 
427
 
 
428
        <template match="text:p[string-length(.) &gt; 0]">
 
429
                <variable name="style">
 
430
                        <call-template name="mk-style-set">
 
431
                                <with-param name="node" select="."/>
 
432
                        </call-template>
 
433
                </variable>
 
434
 
 
435
                <variable name="code" 
 
436
                        select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
 
437
                <variable name="center" 
 
438
                        select="($style mod (2 * $CENTER_BIT)) - ($style mod ($CENTER_BIT)) != 0"/>
 
439
                <variable name="right" 
 
440
                        select="($style mod (2 * $RIGHT_BIT)) - ($style mod ($RIGHT_BIT)) != 0"/>
 
441
                
 
442
                <choose>
 
443
                        <when test="$center">
 
444
                                <text>&lt;center&gt;</text>
 
445
                        </when>
 
446
                        <when test="$right">
 
447
                                <text>&lt;div align="right"&gt;</text>
 
448
                        </when>
 
449
                        <when test="$code">
 
450
                                <value-of select="' '"/>
 
451
                        </when>
 
452
                </choose>
 
453
        
 
454
                <apply-templates/>
 
455
 
 
456
                <choose>
 
457
                        <when test="$center">
 
458
                                <text>&lt;/center&gt;</text>
 
459
                        </when>
 
460
                        <when test="$right">
 
461
                                <text>&lt;/div&gt;</text>
 
462
                        </when>
 
463
                </choose>
 
464
 
 
465
                <variable name="paragraph-right" 
 
466
                        select="./following-sibling::*[1]/self::text:p"/>
 
467
 
 
468
                <choose>
 
469
                <when test="boolean($paragraph-right)">
 
470
                        <!-- 
 
471
                                Insert end of line only if not within a list. Within wiki lists, 
 
472
                                a line break leaves the current list item. 
 
473
                        -->
 
474
                        <choose>
 
475
                                <when test="boolean(ancestor::text:list-item)">
 
476
                                        <text>&lt;br/&gt; </text>
 
477
                                </when>
 
478
                                <when test="$code">
 
479
                                        <variable name="style-right">
 
480
                                                <call-template name="mk-style-set">
 
481
                                                        <with-param name="node" select="$paragraph-right"/>
 
482
                                                </call-template>
 
483
                                        </variable>
 
484
                        
 
485
                                        <variable name="code-right" 
 
486
                                                select="($style-right mod (2 * $CODE_BIT)) - ($style-right mod ($CODE_BIT)) != 0"/>
 
487
                                
 
488
                                        <choose>
 
489
                                                <when test="$code-right">
 
490
                                                        <choose>
 
491
                                                                <when test="$CODE_JOIN_PARAGRAPHS">
 
492
                                                                        <value-of select="$NL"/>
 
493
                                                                </when>
 
494
                                                                
 
495
                                                                <otherwise>
 
496
                                                                        <value-of select="$NL"/>
 
497
                                                                        <value-of select="' '"/>
 
498
                                                                        <value-of select="$NL"/>
 
499
                                                                </otherwise>
 
500
                                                        </choose>
 
501
                                                </when>
 
502
                                                <otherwise>
 
503
                                                        <value-of select="$NL"/>
 
504
                                                        <value-of select="$NL"/>
 
505
                                                </otherwise>
 
506
                                        </choose>
 
507
                                </when>
 
508
                                <otherwise>
 
509
                                        <value-of select="$NL"/>
 
510
                                        <value-of select="$NL"/>
 
511
                                </otherwise>
 
512
                        </choose>
 
513
                </when>
 
514
                <when test="boolean(./following-sibling::*[1]/self::text:h) or boolean(./following-sibling::*[1]/self::table:table) or boolean(./following-sibling::*[1]/self::text:bibliography)">
 
515
                        <!-- Newline before following heading or table. -->
 
516
                        <value-of select="$NL"/>
 
517
                        <value-of select="$NL"/>
 
518
                </when>
 
519
                <when test="./following-sibling::*[1]/self::text:list and not(ancestor::text:list-item)">
 
520
                        <value-of select="$NL"/>
 
521
                        <value-of select="$NL"/>
 
522
                </when>
 
523
                </choose>
 
524
        </template>
 
525
 
 
526
        <template match="text:p[string-length(.) = 0 and string-length(preceding-sibling::*[1]/self::text:p) &gt; 0]">
 
527
                <value-of select="$NL"/>
 
528
        </template>
 
529
 
 
530
 
 
531
        <!-- 
 
532
                == Preformatted text == 
 
533
        -->
 
534
        
 
535
        <template match="text:s">
 
536
                <variable name="style">
 
537
                        <call-template name="mk-style-set">
 
538
                                <with-param name="node" select="."/>
 
539
                        </call-template>
 
540
                </variable>
 
541
 
 
542
                <variable name="code" 
 
543
                        select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
 
544
                
 
545
                <if test="$code">
 
546
                        <choose>
 
547
                                <when test="@text:c">
 
548
                                        <call-template name="mk-token">
 
549
                                                <with-param name="level" select="@text:c"/>
 
550
                                                <with-param name="char" select="' '"/>
 
551
                                        </call-template>
 
552
                                </when>
 
553
                                <otherwise>
 
554
                                        <value-of select="' '"/>
 
555
                                </otherwise>
 
556
                        </choose>
 
557
                </if>
 
558
        </template>
 
559
        
 
560
        <template match="text:tab">
 
561
                <variable name="style">
 
562
                        <call-template name="mk-style-set">
 
563
                                <with-param name="node" select="."/>
 
564
                        </call-template>
 
565
                </variable>
 
566
 
 
567
                <variable name="code" 
 
568
                        select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
 
569
                
 
570
                <if test="$code">
 
571
                        <value-of select="$CODE_TAB_REPLACEMENT"/>
 
572
                </if>
 
573
        </template>
 
574
        
 
575
        <template match="text:line-break">
 
576
                <variable name="style">
 
577
                        <call-template name="mk-style-set">
 
578
                                <with-param name="node" select="."/>
 
579
                        </call-template>
 
580
                </variable>
 
581
 
 
582
                <variable name="code" 
 
583
                        select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
 
584
                
 
585
                <if test="$code">
 
586
                        <value-of select="$NL"/>
 
587
                        <value-of select="' '"/>
 
588
                </if>
 
589
        </template>
 
590
 
 
591
        <!-- 
 
592
                Footnotes
 
593
        -->
 
594
        
 
595
        <template match="text:note-body">
 
596
                <variable name="note" select="./parent::text:note"/>
 
597
                
 
598
                <if test="$note/@text:note-class = 'footnote'">
 
599
                        <text>&lt;ref name="</text>
 
600
                        <value-of select="$note/@text:id"/>
 
601
                        <text>"&gt;</text>
 
602
                        <apply-templates/>
 
603
                        <text>&lt;/ref&gt;</text>
 
604
                </if>
 
605
        </template>
 
606
        
 
607
        <template match="text:note-ref[@text:note-class='footnote']">
 
608
                <text>&lt;ref name="</text>
 
609
                <value-of select="@text:ref-name"/>
 
610
                <text>"/&gt;</text>
 
611
        </template>
 
612
        
 
613
         
 
614
        <!-- 
 
615
                == Images == 
 
616
        -->
 
617
        
 
618
        <template match="draw:text-box[boolean(.//draw:image)]">
 
619
                <variable name="image" select=".//draw:image[1]"/>
 
620
                
 
621
                <variable name="image-description">
 
622
                        <apply-templates/>
 
623
                </variable>
 
624
                
 
625
                <text>[[</text>
 
626
                <call-template name="mk-image-name">
 
627
                        <with-param name="image" select="$image"/>
 
628
                </call-template>
 
629
                <text>|thumb|</text>
 
630
                <value-of select="normalize-space($image-description)"/>
 
631
                <text>]]</text>
 
632
        </template>
 
633
        
 
634
        <template match="draw:image[not(boolean(ancestor::draw:text-box))]">
 
635
                <text>[[</text>
 
636
                <call-template name="mk-image-name">
 
637
                        <with-param name="image" select="."/>
 
638
                </call-template>
 
639
                <text>]]</text>
 
640
        </template>
 
641
 
 
642
        <template name="mk-image-name">
 
643
                <param name="image"/>
 
644
                
 
645
                <variable name="base-name">
 
646
                        <call-template name="mk-base-name">
 
647
                                <with-param name="href" select="$image/@xlink:href"/>
 
648
                        </call-template>
 
649
                </variable>
 
650
                
 
651
                <if test="not(starts-with($base-name, 'Image:'))">
 
652
                        <value-of select="'Image:'"/>
 
653
                </if>
 
654
                <value-of select="$base-name"/>
 
655
        </template>     
 
656
        
 
657
        <template name="mk-base-name">
 
658
                <param name="href"/>
 
659
                
 
660
                <variable name="result" select="substring-after($href, '/')"/>
 
661
                <choose>
 
662
                        <when test="boolean($result)">
 
663
                                <call-template name="mk-base-name">
 
664
                                        <with-param name="href" select="$result"/>
 
665
                                </call-template>
 
666
                        </when>
 
667
                        <otherwise>
 
668
                                <value-of select="$href"/>
 
669
                        </otherwise>
 
670
                </choose>
 
671
        </template>
 
672
        
 
673
        
 
674
        <!-- 
 
675
                References
 
676
         -->
 
677
         
 
678
        <!-- TODO: text:bibliography-mark -->
 
679
 
 
680
        <template match="text:reference-ref">
 
681
                <variable name="reference-mark" select="key('reference-resolution', @text:ref-name)"/>
 
682
                
 
683
                <choose>
 
684
                        <when test="boolean($reference-mark)">
 
685
                                <!-- 
 
686
                                        In wiki syntax, only a local reference to a heading can be inserted. 
 
687
                                        If the link target is a descendant of a heading element, a link can be
 
688
                                        inserted in the result. -->
 
689
                                <variable name="header-anchor" select="$reference-mark/ancestor::text:h[1]"/>
 
690
                                <if test="boolean($header-anchor)">
 
691
                                        <text>[[#</text>
 
692
                                        <value-of select="string($header-anchor)"/>
 
693
                                        <text>|</text>
 
694
                                </if>
 
695
                                
 
696
                                <variable name="reference-text" select="string(.)"/>
 
697
                                
 
698
                                <choose>
 
699
                                        <!-- Check, whether the reference text is cached in the document. -->
 
700
                                        <when test="string-length($reference-text) &gt; 0">
 
701
                                                <value-of select="$reference-text"/>
 
702
                                        </when>
 
703
                                        
 
704
                                        <otherwise>
 
705
                                                <!-- 
 
706
                                                        TODO: Evaluate the @text:reference-format attribute and 
 
707
                                                        generate the replacement text (difficult).-->
 
708
                                                <text>(REFERENCE TEXT UNAVAILABLE: "</text>
 
709
                                                <value-of select="@text:ref-name"/>
 
710
                                                <text>")</text>
 
711
                                        </otherwise>
 
712
                                </choose>
 
713
                                
 
714
                                <if test="boolean($header-anchor)">
 
715
                                        <text>]]</text>
 
716
                                </if>
 
717
                        </when>
 
718
 
 
719
                        <otherwise>
 
720
                                <text>(UNDEFINED REFERENCE: "</text>
 
721
                                <value-of select="@text:ref-name"/>
 
722
                                <text>")</text>
 
723
                        </otherwise>
 
724
                </choose>
 
725
        </template>
 
726
        
 
727
        <template match="text:reference-mark">
 
728
                <!-- TODO: Output an anchor. -->
 
729
                <apply-templates/>
 
730
        </template>
 
731
 
 
732
        <template match="text:reference-mark-start">
 
733
                <!-- TODO: Output an anchor. -->
 
734
        </template>
 
735
 
 
736
        <!-- 
 
737
                == Plain text == 
 
738
        -->
 
739
 
 
740
        <template match="text:p/text() | text:h/text() | text:span/text() | text:sequence/text() | text:sequence-ref/text() | text:a/text() | text:bookmark-ref/text() | text:reference-mark/text() | text:date/text() | text:time/text() | text:page-number/text() | text:sender-firstname/text() | text:sender-lastname/text() | text:sender-initials/text() | text:sender-title/text() | text:sender-position/text() | text:sender-email/text() | text:sender-phone-private/text() | text:sender-fax/text() | text:sender-company/text() | text:sender-phone-work/text() | text:sender-street/text() | text:sender-city/text() | text:sender-postal-code/text() | text:sender-country/text() | text:sender-state-or-province/text() | text:author-name/text() | text:author-initials/text() | text:chapter/text() | text:file-name/text() | text:template-name/text() | text:sheet-name/text() | text:variable-get/text() | text:variable-input/text() | text:user-field-get/text() | text:user-field-input/text() | text:expression/text() | text:text-input/text() | text:initial-creator/text() | text:creation-date/text() | text:creation-time/text() | text:description/text() | text:user-defined/text() | text:print-date/text() | text:printed-by/text() | text:title/text() | text:subject/text() | text:keywords/text() | text:editing-cycles/text() | text:editing-duration/text() | text:modification-date/text() | text:creator/text() | text:modification-time/text() | text:page-count/text() | text:paragraph-count/text() | text:word-count/text() | text:character-count/text() | text:table-count/text() | text:image-count/text() | text:object-count/text() | text:database-display/text() | text:database-row-number/text() | text:database-name/text() | text:page-variable-get/text() | text:placeholder/text() | text:conditional-text/text() | text:hidden-text/text() | text:execute-macro/text() | text:dde-connection/text() | text:measure/text() | text:table-formula/text()">
 
741
                <choose>
 
742
                        <when test="boolean(./ancestor::table:table-header-rows | ./ancestor::text:h)">
 
743
                                <!-- 
 
744
                                        No explicit styles within table headings or section headings, 
 
745
                                        because those styles are consistently declared by the Wiki engine. -->
 
746
                                <value-of select="."/>
 
747
                        </when>
 
748
                        
 
749
                        <when test="string-length(.) &gt; 0">
 
750
                                <variable name="style">
 
751
                                        <call-template name="mk-style-set">
 
752
                                                <with-param name="node" select="."/>
 
753
                                        </call-template>
 
754
                                </variable>
 
755
                                
 
756
                                <variable name="current-paragraph" 
 
757
                                        select="./ancestor::text:p[1]"/>
 
758
                                <variable name="paragraph-id" 
 
759
                                        select="generate-id($current-paragraph)"/>
 
760
                                <variable name="frames" 
 
761
                                        select="$current-paragraph/descendant::draw:frame"/>
 
762
                                <variable name="frame-count" 
 
763
                                        select="count($frames)"/>
 
764
                                        
 
765
                                <!-- 
 
766
                                        The current style context consists of all text nodes that are 
 
767
                                        descendants of the paragraph ancestor of this text node but not 
 
768
                                        descendants of any frame nodes that are descendants of the current 
 
769
                                        text nodes paragraph.
 
770
                                 -->
 
771
                                <variable name="context" 
 
772
                                        select="$current-paragraph//text()[not(boolean(./ancestor::draw:frame[1]) and count(./ancestor::draw:frame[1] | $frames) = $frame-count)]"/>
 
773
                                <variable name="context-size" select="count($context)"/>
 
774
 
 
775
                                <variable name="context-index">
 
776
                                        <call-template name="mk-context-index">
 
777
                                                <with-param name="current-id" select="generate-id(.)"/>
 
778
                                                <with-param name="context" select="$context"/>
 
779
                                                <with-param name="test-index" select="1"/>
 
780
                                        </call-template>
 
781
                                </variable>
 
782
 
 
783
                                <variable name="style-left">
 
784
                                        <choose>
 
785
                                                <when test="$context-index &gt; 1">
 
786
                                                        <variable name="left" select="$context[$context-index - 1]"/>
 
787
                                                        <!-- 
 
788
                                                                The preceding text node is a child of this nodes topmost 
 
789
                                                                styled ancestor. This means that the result of the 
 
790
                                                                transformation will be directly concatenated. 
 
791
                                                                -->
 
792
                                                        <call-template name="mk-style-set">
 
793
                                                                <with-param name="node" select="$left"/>
 
794
                                                        </call-template>
 
795
                                                </when>
 
796
                                                <otherwise>
 
797
                                                        <value-of select="$NO_STYLE"/>
 
798
                                                </otherwise>
 
799
                                        </choose>
 
800
                                </variable>
 
801
                                <variable name="style-right">
 
802
                                        <choose>
 
803
                                                <when test="$context-index &lt; count($context)">
 
804
                                                        <variable name="right" select="$context[$context-index + 1]"/>
 
805
                                                        <!-- 
 
806
                                                                The preceding text node is a child of this nodes topmost 
 
807
                                                                styled ancestor. This means that the result of the 
 
808
                                                                transformation will be directly concatenated. 
 
809
                                                                -->
 
810
                                                        <call-template name="mk-style-set">
 
811
                                                                <with-param name="node" select="$right"/>
 
812
                                                        </call-template>
 
813
                                                </when>
 
814
                                                <otherwise>
 
815
                                                        <value-of select="$NO_STYLE"/>
 
816
                                                </otherwise>
 
817
                                        </choose>
 
818
                                </variable>
 
819
 
 
820
                                <variable name="bold" 
 
821
                                        select="($style mod (2 * $BOLD_BIT)) != 0"/>
 
822
                                <variable name="italic" 
 
823
                                        select="($style mod (2 * $ITALIC_BIT)) - ($style mod ($ITALIC_BIT)) != 0"/>
 
824
                                <variable name="superscript" 
 
825
                                        select="($style mod (2 * $SUPERSCRIPT_BIT)) - ($style mod ($SUPERSCRIPT_BIT)) != 0"/>
 
826
                                <variable name="subscript" 
 
827
                                        select="($style mod (2 * $SUBSCRIPT_BIT)) - ($style mod ($SUBSCRIPT_BIT)) != 0"/>
 
828
                                <variable name="code" 
 
829
                                        select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
 
830
                                <variable name="typewriter" 
 
831
                                        select="($style mod (2 * $TYPEWRITER_BIT)) - ($style mod ($TYPEWRITER_BIT)) != 0"/>
 
832
 
 
833
                                <variable name="bold-left" 
 
834
                                        select="($style-left mod (2 * $BOLD_BIT)) != 0"/>
 
835
                                <variable name="italic-left" 
 
836
                                        select="($style-left mod (2 * $ITALIC_BIT)) - ($style-left mod ($ITALIC_BIT)) != 0"/>
 
837
                                <variable name="superscript-left" 
 
838
                                        select="($style-left mod (2 * $SUPERSCRIPT_BIT)) - ($style-left mod ($SUPERSCRIPT_BIT)) != 0"/>
 
839
                                <variable name="subscript-left" 
 
840
                                        select="($style-left mod (2 * $SUBSCRIPT_BIT)) - ($style-left mod ($SUBSCRIPT_BIT)) != 0"/>
 
841
                                <variable name="typewriter-left" 
 
842
                                        select="($style-left mod (2 * $TYPEWRITER_BIT)) - ($style-left mod ($TYPEWRITER_BIT)) != 0"/>
 
843
 
 
844
                                <variable name="bold-right" 
 
845
                                        select="($style-right mod (2 * $BOLD_BIT)) != 0"/>
 
846
                                <variable name="italic-right" 
 
847
                                        select="($style-right mod (2 * $ITALIC_BIT)) - ($style-right mod ($ITALIC_BIT)) != 0"/>
 
848
                                <variable name="superscript-right" 
 
849
                                        select="($style-right mod (2 * $SUPERSCRIPT_BIT)) - ($style-right mod ($SUPERSCRIPT_BIT)) != 0"/>
 
850
                                <variable name="subscript-right" 
 
851
                                        select="($style-right mod (2 * $SUBSCRIPT_BIT)) - ($style-right mod ($SUBSCRIPT_BIT)) != 0"/>
 
852
                                <variable name="typewriter-right" 
 
853
                                        select="($style-right mod (2 * $TYPEWRITER_BIT)) - ($style-right mod ($TYPEWRITER_BIT)) != 0"/>
 
854
 
 
855
                                <!-- Debugging: Add style infos to the output. -->
 
856
                                <!-- 
 
857
                                <value-of select="'{'"/>
 
858
                                <value-of select="$style-left"/>
 
859
                                <value-of select="'-'"/>
 
860
                                <value-of select="$style"/>
 
861
                                <value-of select="','"/>
 
862
                                <value-of select="$context-size"/>
 
863
                                <value-of select="'}'"/>
 
864
                                 -->
 
865
 
 
866
                                <if test="$superscript and not($superscript-left)">
 
867
                                        <text>&lt;sup&gt;</text>
 
868
                                </if>
 
869
                                <if test="$subscript and not($subscript-left)">
 
870
                                        <text>&lt;sub&gt;</text>
 
871
                                </if>
 
872
                                <if test="not($code) and $typewriter and not($typewriter-left)">
 
873
                                        <text>&lt;tt&gt;</text>
 
874
                                </if>
 
875
                                <if test="$bold and not($bold-left)">
 
876
                                        <text>'''</text>
 
877
                                </if>
 
878
                                <if test="$italic and not($italic-left)">
 
879
                                        <text>''</text>
 
880
                                </if>
 
881
 
 
882
                                <call-template name="render-quoted-text">
 
883
                                        <with-param name="text" select="."/>
 
884
                                </call-template>
 
885
 
 
886
                                <if test="$italic and not($italic-right)">
 
887
                                        <text>''</text>
 
888
                                </if>
 
889
                                <if test="$bold and not($bold-right)">
 
890
                                        <text>'''</text>
 
891
                                </if>
 
892
                                <if test="not($code) and $typewriter and not($typewriter-right)">
 
893
                                        <text>&lt;/tt&gt;</text>
 
894
                                </if>
 
895
                                <if test="$subscript and not($subscript-right)">
 
896
                                        <text>&lt;/sub&gt;</text>
 
897
                                </if>
 
898
                                <if test="$superscript and not($superscript-right)">
 
899
                                        <text>&lt;/sup&gt;</text>
 
900
                                </if>
 
901
 
 
902
                                <!-- Debugging: Add style details to the output. -->
 
903
                                <!-- 
 
904
                                <value-of select="'{'"/>
 
905
                                <value-of select="$style"/>
 
906
                                <value-of select="'-'"/>
 
907
                                <value-of select="$style-right"/>
 
908
                                <value-of select="'}'"/>
 
909
                                 -->
 
910
 
 
911
                        </when>
 
912
                </choose>
 
913
        </template>
 
914
 
 
915
        <!-- 
 
916
                Function for looking up the position of a node identified by the given 
 
917
                'current-id' within a node set 'context'. 
 
918
                
 
919
                The search starts with the the index 'test-index'. The search is recursive 
 
920
                in the 'test-index' argument. To save recursion depth, each recursive call 
 
921
                iteratively tests a fixed number of indexes (by loop unrolling).
 
922
         -->
 
923
        <template name="mk-context-index">
 
924
                <param name="current-id"/>
 
925
                <param name="context"/>
 
926
                <param name="test-index"/>
 
927
                
 
928
                <variable name="context-size" select="count($context)"/>
 
929
                
 
930
                <choose>
 
931
                        <when test="context-size &lt; $test-index">
 
932
                        </when>
 
933
                        <when test="$current-id = generate-id($context[$test-index])">
 
934
                                <value-of select="$test-index"/>
 
935
                        </when>
 
936
                        <when test="context-size &lt; ($test-index + 1)">
 
937
                        </when>
 
938
                        <when test="$current-id = generate-id($context[$test-index + 1])">
 
939
                                <value-of select="$test-index + 1"/>
 
940
                        </when>
 
941
                        <when test="context-size &lt; ($test-index + 2)">
 
942
                        </when>
 
943
                        <when test="$current-id = generate-id($context[$test-index + 2])">
 
944
                                <value-of select="$test-index + 2"/>
 
945
                        </when>
 
946
                        <when test="context-size &lt; ($test-index + 3)">
 
947
                        </when>
 
948
                        <when test="$current-id = generate-id($context[$test-index + 3])">
 
949
                                <value-of select="$test-index + 3"/>
 
950
                        </when>
 
951
                        <when test="context-size &lt; ($test-index + 4)">
 
952
                        </when>
 
953
                        <when test="$current-id = generate-id($context[$test-index + 4])">
 
954
                                <value-of select="$test-index + 4"/>
 
955
                        </when>
 
956
                        <when test="context-size &lt; ($test-index + 5)">
 
957
                        </when>
 
958
                        <when test="$current-id = generate-id($context[$test-index + 5])">
 
959
                                <value-of select="$test-index + 5"/>
 
960
                        </when>
 
961
                        <when test="context-size &lt; ($test-index + 6)">
 
962
                        </when>
 
963
                        <otherwise>
 
964
                                <call-template name="mk-context-index">
 
965
                                        <with-param name="current-id" select="$current-id"/>
 
966
                                        <with-param name="context" select="$context"/>
 
967
                                        <with-param name="test-index" select="$test-index + 6"/>
 
968
                                </call-template>
 
969
                        </otherwise>
 
970
                </choose>
 
971
        </template>
 
972
        
 
973
        <template name="render-quoted-text">
 
974
                <param name="text"/>
 
975
                
 
976
                <choose>
 
977
                        <when test="contains($text, '&lt;') or contains($text, '[') or starts-with($text, '----') or starts-with($text, '=') or starts-with($text, '*')  or starts-with($text, ';')  or starts-with($text, '#')">
 
978
                                <text>&lt;nowiki&gt;</text>
 
979
                                <choose>
 
980
                                        <when test="contains($text, '&lt;/nowiki&gt;')">
 
981
                                                <call-template name="render-escaped-text">
 
982
                                                        <with-param name="text" select="$text"/>
 
983
                                                </call-template>
 
984
                                        </when>
 
985
                                        <otherwise>
 
986
                                                <call-template name="render-encoded-text">
 
987
                                                        <with-param name="text" select="$text"/>
 
988
                                                </call-template>
 
989
                                        </otherwise>
 
990
                                </choose>
 
991
                                <text>&lt;/nowiki&gt;</text>                    
 
992
                        </when>
 
993
                        <otherwise>
 
994
                                <call-template name="render-encoded-text">
 
995
                                        <with-param name="text" select="$text"/>
 
996
                                </call-template>
 
997
                        </otherwise>
 
998
                </choose>
 
999
        </template>
 
1000
 
 
1001
        <template name="render-escaped-text">
 
1002
                <param name="text"/>
 
1003
                
 
1004
                <choose>
 
1005
                        <when test="contains($text, '&lt;')">
 
1006
                                <call-template name="render-encoded-text">
 
1007
                                        <with-param name="text" select="substring-before($text, '&lt;')"/>
 
1008
                                </call-template>
 
1009
                                <value-of select="'&amp;lt;'"/>
 
1010
                                <call-template name="render-escaped-text">
 
1011
                                        <with-param name="text" select="substring-after($text, '&lt;')"/>
 
1012
                                </call-template>
 
1013
                        </when>
 
1014
                        <otherwise>
 
1015
                                <call-template name="render-encoded-text">
 
1016
                                        <with-param name="text" select="$text"/>
 
1017
                                </call-template>
 
1018
                        </otherwise>
 
1019
                </choose>
 
1020
        </template>
 
1021
 
 
1022
        <template name="render-encoded-text">
 
1023
                <param name="text"/>
 
1024
                
 
1025
                <choose>
 
1026
                        <when test="contains($text, '&#160;')">
 
1027
                                <value-of select="substring-before($text, '&#160;')"/>
 
1028
                                <value-of select="'&amp;nbsp;'"/>
 
1029
                                <call-template name="render-encoded-text">
 
1030
                                        <with-param name="text" select="substring-after($text, '&#160;')"/>
 
1031
                                </call-template>
 
1032
                        </when>
 
1033
                        <otherwise>
 
1034
                                <value-of select="$text"/>
 
1035
                        </otherwise>
 
1036
                </choose>
 
1037
        </template>
 
1038
 
 
1039
        <!-- 
 
1040
                == Wiki styles: bold, italics, ... == 
 
1041
         -->
 
1042
 
 
1043
        <template name="mk-style-set">
 
1044
                <param name="node"/>
 
1045
                
 
1046
                <variable 
 
1047
                        name="context" 
 
1048
                        select="$node/ancestor-or-self::*[@text:style-name][1]"
 
1049
                />
 
1050
                
 
1051
                <choose>
 
1052
                        <when test="boolean($context)">
 
1053
                                <variable 
 
1054
                                        name="style" 
 
1055
                                        select="key('style-ref', $context/@text:style-name)"
 
1056
                                />
 
1057
 
 
1058
                                <!-- Debugging: Print inspected styles. -->                             
 
1059
                                <!-- 
 
1060
                                <message>
 
1061
                                        <value-of select="'=== '"/>
 
1062
                                        <value-of select="$style/@style:name"/>
 
1063
                                        <value-of select="' ==='"/>
 
1064
                                </message>
 
1065
                                 -->
 
1066
                
 
1067
                                <call-template name="mk-style-set-internal">
 
1068
                                        <with-param name="node" select="$context"/>
 
1069
                                        <with-param name="style" select="$style"/>
 
1070
                                        <with-param name="style-set" select="$NO_STYLE"/>
 
1071
                                        <with-param name="style-mask" select="$NO_STYLE"/>
 
1072
                                </call-template>
 
1073
                        </when>
 
1074
                        <otherwise>
 
1075
                                <value-of select="$NO_STYLE"/>
 
1076
                        </otherwise>
 
1077
                </choose>
 
1078
        </template>
 
1079
        
 
1080
        <!-- 
 
1081
                Compute the wiki style set that corresponds 
 
1082
                to the given office style at the given context node. 
 
1083
                
 
1084
                @param node
 
1085
                        A node in which context the style is computed. If neither the given style 
 
1086
                        nor one of its linked styles does specify a style of the given type, 
 
1087
                        ancestor nodes of the given context node are considered.
 
1088
                @param style
 
1089
                        A style:style element node. The style of the requested type is searched
 
1090
                        in the given style and its linked styles. 
 
1091
                @style-set
 
1092
                        A bit set of styles already defined by the context.
 
1093
                @style-mask
 
1094
                        A bit set of styles that must not be taken from the currently inspected 
 
1095
                        style, because those styles are already defined by the context.
 
1096
                        
 
1097
                @return A bit set composed of the wiki style constants.
 
1098
        -->
 
1099
        <template name="mk-style-set-internal">
 
1100
                <param name="node"/>
 
1101
                <param name="style"/>
 
1102
                <param name="style-set"/>
 
1103
                <param name="style-mask"/>
 
1104
                
 
1105
                <variable name="text-properties" select="$style/style:text-properties"/>
 
1106
                
 
1107
                <!-- Decompose style-mask into individual bits. -->
 
1108
                <variable name="bold-requested" 
 
1109
                        select="($style-mask mod (2 * $BOLD_BIT)) = 0"/>
 
1110
                <variable name="italic-requested" 
 
1111
                        select="($style-mask mod (2 * $ITALIC_BIT)) - ($style-mask mod ($ITALIC_BIT)) = 0"/>
 
1112
                <variable name="superscript-requested" 
 
1113
                        select="($style-mask mod (2 * $SUPERSCRIPT_BIT)) - ($style-mask mod ($SUPERSCRIPT_BIT)) = 0"/>
 
1114
                <variable name="subscript-requested" 
 
1115
                        select="($style-mask mod (2 * $SUBSCRIPT_BIT)) - ($style-mask mod ($SUBSCRIPT_BIT)) = 0"/>
 
1116
                <variable name="typewriter-requested" 
 
1117
                        select="($style-mask mod (2 * $TYPEWRITER_BIT)) - ($style-mask mod ($TYPEWRITER_BIT)) = 0"/>
 
1118
                <variable name="code-requested" 
 
1119
                        select="($style-mask mod (2 * $CODE_BIT)) - ($style-mask mod ($CODE_BIT)) = 0"/>
 
1120
                <variable name="center-requested" 
 
1121
                        select="($style-mask mod (2 * $CENTER_BIT)) - ($style-mask mod ($CENTER_BIT)) = 0"/>
 
1122
                <variable name="right-requested" 
 
1123
                        select="($style-mask mod (2 * $RIGHT_BIT)) - ($style-mask mod ($RIGHT_BIT)) = 0"/>
 
1124
                
 
1125
                <!-- Extract styles that are not already defined by the context. -->
 
1126
                <variable name="bold-style">
 
1127
                        <choose>
 
1128
                                <when test="$bold-requested and boolean($text-properties/@fo:font-weight='bold')">
 
1129
                                        <!-- Bold found in current style. -->
 
1130
                                        <value-of select="$BOLD_BIT"/>
 
1131
                                </when>
 
1132
                                <otherwise>
 
1133
                                        <value-of select="$NO_STYLE"/>
 
1134
                                </otherwise>
 
1135
                        </choose>
 
1136
                </variable>
 
1137
                <variable name="bold-mask">
 
1138
                        <choose>
 
1139
                                <when test="$bold-requested and boolean($text-properties/@fo:font-weight)">
 
1140
                                        <!-- 
 
1141
                                                Other value than "bold" means that the character style is not 
 
1142
                                                bold and no parent style must be considered.
 
1143
                                        -->
 
1144
                                        <value-of select="$BOLD_BIT"/>
 
1145
                                </when>
 
1146
                                <otherwise>
 
1147
                                        <value-of select="$NO_STYLE"/>
 
1148
                                </otherwise>
 
1149
                        </choose>
 
1150
                </variable>
 
1151
                
 
1152
                <variable name="italic-style">
 
1153
                        <choose>
 
1154
                                <when test="$italic-requested and boolean($text-properties/@fo:font-style='italic')">
 
1155
                                        <!-- Italic found in current style. -->
 
1156
                                        <value-of select="$ITALIC_BIT"/>
 
1157
                                </when>
 
1158
                                <otherwise>
 
1159
                                        <value-of select="$NO_STYLE"/>
 
1160
                                </otherwise>
 
1161
                        </choose>
 
1162
                </variable>
 
1163
                <variable name="italic-mask">
 
1164
                        <choose>
 
1165
                                <when test="$italic-requested and boolean($text-properties/@fo:font-style)">
 
1166
                                        <!-- 
 
1167
                                                Other value than "italic" means that the character style is not 
 
1168
                                                italic and no parent style must be considered.
 
1169
                                        -->
 
1170
                                        <value-of select="$ITALIC_BIT"/>
 
1171
                                </when>
 
1172
                                <otherwise>
 
1173
                                        <value-of select="$NO_STYLE"/>
 
1174
                                </otherwise>
 
1175
                        </choose>
 
1176
                </variable>
 
1177
 
 
1178
                <variable name="superscript-style">
 
1179
                        <choose>
 
1180
                                <when test="$superscript-requested and contains($text-properties/@style:text-position, 'super')">
 
1181
                                        <value-of select="$SUPERSCRIPT_BIT"/>
 
1182
                                </when>
 
1183
                                <otherwise>
 
1184
                                        <value-of select="$NO_STYLE"/>
 
1185
                                </otherwise>
 
1186
                        </choose>
 
1187
                </variable>
 
1188
                <variable name="superscript-mask">
 
1189
                        <choose>
 
1190
                                <when test="$superscript-requested and boolean($text-properties/@style:text-position)">
 
1191
                                        <value-of select="$SUPERSCRIPT_BIT"/>
 
1192
                                </when>
 
1193
                                <otherwise>
 
1194
                                        <value-of select="$NO_STYLE"/>
 
1195
                                </otherwise>
 
1196
                        </choose>
 
1197
                </variable>
 
1198
 
 
1199
                <variable name="subscript-style">
 
1200
                        <choose>
 
1201
                                <when test="$subscript-requested and contains($text-properties/@style:text-position, 'sub')">
 
1202
                                        <value-of select="$SUBSCRIPT_BIT"/>
 
1203
                                </when>
 
1204
                                <otherwise>
 
1205
                                        <value-of select="$NO_STYLE"/>
 
1206
                                </otherwise>
 
1207
                        </choose>
 
1208
                </variable>
 
1209
                <variable name="subscript-mask">
 
1210
                        <choose>
 
1211
                                <when test="$subscript-requested and boolean($text-properties/@style:text-position)">
 
1212
                                        <value-of select="$SUBSCRIPT_BIT"/>
 
1213
                                </when>
 
1214
                                <otherwise>
 
1215
                                        <value-of select="$NO_STYLE"/>
 
1216
                                </otherwise>
 
1217
                        </choose>
 
1218
                </variable>
 
1219
 
 
1220
                <variable name="typewriter-style">
 
1221
                        <choose>
 
1222
                                <when test="$typewriter-requested and ($style/@style:family='text') and boolean($text-properties/@style:font-name)">
 
1223
                                        <variable name="font-face" 
 
1224
                                                select="key('font-face-ref', $text-properties/@style:font-name)"/>
 
1225
                                        <choose>
 
1226
                                                <when test="$font-face/@style:font-pitch='fixed'">
 
1227
                                                        <value-of select="$TYPEWRITER_BIT"/>
 
1228
                                                </when>
 
1229
                                                <otherwise>
 
1230
                                                        <value-of select="$NO_STYLE"/>
 
1231
                                                </otherwise>
 
1232
                                        </choose>
 
1233
                                </when>
 
1234
                                <otherwise>
 
1235
                                        <value-of select="$NO_STYLE"/>
 
1236
                                </otherwise>
 
1237
                        </choose>
 
1238
                </variable>
 
1239
                <variable name="typewriter-mask">
 
1240
                        <choose>
 
1241
                                <!-- Note: Suppress the typewriter style on text within a code paragraph. -->
 
1242
                                <when test="$typewriter-requested and boolean($text-properties/@style:font-name)">
 
1243
                                        <value-of select="$TYPEWRITER_BIT"/>
 
1244
                                </when>
 
1245
                                <otherwise>
 
1246
                                        <value-of select="$NO_STYLE"/>
 
1247
                                </otherwise>
 
1248
                        </choose>
 
1249
                </variable>
 
1250
 
 
1251
                <variable name="code-style">
 
1252
                        <choose>
 
1253
                                <when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
 
1254
                                        <variable name="font-face" 
 
1255
                                                select="key('font-face-ref', $text-properties/@style:font-name)"/>
 
1256
                                        <choose>
 
1257
                                                <when test="$font-face/@style:font-pitch='fixed' or (boolean(@style:display-name) and contains($CODE_STYLES, $style/@style:display-name))">
 
1258
                                                        <value-of select="$CODE_BIT"/>
 
1259
                                                </when>
 
1260
                                                <otherwise>
 
1261
                                                        <value-of select="$NO_STYLE"/>
 
1262
                                                </otherwise>
 
1263
                                        </choose>
 
1264
                                </when>
 
1265
                                <otherwise>
 
1266
                                        <value-of select="$NO_STYLE"/>
 
1267
                                </otherwise>
 
1268
                        </choose>
 
1269
                </variable>
 
1270
                <variable name="code-mask">
 
1271
                        <choose>
 
1272
                                <when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
 
1273
                                        <value-of select="$CODE_BIT"/>
 
1274
                                </when>
 
1275
                                <otherwise>
 
1276
                                        <value-of select="$NO_STYLE"/>
 
1277
                                </otherwise>
 
1278
                        </choose>
 
1279
                </variable>
 
1280
                
 
1281
                <variable name="center-style">
 
1282
                        <choose>
 
1283
                                <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align='center')">
 
1284
                                        <value-of select="$CENTER_BIT"/>
 
1285
                                </when>
 
1286
                                <otherwise>
 
1287
                                        <value-of select="$NO_STYLE"/>
 
1288
                                </otherwise>
 
1289
                        </choose>
 
1290
                </variable>
 
1291
                <variable name="center-mask">
 
1292
                        <choose>
 
1293
                                <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align)">
 
1294
                                        <value-of select="$CENTER_BIT"/>
 
1295
                                </when>
 
1296
                                <otherwise>
 
1297
                                        <value-of select="$NO_STYLE"/>
 
1298
                                </otherwise>
 
1299
                        </choose>
 
1300
                </variable>
 
1301
 
 
1302
                <variable name="right-style">
 
1303
                        <choose>
 
1304
                                <when test="$right-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align='end')">
 
1305
                                        <value-of select="$RIGHT_BIT"/>
 
1306
                                </when>
 
1307
                                <otherwise>
 
1308
                                        <value-of select="$NO_STYLE"/>
 
1309
                                </otherwise>
 
1310
                        </choose>
 
1311
                </variable>
 
1312
                <variable name="right-mask">
 
1313
                        <choose>
 
1314
                                <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align)">
 
1315
                                        <value-of select="$RIGHT_BIT"/>
 
1316
                                </when>
 
1317
                                <otherwise>
 
1318
                                        <value-of select="$NO_STYLE"/>
 
1319
                                </otherwise>
 
1320
                        </choose>
 
1321
                </variable>
 
1322
                
 
1323
 
 
1324
                <!-- Compute the updated styles and mask. -->
 
1325
                <!-- 
 
1326
                        Note: The bit masks style-mask, bold-style, italic-style,... are 
 
1327
                        guaranteed to be disjoint, therefore, addition can be use instead 
 
1328
                        of bitwise or (which is missing in XPath). -->
 
1329
                <variable name="updated-style" 
 
1330
                        select="$style-set + $bold-style + $italic-style + $superscript-style + $subscript-style + $code-style + $typewriter-style + $center-style + $right-style"/>
 
1331
                <variable name="updated-mask" 
 
1332
                        select="$style-mask + $bold-mask + $italic-mask + $superscript-mask + $subscript-mask + $code-mask + $typewriter-mask + $center-mask + $right-mask"/>
 
1333
 
 
1334
                <!-- Inspect linked and nested styles. -->
 
1335
                <choose>
 
1336
                        <when test="boolean($style/@style:parent-style-name)">
 
1337
                                <!-- Look through the style, the current style is based on. -->
 
1338
                                <call-template name="mk-style-set-internal">
 
1339
                                        <with-param name="node" select="$node"/>
 
1340
                                        <with-param name="style" select="key('style-ref', $style/@style:parent-style-name)"/>
 
1341
                                        <with-param name="style-set" select="$updated-style"/>
 
1342
                                        <with-param name="style-mask" select="$updated-mask"/>
 
1343
                                </call-template>
 
1344
                        </when>
 
1345
                        <otherwise>
 
1346
                                <variable name="ancestors" select="$node/ancestor::*[@text:style-name][1]"/>
 
1347
                                
 
1348
                                <!-- Debugging: Print currently inspected style.  -->
 
1349
                                <!-- 
 
1350
                                <message>
 
1351
                                        <value-of select="'{'"/>
 
1352
                                        <value-of select="$style/@style:name"/>
 
1353
                                        <value-of select="','"/>
 
1354
                                        <value-of select="$updated-style"/>
 
1355
                                        <value-of select="','"/>
 
1356
                                        <value-of select="$updated-mask"/>
 
1357
                                        <value-of select="','"/>
 
1358
                                        <value-of select="local-name($ancestors)"/>
 
1359
                                        <value-of select="',('"/>
 
1360
                                        <value-of select="$node"/>
 
1361
                                        <value-of select="')'"/>
 
1362
                                        <value-of select="'}'"/>
 
1363
                                </message>
 
1364
                                 -->
 
1365
                                 
 
1366
                                <!-- 
 
1367
                                        If there is an ancestor that has a style, use that style, 
 
1368
                                        otherwise, a style is not found. -->
 
1369
                                <choose>
 
1370
                                        <when test="boolean($ancestors)">
 
1371
                                                <!-- Look through the style of the nearest ancestor that has a style. -->
 
1372
                                                <call-template name="mk-style-set-internal">
 
1373
                                                        <with-param name="node" select="$ancestors"/>
 
1374
                                                        <with-param name="style" select="key('style-ref', $ancestors/@text:style-name)"/>
 
1375
                                                        <with-param name="style-set" select="$updated-style"/>
 
1376
                                                        <with-param name="style-mask" select="$updated-mask"/>
 
1377
                                                </call-template>
 
1378
                                        </when>
 
1379
                                        <otherwise>
 
1380
                                                <!-- No more styles to inspect. Return the result. -->
 
1381
                                                <value-of select="$updated-style"/>
 
1382
                                        </otherwise>
 
1383
                                </choose>
 
1384
                        </otherwise>
 
1385
                </choose>
 
1386
        </template>
 
1387
 
 
1388
 
 
1389
        <!-- 
 
1390
                == Descending the tree == 
 
1391
        -->
 
1392
 
 
1393
        <template match="/">
 
1394
                <apply-templates/>
 
1395
                <value-of select="$NL"/>
 
1396
                <if test="boolean(//text:note[@text:note-class='footnote'])">
 
1397
                        <value-of select="$NL"/>
 
1398
                        <text>----</text>
 
1399
                        <value-of select="$NL"/>
 
1400
                        <text>&lt;references/&gt;</text>
 
1401
                        <value-of select="$NL"/>
 
1402
                </if>
 
1403
        </template>
 
1404
        
 
1405
        <template match="office:document-content">
 
1406
                <apply-templates/>
 
1407
        </template>
 
1408
 
 
1409
        <template match="office:body">
 
1410
                <apply-templates/>
 
1411
        </template>
 
1412
 
 
1413
        <template match="office:* | text:* | draw:frame | draw:text-box | draw:frame | draw:a">
 
1414
                <apply-templates/>
 
1415
        </template>
 
1416
 
 
1417
        <template match="node()">
 
1418
        </template>
 
1419
</stylesheet>
 
1420
 
 
1421
<!--
 
1422
  Local Variables:
 
1423
        tab-width: 4
 
1424
        sgml-indent-step: 4
 
1425
  End:
 
1426
-->