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