1
<?xml version="1.0" encoding="UTF-8"?>
4
odt2wiki: OpenDocument to WikiMedia transformation
5
Copyright (C) 2007 Bernhard Haumacher (haui at haumacher dot de)
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.
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.
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.
21
<stylesheet version="1.0"
22
xmlns="http://www.w3.org/1999/XSL/Transform"
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"
47
== Customization options ==
50
<!-- Constant defining the newline token. -->
51
<param name="NL" select="' '"/>
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']"/>
58
<when test="boolean($document-value)">
59
<value-of select="$document-value"/>
63
<value-of select="' '"/>
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')"/>
74
<param name="CODE_STYLES">
75
<variable name="document-value"
76
select="/office:document/office:meta/meta:user-defined[@meta:name='CODE_STYLES']"/>
78
<when test="boolean($document-value)">
79
<value-of select="$document-value"/>
83
<value-of select="''"/>
89
== Wiki style constants ==
92
<!-- Bold character style. -->
93
<variable name="BOLD_BIT" select="1"/>
95
<!-- Italic character style. -->
96
<variable name="ITALIC_BIT" select="2"/>
98
<!-- Subscript character style. -->
99
<variable name="SUBSCRIPT_BIT" select="4"/>
101
<!-- Superscript character style. -->
102
<variable name="SUPERSCRIPT_BIT" select="8"/>
104
<!-- Typewriter character style. -->
105
<variable name="TYPEWRITER_BIT" select="16"/>
107
<!-- Preformatted text paragraph style. -->
108
<variable name="CODE_BIT" select="32"/>
110
<!-- Centered paragraph style. -->
111
<variable name="CENTER_BIT" select="64"/>
113
<!-- Right aligned paragraph style. -->
114
<variable name="RIGHT_BIT" select="128"/>
116
<!-- Constant defining the empty style. -->
117
<variable name="NO_STYLE" select="0"/>
123
media-type="text/plain"
129
== Reference resolution ==
134
match="//style:style"
139
name="list-style-ref"
140
match="//text:list-style"
146
match="//style:font-face"
151
name="reference-resolution"
152
match="//text:reference-mark | //text:reference-mark-start"
158
Multiple pages (draw only)
161
<template match="draw:page">
162
<value-of select="concat(' <!-- Page ', @draw:name, '--> ')"/>
164
<value-of select="' ---- '"/>
172
<template match="text:list">
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.
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
185
<when test="boolean(./descendant::node()[not(./self::text:list) and not(./self::text:list-item) and not(./ancestor-or-self::text:h)])">
190
<apply-templates select=".//text:h"/>
195
<template match="text:list-item">
196
<if test="position() > 1 or boolean(ancestor::text:list-item)">
197
<value-of select="$NL"/>
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)"/>
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"/>
214
<template name="mk-list-token">
215
<param name="list-style"/>
216
<param name="level"/>
218
<if test="$level > 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"/>
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]"/>
228
<when test="boolean($number-style)">
230
<when test="string-length($number-style/@style:num-format) > 0">
238
<when test="boolean($bullet-style)">
249
<template match="text:h">
250
<if test="string-length(.) > 0">
251
<variable name="token">
252
<call-template name="mk-heading-prefix">
253
<with-param name="level" select="@text:outline-level"/>
256
<value-of select="$token"/>
260
<value-of select="$token"/>
261
<value-of select="$NL"/>
265
<template match="text:index-title">
269
<value-of select="$NL"/>
273
Function generating a wiki heading prefix.
276
The heading level. The value must be between 1 and 5.
278
<template name="mk-heading-prefix">
279
<param name="level"/>
281
<when test="$level > 5">
282
<call-template name="mk-heading-prefix">
283
<with-param name="level" select="5"/>
286
<when test="$level > 0">
288
<call-template name="mk-heading-prefix">
289
<with-param name="level" select="$level - 1"/>
296
Funktion generating a token consisting of the given character
297
repeated 'level' times.
300
The lengh of the result.
302
The character that should be repeated 'level' times.
304
<template name="mk-token">
305
<param name="level"/>
307
<if test="$level > 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"/>
321
<template match="table:table">
323
<text>{| class="prettytable"</text>
331
<template match="table:table-header-rows">
335
<template match="table:table-row[position() < last()] | table:table-header-rows/table:table-row">
342
<template match="table:table-row">
346
<template match="table:table-header-rows//table:table-cell">
348
<if test="@table:number-columns-spanned">
349
<text>colspan="</text>
350
<value-of select="@table:number-columns-spanned"/>
354
<value-of select="$NL"/>
357
<template match="table:table-cell">
359
<if test="@table:number-columns-spanned">
360
<text>colspan="</text>
361
<value-of select="@table:number-columns-spanned"/>
365
<value-of select="$NL"/>
373
<template match="text:span[@text:style-name='WikiMath']">
374
<value-of select="'<math>'"/>
376
<value-of select="'</math>'"/>
384
<template match="text:a">
385
<variable name="link-ref" select="@xlink:href"/>
387
<when test="string-length($link-ref) > 0">
388
<variable name="link-label" select="string(.)"/>
390
<value-of select="$link-ref"/>
392
<value-of select="$link-label"/>
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, '['), ']'))"/>
413
<when test="boolean($link-ref)">
414
<value-of select="concat($link-ref, '|', $link-label)"/>
417
<value-of select="$link-def"/>
420
<value-of select="']]'"/>
428
<template match="text:p[string-length(.) > 0]">
429
<variable name="style">
430
<call-template name="mk-style-set">
431
<with-param name="node" select="."/>
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"/>
443
<when test="$center">
444
<text><center></text>
447
<text><div align="right"></text>
450
<value-of select="' '"/>
457
<when test="$center">
458
<text></center></text>
461
<text></div></text>
465
<variable name="paragraph-right"
466
select="./following-sibling::*[1]/self::text:p"/>
469
<when test="boolean($paragraph-right)">
471
Insert end of line only if not within a list. Within wiki lists,
472
a line break leaves the current list item.
475
<when test="boolean(ancestor::text:list-item)">
476
<text><br/> </text>
479
<variable name="style-right">
480
<call-template name="mk-style-set">
481
<with-param name="node" select="$paragraph-right"/>
485
<variable name="code-right"
486
select="($style-right mod (2 * $CODE_BIT)) - ($style-right mod ($CODE_BIT)) != 0"/>
489
<when test="$code-right">
491
<when test="$CODE_JOIN_PARAGRAPHS">
492
<value-of select="$NL"/>
496
<value-of select="$NL"/>
497
<value-of select="' '"/>
498
<value-of select="$NL"/>
503
<value-of select="$NL"/>
504
<value-of select="$NL"/>
509
<value-of select="$NL"/>
510
<value-of select="$NL"/>
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"/>
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"/>
526
<template match="text:p[string-length(.) = 0 and string-length(preceding-sibling::*[1]/self::text:p) > 0]">
527
<value-of select="$NL"/>
532
== Preformatted text ==
535
<template match="text:s">
536
<variable name="style">
537
<call-template name="mk-style-set">
538
<with-param name="node" select="."/>
542
<variable name="code"
543
select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
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="' '"/>
554
<value-of select="' '"/>
560
<template match="text:tab">
561
<variable name="style">
562
<call-template name="mk-style-set">
563
<with-param name="node" select="."/>
567
<variable name="code"
568
select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
571
<value-of select="$CODE_TAB_REPLACEMENT"/>
575
<template match="text:line-break">
576
<variable name="style">
577
<call-template name="mk-style-set">
578
<with-param name="node" select="."/>
582
<variable name="code"
583
select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
586
<value-of select="$NL"/>
587
<value-of select="' '"/>
595
<template match="text:note-body">
596
<variable name="note" select="./parent::text:note"/>
598
<if test="$note/@text:note-class = 'footnote'">
599
<text><ref name="</text>
600
<value-of select="$note/@text:id"/>
603
<text></ref></text>
607
<template match="text:note-ref[@text:note-class='footnote']">
608
<text><ref name="</text>
609
<value-of select="@text:ref-name"/>
618
<template match="draw:text-box[boolean(.//draw:image)]">
619
<variable name="image" select=".//draw:image[1]"/>
621
<variable name="image-description">
626
<call-template name="mk-image-name">
627
<with-param name="image" select="$image"/>
630
<value-of select="normalize-space($image-description)"/>
634
<template match="draw:image[not(boolean(ancestor::draw:text-box))]">
636
<call-template name="mk-image-name">
637
<with-param name="image" select="."/>
642
<template name="mk-image-name">
643
<param name="image"/>
645
<variable name="base-name">
646
<call-template name="mk-base-name">
647
<with-param name="href" select="$image/@xlink:href"/>
651
<if test="not(starts-with($base-name, 'Image:'))">
652
<value-of select="'Image:'"/>
654
<value-of select="$base-name"/>
657
<template name="mk-base-name">
660
<variable name="result" select="substring-after($href, '/')"/>
662
<when test="boolean($result)">
663
<call-template name="mk-base-name">
664
<with-param name="href" select="$result"/>
668
<value-of select="$href"/>
678
<!-- TODO: text:bibliography-mark -->
680
<template match="text:reference-ref">
681
<variable name="reference-mark" select="key('reference-resolution', @text:ref-name)"/>
684
<when test="boolean($reference-mark)">
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)">
692
<value-of select="string($header-anchor)"/>
696
<variable name="reference-text" select="string(.)"/>
699
<!-- Check, whether the reference text is cached in the document. -->
700
<when test="string-length($reference-text) > 0">
701
<value-of select="$reference-text"/>
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"/>
714
<if test="boolean($header-anchor)">
720
<text>(UNDEFINED REFERENCE: "</text>
721
<value-of select="@text:ref-name"/>
727
<template match="text:reference-mark">
728
<!-- TODO: Output an anchor. -->
732
<template match="text:reference-mark-start">
733
<!-- TODO: Output an anchor. -->
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()">
742
<when test="boolean(./ancestor::table:table-header-rows | ./ancestor::text:h)">
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="."/>
749
<when test="string-length(.) > 0">
750
<variable name="style">
751
<call-template name="mk-style-set">
752
<with-param name="node" select="."/>
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)"/>
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.
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)"/>
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"/>
783
<variable name="style-left">
785
<when test="$context-index > 1">
786
<variable name="left" select="$context[$context-index - 1]"/>
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.
792
<call-template name="mk-style-set">
793
<with-param name="node" select="$left"/>
797
<value-of select="$NO_STYLE"/>
801
<variable name="style-right">
803
<when test="$context-index < count($context)">
804
<variable name="right" select="$context[$context-index + 1]"/>
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.
810
<call-template name="mk-style-set">
811
<with-param name="node" select="$right"/>
815
<value-of select="$NO_STYLE"/>
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"/>
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"/>
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"/>
855
<!-- Debugging: Add style infos to the output. -->
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="'}'"/>
866
<if test="$superscript and not($superscript-left)">
867
<text><sup></text>
869
<if test="$subscript and not($subscript-left)">
870
<text><sub></text>
872
<if test="not($code) and $typewriter and not($typewriter-left)">
873
<text><tt></text>
875
<if test="$bold and not($bold-left)">
878
<if test="$italic and not($italic-left)">
882
<call-template name="render-quoted-text">
883
<with-param name="text" select="."/>
886
<if test="$italic and not($italic-right)">
889
<if test="$bold and not($bold-right)">
892
<if test="not($code) and $typewriter and not($typewriter-right)">
893
<text></tt></text>
895
<if test="$subscript and not($subscript-right)">
896
<text></sub></text>
898
<if test="$superscript and not($superscript-right)">
899
<text></sup></text>
902
<!-- Debugging: Add style details to the output. -->
904
<value-of select="'{'"/>
905
<value-of select="$style"/>
906
<value-of select="'-'"/>
907
<value-of select="$style-right"/>
908
<value-of select="'}'"/>
916
Function for looking up the position of a node identified by the given
917
'current-id' within a node set 'context'.
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).
923
<template name="mk-context-index">
924
<param name="current-id"/>
925
<param name="context"/>
926
<param name="test-index"/>
928
<variable name="context-size" select="count($context)"/>
931
<when test="context-size < $test-index">
933
<when test="$current-id = generate-id($context[$test-index])">
934
<value-of select="$test-index"/>
936
<when test="context-size < ($test-index + 1)">
938
<when test="$current-id = generate-id($context[$test-index + 1])">
939
<value-of select="$test-index + 1"/>
941
<when test="context-size < ($test-index + 2)">
943
<when test="$current-id = generate-id($context[$test-index + 2])">
944
<value-of select="$test-index + 2"/>
946
<when test="context-size < ($test-index + 3)">
948
<when test="$current-id = generate-id($context[$test-index + 3])">
949
<value-of select="$test-index + 3"/>
951
<when test="context-size < ($test-index + 4)">
953
<when test="$current-id = generate-id($context[$test-index + 4])">
954
<value-of select="$test-index + 4"/>
956
<when test="context-size < ($test-index + 5)">
958
<when test="$current-id = generate-id($context[$test-index + 5])">
959
<value-of select="$test-index + 5"/>
961
<when test="context-size < ($test-index + 6)">
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"/>
973
<template name="render-quoted-text">
977
<when test="contains($text, '<') 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><nowiki></text>
980
<when test="contains($text, '</nowiki>')">
981
<call-template name="render-escaped-text">
982
<with-param name="text" select="$text"/>
986
<call-template name="render-encoded-text">
987
<with-param name="text" select="$text"/>
991
<text></nowiki></text>
994
<call-template name="render-encoded-text">
995
<with-param name="text" select="$text"/>
1001
<template name="render-escaped-text">
1002
<param name="text"/>
1005
<when test="contains($text, '<')">
1006
<call-template name="render-encoded-text">
1007
<with-param name="text" select="substring-before($text, '<')"/>
1009
<value-of select="'&lt;'"/>
1010
<call-template name="render-escaped-text">
1011
<with-param name="text" select="substring-after($text, '<')"/>
1015
<call-template name="render-encoded-text">
1016
<with-param name="text" select="$text"/>
1022
<template name="render-encoded-text">
1023
<param name="text"/>
1026
<when test="contains($text, ' ')">
1027
<value-of select="substring-before($text, ' ')"/>
1028
<value-of select="'&nbsp;'"/>
1029
<call-template name="render-encoded-text">
1030
<with-param name="text" select="substring-after($text, ' ')"/>
1034
<value-of select="$text"/>
1040
== Wiki styles: bold, italics, ... ==
1043
<template name="mk-style-set">
1044
<param name="node"/>
1048
select="$node/ancestor-or-self::*[@text:style-name][1]"
1052
<when test="boolean($context)">
1055
select="key('style-ref', $context/@text:style-name)"
1058
<!-- Debugging: Print inspected styles. -->
1061
<value-of select="'=== '"/>
1062
<value-of select="$style/@style:name"/>
1063
<value-of select="' ==='"/>
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"/>
1075
<value-of select="$NO_STYLE"/>
1081
Compute the wiki style set that corresponds
1082
to the given office style at the given context 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.
1089
A style:style element node. The style of the requested type is searched
1090
in the given style and its linked styles.
1092
A bit set of styles already defined by the context.
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.
1097
@return A bit set composed of the wiki style constants.
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"/>
1105
<variable name="text-properties" select="$style/style:text-properties"/>
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"/>
1125
<!-- Extract styles that are not already defined by the context. -->
1126
<variable name="bold-style">
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"/>
1133
<value-of select="$NO_STYLE"/>
1137
<variable name="bold-mask">
1139
<when test="$bold-requested and boolean($text-properties/@fo:font-weight)">
1141
Other value than "bold" means that the character style is not
1142
bold and no parent style must be considered.
1144
<value-of select="$BOLD_BIT"/>
1147
<value-of select="$NO_STYLE"/>
1152
<variable name="italic-style">
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"/>
1159
<value-of select="$NO_STYLE"/>
1163
<variable name="italic-mask">
1165
<when test="$italic-requested and boolean($text-properties/@fo:font-style)">
1167
Other value than "italic" means that the character style is not
1168
italic and no parent style must be considered.
1170
<value-of select="$ITALIC_BIT"/>
1173
<value-of select="$NO_STYLE"/>
1178
<variable name="superscript-style">
1180
<when test="$superscript-requested and contains($text-properties/@style:text-position, 'super')">
1181
<value-of select="$SUPERSCRIPT_BIT"/>
1184
<value-of select="$NO_STYLE"/>
1188
<variable name="superscript-mask">
1190
<when test="$superscript-requested and boolean($text-properties/@style:text-position)">
1191
<value-of select="$SUPERSCRIPT_BIT"/>
1194
<value-of select="$NO_STYLE"/>
1199
<variable name="subscript-style">
1201
<when test="$subscript-requested and contains($text-properties/@style:text-position, 'sub')">
1202
<value-of select="$SUBSCRIPT_BIT"/>
1205
<value-of select="$NO_STYLE"/>
1209
<variable name="subscript-mask">
1211
<when test="$subscript-requested and boolean($text-properties/@style:text-position)">
1212
<value-of select="$SUBSCRIPT_BIT"/>
1215
<value-of select="$NO_STYLE"/>
1220
<variable name="typewriter-style">
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)"/>
1226
<when test="$font-face/@style:font-pitch='fixed'">
1227
<value-of select="$TYPEWRITER_BIT"/>
1230
<value-of select="$NO_STYLE"/>
1235
<value-of select="$NO_STYLE"/>
1239
<variable name="typewriter-mask">
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"/>
1246
<value-of select="$NO_STYLE"/>
1251
<variable name="code-style">
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)"/>
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"/>
1261
<value-of select="$NO_STYLE"/>
1266
<value-of select="$NO_STYLE"/>
1270
<variable name="code-mask">
1272
<when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
1273
<value-of select="$CODE_BIT"/>
1276
<value-of select="$NO_STYLE"/>
1281
<variable name="center-style">
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"/>
1287
<value-of select="$NO_STYLE"/>
1291
<variable name="center-mask">
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"/>
1297
<value-of select="$NO_STYLE"/>
1302
<variable name="right-style">
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"/>
1308
<value-of select="$NO_STYLE"/>
1312
<variable name="right-mask">
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"/>
1318
<value-of select="$NO_STYLE"/>
1324
<!-- Compute the updated styles and mask. -->
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"/>
1334
<!-- Inspect linked and nested styles. -->
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"/>
1346
<variable name="ancestors" select="$node/ancestor::*[@text:style-name][1]"/>
1348
<!-- Debugging: Print currently inspected style. -->
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="'}'"/>
1367
If there is an ancestor that has a style, use that style,
1368
otherwise, a style is not found. -->
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"/>
1380
<!-- No more styles to inspect. Return the result. -->
1381
<value-of select="$updated-style"/>
1390
== Descending the tree ==
1393
<template match="/">
1395
<value-of select="$NL"/>
1396
<if test="boolean(//text:note[@text:note-class='footnote'])">
1397
<value-of select="$NL"/>
1399
<value-of select="$NL"/>
1400
<text><references/></text>
1401
<value-of select="$NL"/>
1405
<template match="office:document-content">
1409
<template match="office:body">
1413
<template match="office:* | text:* | draw:frame | draw:text-box | draw:frame | draw:a">
1417
<template match="node()">