1 <?xml version="1.0" encoding="UTF-8"?>
4 odt2phpwiki: OpenDocument to Phpwiki transformation
6 Copyright (C) 2007 Bernhard Haumacher (haui at haumacher dot de)
7 Copyright (C) 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 This program is based on the OpenDocument to Mediawiki converter by
26 Modifications to convert to Phpwiki were made by Marc-Etienne Vargenau
27 and are Copyright (C) 2008-2009 Alcatel-Lucent
29 Standard Alcatel-Lucent disclaimer for contributing to open source
31 "The OpenDocument to Phpwiki converter ("Contribution") has not been tested and/or
32 validated for release as or in products, combinations with products or
33 other commercial use. Any use of the Contribution is entirely made at
34 the user's own responsibility and the user can not rely on any features,
35 functionalities or performances Alcatel-Lucent has attributed to the
38 THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
39 OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
40 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
41 NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
42 CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
43 ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
44 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45 CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
46 TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
50 <stylesheet version="1.0"
51 xmlns="http://www.w3.org/1999/XSL/Transform"
53 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
54 xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
55 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
56 xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
57 xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
58 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
59 xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
60 xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
61 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
62 xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
63 xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
64 xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
65 xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
66 xmlns:xlink="http://www.w3.org/1999/xlink"
67 xmlns:dc="http://purl.org/dc/elements/1.1/"
68 xmlns:math="http://www.w3.org/1998/Math/MathML"
69 xmlns:dom="http://www.w3.org/2001/xml-events"
70 xmlns:xforms="http://www.w3.org/2002/xforms"
71 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
72 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
76 media-type="text/plain"
81 == Reference resolution ==
92 match="//text:list-style"
98 match="//style:font-face"
103 name="reference-resolution"
104 match="//text:reference-mark | //text:reference-mark-start"
109 <!-- Wiki style constants. -->
111 <!-- Bold character style. -->
112 <variable name="BOLD_BIT" select="1"/>
114 <!-- Italic character style. -->
115 <variable name="ITALIC_BIT" select="2"/>
117 <!-- Subscript character style. -->
118 <variable name="SUBSCRIPT_BIT" select="4"/>
120 <!-- Superscript character style. -->
121 <variable name="SUPERSCRIPT_BIT" select="8"/>
123 <!-- Typewriter character style. -->
124 <variable name="TYPEWRITER_BIT" select="16"/>
126 <!-- Preformatted text paragraph style. -->
127 <variable name="CODE_BIT" select="32"/>
129 <!-- Centered paragraph style. -->
130 <variable name="CENTER_BIT" select="64"/>
132 <!-- Right aligned paragraph style. -->
133 <variable name="RIGHT_BIT" select="128"/>
135 <!-- Constant defining the empty style. -->
136 <variable name="NO_STYLE" select="0"/>
138 <!-- Constant defining the newline token. -->
139 <variable name="NL" select="' '"/>
142 Multiple pages (draw only)
145 <template match="draw:page">
146 <value-of select="concat(' <!-- Page ', @draw:name, '--> ')"/>
148 <value-of select="' ---- '"/>
156 <template match="text:list-item">
157 <if test="position() > 1 or boolean(ancestor::text:list-item)">
158 <value-of select="$NL"/>
160 <variable name="list-style"
161 select="key('list-style-ref',ancestor::text:list[boolean(@text:style-name)][1]/@text:style-name)"/>
162 <call-template name="mk-list-token">
163 <with-param name="list-style" select="$list-style"/>
164 <with-param name="level" select="count(ancestor::text:list)"/>
168 <if test="position() = last() and not(boolean(ancestor::text:list-item))">
169 <value-of select="$NL"/>
170 <value-of select="$NL"/>
174 <template name="mk-list-token">
175 <param name="list-style"/>
176 <param name="level"/>
178 <if test="$level > 1">
179 <call-template name="mk-list-token">
180 <with-param name="list-style" select="$list-style"/>
181 <with-param name="level" select="$level - 1"/>
185 <variable name="number-style" select="$list-style/text:list-level-style-number[@text:level=$level]"/>
186 <variable name="bullet-style" select="$list-style/text:list-level-style-bullet[@text:level=$level]"/>
188 <when test="boolean($number-style)">
190 <when test="string-length($number-style/@style:num-format) > 0">
198 <when test="boolean($bullet-style)">
209 <template match="text:h">
210 <if test="string-length(.) > 0">
211 <variable name="token">
212 <call-template name="mk-heading-prefix">
213 <with-param name="level" select="1 + @text:outline-level"/>
216 <value-of select="$token"/>
220 <value-of select="$token"/>
226 Function generating a wiki heading prefix.
229 The heading level. The value must be between 1 and 5.
231 <template name="mk-heading-prefix">
232 <param name="level"/>
234 <when test="$level > 6">
235 <call-template name="mk-heading-prefix">
236 <with-param name="level" select="6"/>
239 <when test="$level > 0">
241 <call-template name="mk-heading-prefix">
242 <with-param name="level" select="$level - 1"/>
249 Function generating a token consisting of the given character
250 repeated 'level' times.
253 The lengh of the result.
255 The character that should be repeated 'level' times.
257 <template name="mk-token">
258 <param name="level"/>
260 <if test="$level > 0">
261 <value-of select="$char"/>
262 <call-template name="mk-token">
263 <with-param name="level" select="$level - 1"/>
264 <with-param name="char" select="$char"/>
274 <template match="table:table">
276 <text>{| class="bordered"</text>
286 <template match="table:table-header-rows">
290 <template match="table:table-row[position() < last()] | table:table-header-rows/table:table-row">
297 <template match="table:table-row">
301 <template match="table:table-header-rows//table:table-cell">
303 <if test="@table:number-columns-spanned">
304 <text>colspan="</text>
305 <value-of select="@table:number-columns-spanned"/>
309 <value-of select="$NL"/>
312 <template match="table:table-cell">
314 <if test="@table:number-columns-spanned">
315 <text>colspan="</text>
316 <value-of select="@table:number-columns-spanned"/>
320 <value-of select="$NL"/>
328 <template match="text:span[@text:style-name='WikiMath']">
329 <value-of select="'<math>'"/>
331 <value-of select="'</math>'"/>
339 <template match="text:a">
340 <variable name="link-ref" select="@xlink:href"/>
342 <when test="string-length($link-ref) > 0">
343 <variable name="link-label" select="string(.)"/>
345 <value-of select="$link-ref"/>
347 <value-of select="$link-label"/>
362 <template match="text:span[@text:style-name='WikiLink']">
363 <value-of select="'[['"/>
364 <variable name="link-def" select="string(.)"/>
365 <variable name="link-label" select="normalize-space(substring-before($link-def, '['))"/>
366 <variable name="link-ref" select="normalize-space(substring-before(substring-after($link-def, '['), ']'))"/>
368 <when test="boolean($link-ref)">
369 <value-of select="concat($link-ref, '|', $link-label)"/>
372 <value-of select="$link-def"/>
375 <value-of select="']]'"/>
383 <template match="text:p[string-length(.) > 0]">
384 <variable name="style">
385 <call-template name="mk-style-set">
386 <with-param name="node" select="."/>
390 <variable name="code"
391 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
392 <variable name="center"
393 select="($style mod (2 * $CENTER_BIT)) - ($style mod ($CENTER_BIT)) != 0"/>
394 <variable name="right"
395 select="($style mod (2 * $RIGHT_BIT)) - ($style mod ($RIGHT_BIT)) != 0"/>
398 <when test="$center">
399 <text><div align="center"></text>
402 <text><div align="right"></text>
405 <value-of select="' '"/>
412 <when test="$center">
413 <text></div></text>
416 <text></div></text>
420 <variable name="paragraph-right"
421 select="./following-sibling::text:p[1]"/>
423 <if test="boolean($paragraph-right)">
425 Insert end of line only if not within a list. Within wiki lists,
426 a line break leaves the current list item.
429 <when test="boolean(ancestor::text:list-item)">
433 <variable name="style-right">
434 <call-template name="mk-style-set">
435 <with-param name="node" select="$paragraph-right"/>
439 <variable name="code-right"
440 select="($style-right mod (2 * $CODE_BIT)) - ($style-right mod ($CODE_BIT)) != 0"/>
442 <value-of select="$NL"/>
443 <if test="$code-right">
444 <value-of select="' '"/>
446 <value-of select="$NL"/>
449 <value-of select="$NL"/>
450 <value-of select="$NL"/>
456 <template match="text:p[string-length(.) = 0 and string-length(preceding-sibling::text:p[1]) > 0]">
457 <value-of select="$NL"/>
462 == Preformatted text ==
465 <template match="text:s">
466 <variable name="style">
467 <call-template name="mk-style-set">
468 <with-param name="node" select="."/>
472 <variable name="code"
473 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
477 <when test="@text:c">
478 <call-template name="mk-token">
479 <with-param name="level" select="@text:c"/>
480 <with-param name="char" select="' '"/>
484 <value-of select="' '"/>
490 <template match="text:line-break">
491 <variable name="style">
492 <call-template name="mk-style-set">
493 <with-param name="node" select="."/>
497 <variable name="code"
498 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
501 <value-of select="$NL"/>
502 <value-of select="' '"/>
510 <template match="text:note-body">
511 <variable name="note" select="./parent::text:note"/>
513 <if test="$note/@text:note-class = 'footnote'">
514 <text><ref name="</text>
515 <value-of select="$note/@text:id"/>
518 <text></ref></text>
522 <template match="text:note-ref[@text:note-class='footnote']">
523 <text><ref name="</text>
524 <value-of select="@text:ref-name"/>
533 <template match="draw:text-box[boolean(.//draw:image)]">
534 <variable name="image" select=".//draw:image[1]"/>
536 <variable name="image-description">
541 <call-template name="mk-image-name">
542 <with-param name="image" select="$image"/>
545 <value-of select="normalize-space($image-description)"/>
549 <template match="draw:image[not(boolean(ancestor::draw:text-box))]">
551 <call-template name="mk-image-name">
552 <with-param name="image" select="."/>
557 <template name="mk-image-name">
558 <param name="image"/>
560 <variable name="base-name">
561 <call-template name="mk-base-name">
562 <with-param name="href" select="$image/@xlink:href"/>
566 <if test="not(starts-with($base-name, 'Image:'))">
567 <value-of select="'Image:'"/>
569 <value-of select="$base-name"/>
572 <template name="mk-base-name">
575 <variable name="result" select="substring-after($href, '/')"/>
577 <when test="boolean($result)">
578 <call-template name="mk-base-name">
579 <with-param name="href" select="$result"/>
583 <value-of select="$href"/>
593 <!-- TODO: text:bibliography-mark -->
595 <template match="text:reference-ref">
596 <variable name="reference-mark" select="key('reference-resolution', @text:ref-name)"/>
599 <when test="boolean($reference-mark)">
601 In wiki syntax, only a local reference to a heading can be inserted.
602 If the link target is a descendant of a heading element, a link can be
603 inserted in the result. -->
604 <variable name="header-anchor" select="$reference-mark/ancestor::text:h[1]"/>
605 <if test="boolean($header-anchor)">
607 <value-of select="string($header-anchor)"/>
611 <variable name="reference-text" select="string(.)"/>
614 <!-- Check, whether the reference text is cached in the document. -->
615 <when test="string-length($reference-text) > 0">
616 <value-of select="$reference-text"/>
621 TODO: Evaluate the @text:reference-format attribute and
622 generate the replacement text (difficult).-->
623 <text>(REFERENCE TEXT UNAVAILABLE: "</text>
624 <value-of select="@text:ref-name"/>
629 <if test="boolean($header-anchor)">
635 <text>(UNDEFINED REFERENCE: "</text>
636 <value-of select="@text:ref-name"/>
642 <template match="text:reference-mark">
643 <!-- TODO: Output an anchor. -->
647 <template match="text:reference-mark-start">
648 <!-- TODO: Output an anchor. -->
655 <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()">
657 <when test="boolean(./ancestor::table:table-header-rows | ./ancestor::text:h)">
659 No explicit styles within table headings or section headings,
660 because those styles are consistently declared by the Wiki engine. -->
661 <value-of select="."/>
664 <when test="string-length(.) > 0">
665 <variable name="style">
666 <call-template name="mk-style-set">
667 <with-param name="node" select="."/>
671 <variable name="current-paragraph"
672 select="./ancestor::text:p[1]"/>
673 <variable name="paragraph-id"
674 select="generate-id($current-paragraph)"/>
675 <variable name="frames"
676 select="$current-paragraph/descendant::draw:frame"/>
677 <variable name="frame-count"
678 select="count($frames)"/>
681 The current style context consists of all text nodes that are
682 descendants of the paragraph ancestor of this text node but not
683 descendants of any frame nodes that are descendants of the current
684 text nodes paragraph.
686 <variable name="context"
687 select="$current-paragraph//text()[not(boolean(./ancestor::draw:frame[1]) and count(./ancestor::draw:frame[1] | $frames) = $frame-count)]"/>
688 <variable name="context-size" select="count($context)"/>
690 <variable name="context-index">
691 <call-template name="mk-context-index">
692 <with-param name="current-id" select="generate-id(.)"/>
693 <with-param name="context" select="$context"/>
694 <with-param name="test-index" select="1"/>
698 <variable name="style-left">
700 <when test="$context-index > 1">
701 <variable name="left" select="$context[$context-index - 1]"/>
703 The preceding text node is a child of this nodes topmost
704 styled ancestor. This means that the result of the
705 transformation will be directly concatenated.
707 <call-template name="mk-style-set">
708 <with-param name="node" select="$left"/>
712 <value-of select="$NO_STYLE"/>
716 <variable name="style-right">
718 <when test="$context-index < count($context)">
719 <variable name="right" select="$context[$context-index + 1]"/>
721 The preceding text node is a child of this nodes topmost
722 styled ancestor. This means that the result of the
723 transformation will be directly concatenated.
725 <call-template name="mk-style-set">
726 <with-param name="node" select="$right"/>
730 <value-of select="$NO_STYLE"/>
735 <variable name="bold"
736 select="($style mod (2 * $BOLD_BIT)) != 0"/>
737 <variable name="italic"
738 select="($style mod (2 * $ITALIC_BIT)) - ($style mod ($ITALIC_BIT)) != 0"/>
739 <variable name="superscript"
740 select="($style mod (2 * $SUPERSCRIPT_BIT)) - ($style mod ($SUPERSCRIPT_BIT)) != 0"/>
741 <variable name="subscript"
742 select="($style mod (2 * $SUBSCRIPT_BIT)) - ($style mod ($SUBSCRIPT_BIT)) != 0"/>
743 <variable name="code"
744 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
745 <variable name="typewriter"
746 select="($style mod (2 * $TYPEWRITER_BIT)) - ($style mod ($TYPEWRITER_BIT)) != 0"/>
748 <variable name="bold-left"
749 select="($style-left mod (2 * $BOLD_BIT)) != 0"/>
750 <variable name="italic-left"
751 select="($style-left mod (2 * $ITALIC_BIT)) - ($style-left mod ($ITALIC_BIT)) != 0"/>
752 <variable name="superscript-left"
753 select="($style-left mod (2 * $SUPERSCRIPT_BIT)) - ($style-left mod ($SUPERSCRIPT_BIT)) != 0"/>
754 <variable name="subscript-left"
755 select="($style-left mod (2 * $SUBSCRIPT_BIT)) - ($style-left mod ($SUBSCRIPT_BIT)) != 0"/>
756 <variable name="typewriter-left"
757 select="($style-left mod (2 * $TYPEWRITER_BIT)) - ($style-left mod ($TYPEWRITER_BIT)) != 0"/>
759 <variable name="bold-right"
760 select="($style-right mod (2 * $BOLD_BIT)) != 0"/>
761 <variable name="italic-right"
762 select="($style-right mod (2 * $ITALIC_BIT)) - ($style-right mod ($ITALIC_BIT)) != 0"/>
763 <variable name="superscript-right"
764 select="($style-right mod (2 * $SUPERSCRIPT_BIT)) - ($style-right mod ($SUPERSCRIPT_BIT)) != 0"/>
765 <variable name="subscript-right"
766 select="($style-right mod (2 * $SUBSCRIPT_BIT)) - ($style-right mod ($SUBSCRIPT_BIT)) != 0"/>
767 <variable name="typewriter-right"
768 select="($style-right mod (2 * $TYPEWRITER_BIT)) - ($style-right mod ($TYPEWRITER_BIT)) != 0"/>
770 <!-- Debugging: Add style infos to the output. -->
772 <value-of select="'{'"/>
773 <value-of select="$style-left"/>
774 <value-of select="'-'"/>
775 <value-of select="$style"/>
776 <value-of select="','"/>
777 <value-of select="$context-size"/>
778 <value-of select="'}'"/>
781 <if test="$superscript and not($superscript-left)">
784 <if test="$subscript and not($subscript-left)">
787 <if test="not($code) and $typewriter and not($typewriter-left)">
790 <if test="$bold and not($bold-left)">
793 <if test="$italic and not($italic-left)">
797 <call-template name="render-quoted-text">
798 <with-param name="text" select="."/>
801 <if test="$italic and not($italic-right)">
804 <if test="$bold and not($bold-right)">
807 <if test="not($code) and $typewriter and not($typewriter-right)">
810 <if test="$subscript and not($subscript-right)">
813 <if test="$superscript and not($superscript-right)">
817 <!-- Debugging: Add style details to the output. -->
819 <value-of select="'{'"/>
820 <value-of select="$style"/>
821 <value-of select="'-'"/>
822 <value-of select="$style-right"/>
823 <value-of select="'}'"/>
831 Function for looking up the position of a node identified by the given
832 'current-id' within a node set 'context'.
834 The search starts with the the index 'test-index'. The search is recursive
835 in the 'test-index' argument. To save recursion depth, each recursive call
836 iteratively tests a fixed number of indexes (by loop unrolling).
838 <template name="mk-context-index">
839 <param name="current-id"/>
840 <param name="context"/>
841 <param name="test-index"/>
843 <variable name="context-size" select="count($context)"/>
846 <when test="context-size < $test-index">
848 <when test="$current-id = generate-id($context[$test-index])">
849 <value-of select="$test-index"/>
851 <when test="context-size < ($test-index + 1)">
853 <when test="$current-id = generate-id($context[$test-index + 1])">
854 <value-of select="$test-index + 1"/>
856 <when test="context-size < ($test-index + 2)">
858 <when test="$current-id = generate-id($context[$test-index + 2])">
859 <value-of select="$test-index + 2"/>
861 <when test="context-size < ($test-index + 3)">
863 <when test="$current-id = generate-id($context[$test-index + 3])">
864 <value-of select="$test-index + 3"/>
866 <when test="context-size < ($test-index + 4)">
868 <when test="$current-id = generate-id($context[$test-index + 4])">
869 <value-of select="$test-index + 4"/>
871 <when test="context-size < ($test-index + 5)">
873 <when test="$current-id = generate-id($context[$test-index + 5])">
874 <value-of select="$test-index + 5"/>
876 <when test="context-size < ($test-index + 6)">
879 <call-template name="mk-context-index">
880 <with-param name="current-id" select="$current-id"/>
881 <with-param name="context" select="$context"/>
882 <with-param name="test-index" select="$test-index + 6"/>
888 <template name="render-quoted-text">
892 <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, '#')">
893 <text><nowiki></text>
895 <when test="contains($text, '</nowiki>')">
896 <call-template name="render-escaped-text">
897 <with-param name="text" select="$text"/>
901 <value-of select="$text"/>
904 <text></nowiki></text>
907 <value-of select="$text"/>
912 <template name="render-escaped-text">
916 <when test="contains($text, '<')">
917 <value-of select="substring-before($text, '<')"/>
918 <value-of select="'&'"/>
919 <value-of select="'lt;'"/>
920 <value-of select="substring-after($text, '<')"/>
923 <value-of select="$text"/>
929 == Wiki styles: bold, italics, ... ==
932 <template name="mk-style-set">
937 select="$node/ancestor-or-self::*[@text:style-name][1]"
941 <when test="boolean($context)">
944 select="key('style-ref', $context/@text:style-name)"
947 <!-- Debugging: Print inspected styles. -->
950 <value-of select="'=== '"/>
951 <value-of select="$style/@style:name"/>
952 <value-of select="' ==='"/>
956 <call-template name="mk-style-set-internal">
957 <with-param name="node" select="$context"/>
958 <with-param name="style" select="$style"/>
959 <with-param name="style-set" select="$NO_STYLE"/>
960 <with-param name="style-mask" select="$NO_STYLE"/>
964 <value-of select="$NO_STYLE"/>
970 Compute the wiki style set that corresponds
971 to the given office style at the given context node.
974 A node in which context the style is computed. If neither the given style
975 nor one of its linked styles does specify a style of the given type,
976 ancestor nodes of the given context node are considered.
978 A style:style element node. The style of the requested type is searched
979 in the given style and its linked styles.
981 A bit set of styles already defined by the context.
983 A bit set of styles that must not be taken from the currently inspected
984 style, because those styles are already defined by the context.
986 @return A bit set composed of the wiki style constants.
988 <template name="mk-style-set-internal">
990 <param name="style"/>
991 <param name="style-set"/>
992 <param name="style-mask"/>
994 <variable name="text-properties" select="$style/style:text-properties"/>
996 <!-- Decompose style-mask into individual bits. -->
997 <variable name="bold-requested"
998 select="($style-mask mod (2 * $BOLD_BIT)) = 0"/>
999 <variable name="italic-requested"
1000 select="($style-mask mod (2 * $ITALIC_BIT)) - ($style-mask mod ($ITALIC_BIT)) = 0"/>
1001 <variable name="superscript-requested"
1002 select="($style-mask mod (2 * $SUPERSCRIPT_BIT)) - ($style-mask mod ($SUPERSCRIPT_BIT)) = 0"/>
1003 <variable name="subscript-requested"
1004 select="($style-mask mod (2 * $SUBSCRIPT_BIT)) - ($style-mask mod ($SUBSCRIPT_BIT)) = 0"/>
1005 <variable name="typewriter-requested"
1006 select="($style-mask mod (2 * $TYPEWRITER_BIT)) - ($style-mask mod ($TYPEWRITER_BIT)) = 0"/>
1007 <variable name="code-requested"
1008 select="($style-mask mod (2 * $CODE_BIT)) - ($style-mask mod ($CODE_BIT)) = 0"/>
1009 <variable name="center-requested"
1010 select="($style-mask mod (2 * $CENTER_BIT)) - ($style-mask mod ($CENTER_BIT)) = 0"/>
1011 <variable name="right-requested"
1012 select="($style-mask mod (2 * $RIGHT_BIT)) - ($style-mask mod ($RIGHT_BIT)) = 0"/>
1014 <!-- Extract styles that are not already defined by the context. -->
1015 <variable name="bold-style">
1017 <when test="$bold-requested and boolean($text-properties/@fo:font-weight='bold')">
1018 <!-- Bold found in current style. -->
1019 <value-of select="$BOLD_BIT"/>
1022 <value-of select="$NO_STYLE"/>
1026 <variable name="bold-mask">
1028 <when test="$bold-requested and boolean($text-properties/@fo:font-weight)">
1030 Other value than "bold" means that the character style is not
1031 bold and no parent style must be considered.
1033 <value-of select="$BOLD_BIT"/>
1036 <value-of select="$NO_STYLE"/>
1041 <variable name="italic-style">
1043 <when test="$italic-requested and boolean($text-properties/@fo:font-style='italic')">
1044 <!-- Italic found in current style. -->
1045 <value-of select="$ITALIC_BIT"/>
1048 <value-of select="$NO_STYLE"/>
1052 <variable name="italic-mask">
1054 <when test="$italic-requested and boolean($text-properties/@fo:font-style)">
1056 Other value than "italic" means that the character style is not
1057 italic and no parent style must be considered.
1059 <value-of select="$ITALIC_BIT"/>
1062 <value-of select="$NO_STYLE"/>
1067 <variable name="superscript-style">
1069 <when test="$superscript-requested and contains($text-properties/@style:text-position, 'super')">
1070 <value-of select="$SUPERSCRIPT_BIT"/>
1073 <value-of select="$NO_STYLE"/>
1077 <variable name="superscript-mask">
1079 <when test="$superscript-requested and boolean($text-properties/@style:text-position)">
1080 <value-of select="$SUPERSCRIPT_BIT"/>
1083 <value-of select="$NO_STYLE"/>
1088 <variable name="subscript-style">
1090 <when test="$subscript-requested and contains($text-properties/@style:text-position, 'sub')">
1091 <value-of select="$SUBSCRIPT_BIT"/>
1094 <value-of select="$NO_STYLE"/>
1098 <variable name="subscript-mask">
1100 <when test="$subscript-requested and boolean($text-properties/@style:text-position)">
1101 <value-of select="$SUBSCRIPT_BIT"/>
1104 <value-of select="$NO_STYLE"/>
1109 <variable name="typewriter-style">
1111 <when test="$typewriter-requested and ($style/@style:family='text') and boolean($text-properties/@style:font-name)">
1112 <variable name="font-face"
1113 select="key('font-face-ref', $text-properties/@style:font-name)"/>
1115 <when test="$font-face/@style:font-pitch='fixed'">
1116 <value-of select="$TYPEWRITER_BIT"/>
1119 <value-of select="$NO_STYLE"/>
1124 <value-of select="$NO_STYLE"/>
1128 <variable name="typewriter-mask">
1130 <!-- Note: Suppress the typewriter style on text within a code paragraph. -->
1131 <when test="$typewriter-requested and boolean($text-properties/@style:font-name)">
1132 <value-of select="$TYPEWRITER_BIT"/>
1135 <value-of select="$NO_STYLE"/>
1140 <variable name="code-style">
1142 <when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
1143 <variable name="font-face"
1144 select="key('font-face-ref', $text-properties/@style:font-name)"/>
1146 <when test="$font-face/@style:font-pitch='fixed'">
1147 <value-of select="$CODE_BIT"/>
1150 <value-of select="$NO_STYLE"/>
1155 <value-of select="$NO_STYLE"/>
1159 <variable name="code-mask">
1161 <when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
1162 <value-of select="$CODE_BIT"/>
1165 <value-of select="$NO_STYLE"/>
1170 <variable name="center-style">
1172 <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align='center')">
1173 <value-of select="$CENTER_BIT"/>
1176 <value-of select="$NO_STYLE"/>
1180 <variable name="center-mask">
1182 <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align)">
1183 <value-of select="$CENTER_BIT"/>
1186 <value-of select="$NO_STYLE"/>
1191 <variable name="right-style">
1193 <when test="$right-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align='end')">
1194 <value-of select="$RIGHT_BIT"/>
1197 <value-of select="$NO_STYLE"/>
1201 <variable name="right-mask">
1203 <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align)">
1204 <value-of select="$RIGHT_BIT"/>
1207 <value-of select="$NO_STYLE"/>
1213 <!-- Compute the updated styles and mask. -->
1215 Note: The bit masks style-mask, bold-style, italic-style,... are
1216 guaranteed to be disjoint, therefore, addition can be use instead
1217 of bitwise or (which is missing in XPath). -->
1218 <variable name="updated-style"
1219 select="$style-set + $bold-style + $italic-style + $superscript-style + $subscript-style + $code-style + $typewriter-style + $center-style + $right-style"/>
1220 <variable name="updated-mask"
1221 select="$style-mask + $bold-mask + $italic-mask + $superscript-mask + $subscript-mask + $code-mask + $typewriter-mask + $center-mask + $right-mask"/>
1223 <!-- Inspect linked and nested styles. -->
1225 <when test="boolean($style/@style:parent-style-name)">
1226 <!-- Look through the style, the current style is based on. -->
1227 <call-template name="mk-style-set-internal">
1228 <with-param name="node" select="$node"/>
1229 <with-param name="style" select="key('style-ref', $style/@style:parent-style-name)"/>
1230 <with-param name="style-set" select="$updated-style"/>
1231 <with-param name="style-mask" select="$updated-mask"/>
1235 <variable name="ancestors" select="$node/ancestor::*[@text:style-name][1]"/>
1237 <!-- Debugging: Print currently inspected style. -->
1240 <value-of select="'{'"/>
1241 <value-of select="$style/@style:name"/>
1242 <value-of select="','"/>
1243 <value-of select="$updated-style"/>
1244 <value-of select="','"/>
1245 <value-of select="$updated-mask"/>
1246 <value-of select="','"/>
1247 <value-of select="local-name($ancestors)"/>
1248 <value-of select="',('"/>
1249 <value-of select="$node"/>
1250 <value-of select="')'"/>
1251 <value-of select="'}'"/>
1256 If there is an ancestor that has a style, use that style,
1257 otherwise, a style is not found. -->
1259 <when test="boolean($ancestors)">
1260 <!-- Look through the style of the nearest ancestor that has a style. -->
1261 <call-template name="mk-style-set-internal">
1262 <with-param name="node" select="$ancestors"/>
1263 <with-param name="style" select="key('style-ref', $ancestors/@text:style-name)"/>
1264 <with-param name="style-set" select="$updated-style"/>
1265 <with-param name="style-mask" select="$updated-mask"/>
1269 <!-- No more styles to inspect. Return the result. -->
1270 <value-of select="$updated-style"/>
1279 == Descending the tree ==
1282 <template match="/">
1284 <value-of select="$NL"/>
1285 <if test="boolean(//text:note[@text:note-class='footnote'])">
1286 <value-of select="$NL"/>
1288 <value-of select="$NL"/>
1289 <text><references/></text>
1290 <value-of select="$NL"/>
1294 <template match="office:document-content">
1298 <template match="office:body">
1302 <template match="office:* | text:* | draw:frame | draw:text-box | draw:frame | draw:a">
1306 <template match="node()">