tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / swext / mediawiki / src / filter / odt2mediawiki.xsl
blob435f0f498cacb04d64e7435854744278c16ee111
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)
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
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"
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"
45 <!--
46 == Customization options ==
47 -->
49 <!-- Constant defining the newline token. -->
50 <param name="NL" select="'&#10;'"/>
52 <!-- String that a tabulator is expanded with in preformatted paragraphs. -->
54 <variable name="codetabdocument-value"
55 select="/office:document/office:meta/meta:user-defined[@meta:name='CODE_TAB_REPLACEMENT']"/>
57 <param name="CODE_TAB_REPLACEMENT">
59 <choose>
61 <when test="boolean($codetabdocument-value)">
62 <value-of select="$codetabdocument-value"/>
63 </when>
65 <otherwise>
66 <value-of select="' '"/>
67 </otherwise>
68 </choose>
69 </param>
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')"/>
77 <variable name="document-value"
78 select="/office:document/office:meta/meta:user-defined[@meta:name='CODE_STYLES']"/>
80 <param name="CODE_STYLES">
82 <choose>
83 <when test="boolean($document-value)">
84 <value-of select="$document-value"/>
85 </when>
87 <otherwise>
88 <value-of select="''"/>
89 </otherwise>
90 </choose>
91 </param>
93 <variable name="table-class"
94 select="/office:document/office:meta/meta:user-defined[@meta:name='TABLE_CLASS']"/>
96 <param name="TABLE_CLASS">
97 <choose>
98 <when test="boolean($table-class)">
99 <value-of select="$table-class"/>
100 </when>
102 <otherwise>
103 <value-of select="''"/>
104 </otherwise>
105 </choose>
106 </param>
108 <variable name="USE_DEFAULT_TABLE_CLASS" select="string-length($TABLE_CLASS) &gt; 0"/>
111 <!--
112 == Wiki style constants ==
115 <!-- Bold character style. -->
116 <variable name="BOLD_BIT" select="1"/>
118 <!-- Italic character style. -->
119 <variable name="ITALIC_BIT" select="2"/>
121 <!-- Underline character style. -->
122 <variable name="UNDERLINE_BIT" select="4"/>
124 <!-- Subscript character style. -->
125 <variable name="SUBSCRIPT_BIT" select="8"/>
127 <!-- Superscript character style. -->
128 <variable name="SUPERSCRIPT_BIT" select="16"/>
130 <!-- Typewriter character style. -->
131 <variable name="TYPEWRITER_BIT" select="32"/>
133 <!-- Preformatted text paragraph style. -->
134 <variable name="CODE_BIT" select="64"/>
136 <!-- Centered paragraph style. -->
137 <variable name="CENTER_BIT" select="128"/>
139 <!-- Right aligned paragraph style. -->
140 <variable name="RIGHT_BIT" select="256"/>
142 <!-- Constant defining the empty style. -->
143 <variable name="NO_STYLE" select="0"/>
147 <output
148 method="text"
149 media-type="text/plain"
150 encoding="UTF-8"
154 <!--
155 == Reference resolution ==
158 <key
159 name="style-ref"
160 match="//style:style"
161 use="@style:name"
164 <key
165 name="list-style-ref"
166 match="//text:list-style"
167 use="@style:name"
170 <key
171 name="font-face-ref"
172 match="//style:font-face"
173 use="@style:name"
176 <key
177 name="text:table-of-content-entry-ref"
178 match="//text:table-of-content-entry-template"
179 use="@text:style-name"
182 <key
183 name="reference-resolution"
184 match="//text:reference-mark | //text:reference-mark-start"
185 use="@text:name"
189 <!--
190 Multiple pages (draw only)
193 <template match="draw:page">
194 <value-of select="concat('&#10;&lt;!-- Page ', @draw:name, '--&gt;&#10;')"/>
195 <apply-templates/>
196 <value-of select="'&#10;----&#10;&#10;'"/>
197 </template>
200 <!--
201 == Lists ==
204 <template match="text:list">
205 <!--
206 Check, whether this list is used to implement the outline numbering
207 for headings. Such list must not be exported, because within the wiki,
208 automatic outline numbering is performed. An outline list has a single
209 text:h element as its single leaf grandchild.
211 This method of section numbering seems not to be used when creating new
212 documents with OpenOffice.org 2.2, but the document containing the
213 OpenDocument specification version 1.1 uses such numbering through nested
214 lists.
216 <choose>
217 <when test="boolean(./descendant::node()[not(./self::text:list) and not(./self::text:list-item) and not(./ancestor-or-self::text:h)])">
218 <apply-templates/>
219 </when>
221 <otherwise>
222 <apply-templates select=".//text:h"/>
223 </otherwise>
224 </choose>
225 </template>
227 <template match="text:list-item">
228 <if test="position() &gt; 1 or boolean(ancestor::text:list-item)">
229 <value-of select="$NL"/>
230 </if>
231 <variable name="list-style"
232 select="key('list-style-ref',ancestor::text:list[boolean(@text:style-name)][1]/@text:style-name)"/>
233 <call-template name="mk-list-token">
234 <with-param name="list-style" select="$list-style"/>
235 <with-param name="level" select="count(ancestor::text:list)"/>
236 </call-template>
237 <text> </text>
238 <apply-templates/>
239 <if test="position() = last() and not(boolean(ancestor::text:list-item))">
240 <!-- End of (potentially nested) list is marked with a double newline. -->
241 <value-of select="$NL"/>
242 <value-of select="$NL"/>
243 </if>
244 </template>
246 <template name="mk-list-token">
247 <param name="list-style"/>
248 <param name="level"/>
250 <if test="$level &gt; 1">
251 <call-template name="mk-list-token">
252 <with-param name="list-style" select="$list-style"/>
253 <with-param name="level" select="$level - 1"/>
254 </call-template>
255 </if>
257 <variable name="number-style" select="$list-style/text:list-level-style-number[@text:level=$level]"/>
258 <variable name="bullet-style" select="$list-style/text:list-level-style-bullet[@text:level=$level]"/>
259 <choose>
260 <when test="boolean($number-style)">
261 <choose>
262 <when test="string-length($number-style/@style:num-format) &gt; 0">
263 <text>#</text>
264 </when>
265 <otherwise>
266 <text>:</text>
267 </otherwise>
268 </choose>
269 </when>
270 <when test="boolean($bullet-style)">
271 <text>*</text>
272 </when>
273 </choose>
274 </template>
277 <!--
278 == Headings ==
281 <template match="text:h">
282 <if test="string-length(.) &gt; 0">
283 <variable name="token">
284 <call-template name="mk-heading-prefix">
285 <with-param name="level" select="@text:outline-level"/>
286 </call-template>
287 </variable>
288 <value-of select="$token"/>
289 <text> </text>
290 <apply-templates/>
291 <text> </text>
292 <value-of select="$token"/>
293 <value-of select="$NL"/>
294 <value-of select="$NL"/>
295 </if>
296 </template>
298 <template match="text:index-title">
299 <text>__NOTOC__</text>
300 <value-of select="$NL"/>
301 <text>== </text>
302 <apply-templates/>
303 <text> ==</text>
304 <value-of select="$NL"/>
305 <value-of select="$NL"/>
306 </template>
308 <!--
309 Function generating a wiki heading prefix.
311 @param level
312 The heading level. The value must be between 1 and 6.
314 <template name="mk-heading-prefix">
315 <param name="level"/>
316 <choose>
317 <when test="$level &gt; 6">
318 <call-template name="mk-heading-prefix">
319 <with-param name="level" select="6"/>
320 </call-template>
321 </when>
322 <when test="$level &gt; 0">
323 <text>=</text>
324 <call-template name="mk-heading-prefix">
325 <with-param name="level" select="$level - 1"/>
326 </call-template>
327 </when>
328 </choose>
329 </template>
331 <!--
332 Function generating a token consisting of the given character
333 repeated 'level' times.
335 @param level
336 The length of the result.
337 @param char
338 The character that should be repeated 'level' times.
340 <template name="mk-token">
341 <param name="level"/>
342 <param name="char"/>
343 <if test="$level &gt; 0">
344 <value-of select="$char"/>
345 <call-template name="mk-token">
346 <with-param name="level" select="$level - 1"/>
347 <with-param name="char" select="$char"/>
348 </call-template>
349 </if>
350 </template>
353 <!--
354 == Tables ==
357 <template match="table:table">
358 <value-of select="$NL"/>
359 <text>{|</text>
361 <choose>
362 <when test="$USE_DEFAULT_TABLE_CLASS">
363 <text> class="</text>
364 <value-of select="$TABLE_CLASS"/>
365 <text>"</text>
366 </when>
368 <otherwise>
369 <variable name="style-element" select="key('style-ref', @table:style-name)"/>
370 <variable name="table-align" select="$style-element/style:table-properties/@table:align"/>
371 <!-- Table alignment using align -->
372 <if test="boolean($table-align)">
373 <variable name="align">
374 <choose>
375 <when test="$table-align='center'">
376 <text>center</text>
377 </when>
378 </choose>
379 </variable>
380 <if test="string-length($align) &gt; 0">
381 <text> align="</text>
382 <value-of select="$align"/>
383 <text>"</text>
384 </if>
385 </if>
386 <variable name="style">
387 <!-- Default setting to translate detailed office table cell styles correctly. -->
388 <text>border-spacing:0;</text>
389 <!-- Table alignment using css -->
390 <if test="boolean($table-align)">
391 <choose>
392 <when test="$table-align='margins'">
393 <text>margin:auto;</text>
394 </when>
395 </choose>
396 </if>
397 <if test="boolean($style-element/style:table-properties/@style:width)">
398 <text>width:</text>
399 <value-of select="$style-element/style:table-properties/@style:width"/>
400 <text>;</text>
401 </if>
402 </variable>
403 <text> style="</text>
404 <value-of select="$style"/>
405 <text>"</text>
406 </otherwise>
407 </choose>
409 <value-of select="$NL"/>
410 <apply-templates/>
411 <text>|-</text>
412 <value-of select="$NL"/>
413 <text>|}</text>
414 <value-of select="$NL"/>
415 </template>
417 <template match="table:table-header-rows">
418 <apply-templates/>
419 </template>
421 <template match="table:table-row">
422 <text>|-</text>
424 <if test="not($USE_DEFAULT_TABLE_CLASS) and boolean(table:table-cell[1]/@table:style-name)">
425 <variable name="style-name" select="table:table-cell[1]/@table:style-name"/>
426 <variable name="total-style-name" select="count(table:table-cell/@table:style-name)"/>
427 <variable name="total-equal-style-name" select="count(table:table-cell[@table:style-name=$style-name])"/>
429 <variable name="style">
430 <if test="$total-equal-style-name=$total-style-name">
431 <call-template name="translate-table-cell-properties">
432 <with-param name="style-element" select="key('style-ref', $style-name)"/>
433 </call-template>
434 </if>
435 </variable>
437 <if test="string-length($style) &gt; 0">
438 <text> style="</text>
439 <value-of select="$style"/>
440 <text>"</text>
441 </if>
442 </if>
444 <value-of select="$NL"/>
445 <apply-templates/>
446 </template>
448 <template match="table:table-header-rows//table:table-cell">
449 <text>!</text>
450 <if test="@table:number-columns-spanned">
451 <text>colspan="</text>
452 <value-of select="@table:number-columns-spanned"/>
453 <text>" | </text>
454 </if>
456 <!-- Cell alignment -->
457 <if test="text:p and count(*) = 1">
458 <variable name="style-number">
459 <call-template name="mk-style-set">
460 <with-param name="node" select="text:p"/>
461 </call-template>
462 </variable>
464 <variable name="code"
465 select="($style-number mod (2 * $CODE_BIT)) - ($style-number mod ($CODE_BIT)) != 0"/>
466 <variable name="center"
467 select="($style-number mod (2 * $CENTER_BIT)) - ($style-number mod ($CENTER_BIT)) != 0"/>
468 <variable name="right"
469 select="($style-number mod (2 * $RIGHT_BIT)) - ($style-number mod ($RIGHT_BIT)) != 0"/>
471 <choose>
472 <when test="$center">
473 <text> align=center</text>
474 </when>
475 <when test="$right">
476 <text> align=right</text>
477 </when>
478 </choose>
479 </if>
481 <if test="not($USE_DEFAULT_TABLE_CLASS) and boolean(@table:style-name)">
482 <variable name="style-name" select="@table:style-name"/>
484 <variable name="style">
485 <!-- Only if cells have a different style-name -->
486 <if test="count(../table:table-cell/@table:style-name) != count(../table:table-cell[@table:style-name=$style-name]) and count(../table:table-cell/@table:style-name) &gt; 0">
487 <call-template name="translate-table-cell-properties">
488 <with-param name="style-element" select="key('style-ref', $style-name)"/>
489 </call-template>
490 </if>
491 </variable>
493 <if test="string-length($style) &gt; 0">
494 <text> style="</text>
495 <value-of select="$style"/>
496 <text>" </text>
497 </if>
498 </if>
499 <text>| </text>
500 <apply-templates/>
501 <value-of select="$NL"/>
502 </template>
504 <template match="table:table-cell">
505 <text>|</text>
506 <if test="@table:number-columns-spanned">
507 <text> colspan="</text>
508 <value-of select="@table:number-columns-spanned"/>
509 <text>" </text>
510 </if>
512 <!-- Cell alignment -->
513 <if test="text:p and count(*) = 1">
514 <variable name="style-number">
515 <call-template name="mk-style-set">
516 <with-param name="node" select="text:p"/>
517 </call-template>
518 </variable>
520 <variable name="code"
521 select="($style-number mod (2 * $CODE_BIT)) - ($style-number mod ($CODE_BIT)) != 0"/>
522 <variable name="center"
523 select="($style-number mod (2 * $CENTER_BIT)) - ($style-number mod ($CENTER_BIT)) != 0"/>
524 <variable name="right"
525 select="($style-number mod (2 * $RIGHT_BIT)) - ($style-number mod ($RIGHT_BIT)) != 0"/>
527 <choose>
528 <when test="$center">
529 <text> align=center</text>
530 </when>
531 <when test="$right">
532 <text> align=right</text>
533 </when>
534 </choose>
535 </if>
537 <if test="not($USE_DEFAULT_TABLE_CLASS) and boolean(@table:style-name)">
538 <variable name="style-name" select="@table:style-name"/>
540 <variable name="style">
541 <!-- Only if cells have a different style-name -->
542 <if test="count(../table:table-cell/@table:style-name) != count(../table:table-cell[@table:style-name=$style-name]) and count(../table:table-cell/@table:style-name) &gt; 0">
543 <call-template name="translate-table-cell-properties">
544 <with-param name="style-element" select="key('style-ref', $style-name)"/>
545 </call-template>
546 </if>
547 <!-- Font color -->
548 <if test="text:p and count(*) = 1">
549 <if test="boolean(text:p/@text:style-name)">
550 <variable name="style-element" select="key('style-ref', text:p/@text:style-name)"/>
552 <call-template name="translate-style-property">
553 <with-param name="style-name" select="'color'"/>
554 <with-param name="style-property" select="$style-element/style:text-properties/@fo:color"/>
555 </call-template>
556 </if>
557 </if>
558 </variable>
560 <if test="string-length($style) &gt; 0">
561 <text> style="</text>
562 <value-of select="$style"/>
563 <text>" </text>
564 </if>
565 </if>
566 <text>| </text>
567 <apply-templates/>
568 <value-of select="$NL"/>
569 </template>
571 <template name="translate-table-cell-properties">
572 <param name="style-element"/>
573 <call-template name="translate-style-property">
574 <with-param name="style-name" select="'background-color'"/>
575 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:background-color"/>
576 </call-template>
578 <call-template name="translate-style-property">
579 <with-param name="style-name" select="'border'"/>
580 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:border"/>
581 </call-template>
582 <call-template name="translate-style-property">
583 <with-param name="style-name" select="'border-top'"/>
584 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:border-top"/>
585 </call-template>
586 <call-template name="translate-style-property">
587 <with-param name="style-name" select="'border-bottom'"/>
588 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:border-bottom"/>
589 </call-template>
590 <call-template name="translate-style-property">
591 <with-param name="style-name" select="'border-left'"/>
592 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:border-left"/>
593 </call-template>
594 <call-template name="translate-style-property">
595 <with-param name="style-name" select="'border-right'"/>
596 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:border-right"/>
597 </call-template>
599 <call-template name="translate-style-property">
600 <with-param name="style-name" select="'padding'"/>
601 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:padding"/>
602 </call-template>
603 <call-template name="translate-style-property">
604 <with-param name="style-name" select="'padding-top'"/>
605 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:padding-top"/>
606 </call-template>
607 <call-template name="translate-style-property">
608 <with-param name="style-name" select="'padding-bottom'"/>
609 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:padding-bottom"/>
610 </call-template>
611 <call-template name="translate-style-property">
612 <with-param name="style-name" select="'padding-left'"/>
613 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:padding-left"/>
614 </call-template>
615 <call-template name="translate-style-property">
616 <with-param name="style-name" select="'padding-right'"/>
617 <with-param name="style-property" select="$style-element/style:table-cell-properties/@fo:padding-right"/>
618 </call-template>
619 </template>
621 <template name="translate-style-property">
622 <param name="style-name"/>
623 <param name="style-property"/>
625 <if test="boolean($style-property)">
626 <value-of select="$style-name"/>
627 <text>:</text>
628 <value-of select="string($style-property)"/>
629 <text>;</text>
630 </if>
631 </template>
633 <!--
634 == WikiMath ==
637 <!--
638 Make sure to join sibling node that are all formatted with WikiMath style without repeating
639 the <math>..</math> markup.
641 Do not apply any transformation to the contents marked as WikiMath.
643 <template match="text:span[@text:style-name='WikiMath']">
644 <value-of select="'&lt;math&gt;'"/>
645 <value-of select="string(.)"/>
646 <value-of select="'&lt;/math&gt;'"/>
647 </template>
649 <template match="text:span[@text:style-name='WikiMath' and boolean(preceding-sibling::node()[position()=1 and local-name(.)='span' and @text:style-name='WikiMath'])]">
650 <value-of select="string(.)"/>
651 <value-of select="'&lt;/math&gt;'"/>
652 </template>
654 <template match="text:span[@text:style-name='WikiMath' and boolean(following-sibling::node()[position()=1 and local-name(.)='span' and @text:style-name='WikiMath'])]">
655 <value-of select="'&lt;math&gt;'"/>
656 <value-of select="string(.)"/>
657 </template>
659 <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'])]">
660 <value-of select="string(.)"/>
661 </template>
663 <!--
664 == Native links ==
667 <template match="text:a">
668 <variable name="link-ref" select="@xlink:href"/>
669 <choose>
670 <when test="string-length($link-ref) &gt; 0">
671 <choose>
672 <when test="starts-with($link-ref, '#')">
673 <text>[[</text>
674 <choose>
675 <when test="contains($link-ref, '_')">
676 <value-of select="translate($link-ref,'_','')"/>
677 </when>
678 <otherwise>
679 <value-of select="$link-ref"/>
680 </otherwise>
681 </choose>
682 <text>|</text>
683 <choose>
684 <when test="text:tab and ancestor::text:index-body">
685 <value-of select="node()[1]"/>
686 </when>
687 <otherwise>
688 <value-of select="string(.)"/>
689 </otherwise>
690 </choose>
691 <text>]]</text>
692 </when>
694 <otherwise>
695 <text>[</text>
696 <value-of select="$link-ref"/>
697 <text> </text>
698 <value-of select="string(.)"/>
699 <text>]</text>
700 </otherwise>
701 </choose>
702 </when>
704 <otherwise>
705 <apply-templates/>
706 </otherwise>
707 </choose>
708 </template>
710 <!--
711 Function for generating tabulations in TOC entries.
713 @param style
714 The style of the TOC entry
716 <template name="mk-tab-toc">
717 <param name="style"/>
718 <if test="number($style/@text:outline-level) &gt; 0">
719 <call-template name="mk-token">
720 <with-param name="level" select="number($style/@text:outline-level) - 1"/>
721 <with-param name="char" select="':'"/>
722 </call-template>
723 </if>
724 </template>
726 <!--
727 == WikiLink ==
730 <template match="text:span[@text:style-name='WikiLink']">
731 <value-of select="'[['"/>
732 <variable name="link-def" select="string(.)"/>
733 <variable name="link-label" select="normalize-space(substring-before($link-def, '['))"/>
734 <variable name="link-ref" select="normalize-space(substring-before(substring-after($link-def, '['), ']'))"/>
735 <choose>
736 <when test="boolean($link-ref)">
737 <value-of select="concat($link-ref, '|', $link-label)"/>
738 </when>
739 <otherwise>
740 <value-of select="$link-def"/>
741 </otherwise>
742 </choose>
743 <value-of select="']]'"/>
744 </template>
747 <!--
748 == Paragraphs ==
751 <template match="text:p">
752 <!-- TOC tabs -->
753 <if test="ancestor::text:index-body and boolean(@text:style-name)">
754 <variable name="style" select="key('style-ref', @text:style-name)"/>
755 <if test="boolean($style/@style:parent-style-name)">
756 <call-template name="mk-tab-toc">
757 <with-param name="style" select="key('text:table-of-content-entry-ref', $style/@style:parent-style-name)"/>
758 </call-template>
759 </if>
760 </if>
762 <variable name="alignment">
763 <call-template name="mk-style-set">
764 <with-param name="node" select="."/>
765 </call-template>
766 </variable>
768 <variable name="code"
769 select="($alignment mod (2 * $CODE_BIT)) - ($alignment mod ($CODE_BIT)) != 0"/>
770 <variable name="center"
771 select="($alignment mod (2 * $CENTER_BIT)) - ($alignment mod ($CENTER_BIT)) != 0"/>
772 <variable name="right"
773 select="($alignment mod (2 * $RIGHT_BIT)) - ($alignment mod ($RIGHT_BIT)) != 0"/>
775 <variable name="style">
776 <choose>
777 <when test="name(parent::*) != 'table:table-cell'">
778 <choose>
779 <when test="$center">
780 <text>text-align:center;</text>
781 </when>
782 <when test="$right">
783 <text>text-align:right;</text>
784 </when>
785 </choose>
786 <if test="boolean(@text:style-name)">
787 <variable name="style-element" select="key('style-ref', @text:style-name)"/>
789 <call-template name="translate-style-property">
790 <with-param name="style-name" select="'color'"/>
791 <with-param name="style-property" select="$style-element/style:text-properties/@fo:color"/>
792 </call-template>
793 <call-template name="translate-style-property">
794 <with-param name="style-name" select="'margin-left'"/>
795 <with-param name="style-property" select="$style-element/style:paragraph-properties/@fo:margin-left"/>
796 </call-template>
797 <call-template name="translate-style-property">
798 <with-param name="style-name" select="'margin-right'"/>
799 <with-param name="style-property" select="$style-element/style:paragraph-properties/@fo:margin-right"/>
800 </call-template>
801 </if>
802 </when>
803 <otherwise>
804 <if test="count(../text:p) &gt; 1 and boolean(@text:style-name)">
805 <variable name="style-element" select="key('style-ref', @text:style-name)"/>
807 <call-template name="translate-style-property">
808 <with-param name="style-name" select="'color'"/>
809 <with-param name="style-property" select="$style-element/style:text-properties/@fo:color"/>
810 </call-template>
811 </if>
812 </otherwise>
813 </choose>
814 </variable>
816 <if test="string-length($style) &gt; 0">
817 <text>&lt;div style="</text>
818 <value-of select="$style"/>
819 <text>"&gt;</text>
820 </if>
822 <apply-templates/>
824 <if test="string-length($style) &gt; 0">
825 <text>&lt;/div&gt;</text>
826 </if>
828 <variable name="paragraph-right"
829 select="./following-sibling::*[1]/self::text:p"/>
831 <choose>
832 <when test="boolean($paragraph-right)">
833 <!--
834 Insert end of line only if not within a list. Within wiki lists,
835 a line break leaves the current list item.
837 <choose>
838 <when test="boolean(ancestor::text:list-item)">
839 <text>&lt;br/&gt;</text>
840 </when>
841 <when test="$code">
842 <variable name="style-right">
843 <call-template name="mk-style-set">
844 <with-param name="node" select="$paragraph-right"/>
845 </call-template>
846 </variable>
848 <variable name="code-right"
849 select="($style-right mod (2 * $CODE_BIT)) - ($style-right mod ($CODE_BIT)) != 0"/>
851 <choose>
852 <when test="$code-right">
853 <choose>
854 <when test="$CODE_JOIN_PARAGRAPHS">
855 <value-of select="$NL"/>
856 </when>
858 <otherwise>
859 <value-of select="$NL"/>
860 <value-of select="' '"/>
861 <value-of select="$NL"/>
862 </otherwise>
863 </choose>
864 </when>
865 <otherwise>
866 <value-of select="$NL"/>
867 <value-of select="$NL"/>
868 </otherwise>
869 </choose>
870 </when>
871 <otherwise>
872 <value-of select="$NL"/>
873 <value-of select="$NL"/>
874 </otherwise>
875 </choose>
876 </when>
877 <when test="not(boolean(ancestor::text:note)) and (boolean(./following::*[1]/self::text:h) or boolean(./following::*[1]/self::table:table) or boolean(./following::*[1]/self::text:bibliography))">
878 <!-- Newline before following heading or table. -->
879 <value-of select="$NL"/>
880 <value-of select="$NL"/>
881 </when>
882 <when test="not(./following-sibling::*[1]) and name(./following::*[1])='text:p' and ancestor::text:list-item">
883 <!-- End of the list -->
884 <value-of select="$NL"/>
885 <value-of select="$NL"/>
886 </when>
887 </choose>
888 </template>
890 <template match="text:p[string-length(.) = 0 and string-length(preceding-sibling::*[1]/self::text:p) &gt; 0]">
891 <value-of select="$NL"/>
892 </template>
894 <!--
895 == Preformatted text ==
898 <template match="text:s">
899 <variable name="style">
900 <call-template name="mk-style-set">
901 <with-param name="node" select="."/>
902 </call-template>
903 </variable>
905 <variable name="code"
906 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
908 <if test="$code">
909 <choose>
910 <when test="@text:c">
911 <call-template name="mk-token">
912 <with-param name="level" select="@text:c"/>
913 <with-param name="char" select="' '"/>
914 </call-template>
915 </when>
916 <otherwise>
917 <value-of select="' '"/>
918 </otherwise>
919 </choose>
920 </if>
921 </template>
923 <template match="text:span[string-length(.) &gt; 0]">
924 <if test="boolean(@text:style-name)">
925 <variable name="style-element" select="key('style-ref', @text:style-name)"/>
926 <variable name="style">
927 <call-template name="translate-style-property">
928 <with-param name="style-name" select="'background-color'"/>
929 <with-param name="style-property" select="$style-element/style:text-properties/@fo:background-color"/>
930 </call-template>
931 <call-template name="translate-style-property">
932 <with-param name="style-name" select="'color'"/>
933 <with-param name="style-property" select="$style-element/style:text-properties/@fo:color"/>
934 </call-template>
935 </variable>
937 <if test="string-length($style) &gt; 0">
938 <text>&lt;span style="</text>
939 <value-of select="$style"/>
940 <text>"&gt;</text>
941 </if>
943 <apply-templates/>
945 <if test="string-length($style) &gt; 0">
946 <text>&lt;/span&gt;</text>
947 </if>
948 </if>
949 </template>
951 <template match="text:tab">
952 <variable name="style">
953 <call-template name="mk-style-set">
954 <with-param name="node" select="."/>
955 </call-template>
956 </variable>
958 <variable name="code"
959 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
961 <if test="$code">
962 <value-of select="$CODE_TAB_REPLACEMENT"/>
963 </if>
964 </template>
966 <template match="text:line-break">
967 <variable name="style">
968 <call-template name="mk-style-set">
969 <with-param name="node" select="."/>
970 </call-template>
971 </variable>
973 <variable name="code"
974 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
976 <if test="$code">
977 <value-of select="$NL"/>
978 <value-of select="' '"/>
979 </if>
980 </template>
982 <!--
983 Footnotes
986 <template match="text:note-body">
987 <variable name="note" select="./parent::text:note"/>
989 <if test="$note/@text:note-class = 'footnote'">
990 <text>&lt;ref name="</text>
991 <value-of select="$note/@text:id"/>
992 <text>"&gt;</text>
993 <apply-templates/>
994 <text>&lt;/ref&gt;</text>
995 </if>
996 </template>
998 <template match="text:note-ref[@text:note-class='footnote']">
999 <text>&lt;ref name="</text>
1000 <value-of select="@text:ref-name"/>
1001 <text>"/&gt;</text>
1002 </template>
1005 <!--
1006 == Images ==
1009 <template match="draw:text-box[boolean(.//draw:image)]">
1010 <variable name="image" select=".//draw:image[1]"/>
1012 <variable name="image-description">
1013 <apply-templates/>
1014 </variable>
1016 <variable name="picture">
1017 <text>[[</text>
1018 <call-template name="mk-image-name">
1019 <with-param name="image" select="$image"/>
1020 <with-param name="frame" select="."/>
1021 <with-param name="extension" select="'.png'"/>
1022 </call-template>
1023 <text>|thumb</text>
1024 </variable>
1026 <!-- Picture markup + Horizontal & Vertical align -->
1027 <call-template name="mk-image-align">
1028 <with-param name="picture" select="$picture"/>
1029 </call-template>
1031 <!-- Image caption -->
1032 <text>|</text>
1033 <value-of select="normalize-space($image-description)"/>
1035 <text>]]</text>
1036 </template>
1038 <template match="draw:image[not(boolean(ancestor::draw:text-box))]">
1039 <variable name="picture">
1040 <text>[[</text>
1041 <call-template name="mk-image-name">
1042 <with-param name="image" select="."/>
1043 <with-param name="frame" select="parent::node()"/>
1044 </call-template>
1045 </variable>
1047 <!-- Picture markup + Horizontal & Vertical align -->
1048 <call-template name="mk-image-align">
1049 <with-param name="picture" select="$picture"/>
1050 </call-template>
1052 <!-- Image alt -->
1053 <if test="name(following-sibling::*)='svg:title'">
1054 <text>|alt="</text>
1055 <value-of select="following-sibling::*/text()"/>
1056 <text>"</text>
1057 </if>
1059 <text>]]</text>
1060 </template>
1062 <template name="mk-image-align">
1063 <param name="picture"/>
1065 <choose>
1066 <when test="name(..)='draw:frame' and boolean(../@draw:style-name)">
1067 <variable name="style-element" select="key('style-ref', ../@draw:style-name)"/>
1068 <choose>
1069 <when test="boolean($style-element/style:graphic-properties/@style:wrap)">
1070 <choose>
1071 <!-- wrap=none -->
1072 <when test="$style-element/style:graphic-properties/@style:wrap='none'">
1073 <text>{{clear}}</text>
1074 <value-of select="$NL"/>
1075 <value-of select="$picture"/>
1076 <choose>
1077 <when test="boolean($style-element/style:graphic-properties/@style:horizontal-pos)">
1078 <choose>
1079 <when test="$style-element/style:graphic-properties/@style:horizontal-pos='center'">
1080 <text>|center</text>
1081 </when>
1082 <otherwise>
1083 <text>|none</text>
1084 </otherwise>
1085 </choose>
1086 </when>
1087 <otherwise>
1088 <text>|none</text>
1089 </otherwise>
1090 </choose>
1091 </when>
1092 <!-- wrap != none -->
1093 <otherwise>
1094 <value-of select="$picture"/>
1095 <!-- Horizontal align -->
1096 <call-template name="mk-image-horizontal-align">
1097 <with-param name="style-element" select="$style-element"/>
1098 </call-template>
1099 <!-- Vertical align -->
1100 <call-template name="mk-image-vertical-align">
1101 <with-param name="style-element" select="$style-element"/>
1102 </call-template>
1103 </otherwise>
1104 </choose>
1105 </when>
1106 <!-- without wrap -->
1107 <otherwise>
1108 <value-of select="$picture"/>
1109 <!-- Horizontal align -->
1110 <call-template name="mk-image-horizontal-align">
1111 <with-param name="style-element" select="$style-element"/>
1112 </call-template>
1113 <!-- Vertical align -->
1114 <call-template name="mk-image-vertical-align">
1115 <with-param name="style-element" select="$style-element"/>
1116 </call-template>
1117 </otherwise>
1118 </choose>
1119 </when>
1120 <otherwise>
1121 <value-of select="$picture"/>
1122 </otherwise>
1123 </choose>
1124 </template>
1126 <template name="mk-image-horizontal-align">
1127 <param name="style-element"/>
1129 <if test="boolean($style-element/style:graphic-properties/@style:horizontal-pos)">
1130 <choose>
1131 <when test="$style-element/style:graphic-properties/@style:horizontal-pos='right'">
1132 <text>|right</text>
1133 </when>
1134 <when test="$style-element/style:graphic-properties/@style:horizontal-pos='left'">
1135 <text>|left</text>
1136 </when>
1137 </choose>
1138 </if>
1139 </template>
1141 <template name="mk-image-vertical-align">
1142 <param name="style-element"/>
1144 <if test="boolean($style-element/style:graphic-properties/@style:vertical-pos)">
1145 <choose>
1146 <when test="$style-element/style:graphic-properties/@style:vertical-pos='top'">
1147 <text>|top</text>
1148 </when>
1149 <when test="$style-element/style:graphic-properties/@style:vertical-pos='middle'">
1150 <text>|middle</text>
1151 </when>
1152 <when test="$style-element/style:graphic-properties/@style:vertical-pos='below'">
1153 <text>|below</text>
1154 </when>
1155 </choose>
1156 </if>
1157 </template>
1159 <template name="mk-image-name">
1160 <param name="image"/>
1161 <param name="frame"/>
1162 <param name="extension"/>
1164 <variable name="base-name">
1165 <call-template name="mk-base-name">
1166 <with-param name="href" select="$image/@xlink:href"/>
1167 </call-template>
1168 </variable>
1170 <if test="not(starts-with($base-name, 'Image:'))">
1171 <value-of select="'Image:'"/>
1172 </if>
1173 <value-of select="$base-name"/>
1174 <value-of select="$frame/@draw:name"/>
1175 <value-of select="'.png'"/>
1176 </template>
1178 <template name="mk-base-name">
1179 <param name="href"/>
1181 <variable name="result" select="substring-after($href, '/')"/>
1182 <choose>
1183 <when test="boolean($result)">
1184 <call-template name="mk-base-name">
1185 <with-param name="href" select="$result"/>
1186 </call-template>
1187 </when>
1188 <otherwise>
1189 <value-of select="$href"/>
1190 </otherwise>
1191 </choose>
1192 </template>
1194 <!-- Frames -->
1196 <template match="draw:frame">
1197 <choose>
1198 <when test="draw:object/math:math">
1199 <apply-templates select="draw:object/math:math[1]"/>
1200 </when>
1202 <when test="draw:image">
1203 <apply-templates select="draw:image[1]"/>
1204 </when>
1206 <otherwise>
1207 <apply-templates select="./*[1]"/>
1208 </otherwise>
1209 </choose>
1211 </template>
1213 <!-- Formulas (Objects) -->
1215 <include href="math/mmltex.xsl"/>
1217 <template match="math:math" priority="1">
1218 <text>&lt;math&gt;</text>
1219 <apply-templates/>
1220 <text>&lt;/math&gt;</text>
1221 </template>
1224 <!--
1225 References
1228 <!-- TODO: text:bibliography-mark -->
1230 <template match="text:reference-ref">
1231 <variable name="reference-mark" select="key('reference-resolution', @text:ref-name)"/>
1233 <choose>
1234 <when test="boolean($reference-mark)">
1235 <!--
1236 In wiki syntax, only a local reference to a heading can be inserted.
1237 If the link target is a descendant of a heading element, a link can be
1238 inserted in the result. -->
1239 <variable name="header-anchor" select="$reference-mark/ancestor::text:h[1]"/>
1240 <if test="boolean($header-anchor)">
1241 <text>[[#</text>
1242 <value-of select="string($header-anchor)"/>
1243 <text>|</text>
1244 </if>
1246 <variable name="reference-text" select="string(.)"/>
1248 <choose>
1249 <!-- Check, whether the reference text is cached in the document. -->
1250 <when test="string-length($reference-text) &gt; 0">
1251 <value-of select="$reference-text"/>
1252 </when>
1254 <otherwise>
1255 <!--
1256 TODO: Evaluate the @text:reference-format attribute and
1257 generate the replacement text (difficult).-->
1258 <text>(REFERENCE TEXT UNAVAILABLE: "</text>
1259 <value-of select="@text:ref-name"/>
1260 <text>")</text>
1261 </otherwise>
1262 </choose>
1264 <if test="boolean($header-anchor)">
1265 <text>]]</text>
1266 </if>
1267 </when>
1269 <otherwise>
1270 <text>(UNDEFINED REFERENCE: "</text>
1271 <value-of select="@text:ref-name"/>
1272 <text>")</text>
1273 </otherwise>
1274 </choose>
1275 </template>
1277 <template match="text:reference-mark">
1278 <!-- TODO: Output an anchor. -->
1279 <apply-templates/>
1280 </template>
1282 <template match="text:reference-mark-start">
1283 <!-- TODO: Output an anchor. -->
1284 </template>
1286 <template match="text:bookmark-start">
1287 <if test="boolean(@text:name)">
1288 <variable name="bookmark">
1289 <choose>
1290 <when test="contains(@text:name,'_')">
1291 <value-of select="translate(@text:name,'_','')"/>
1292 </when>
1293 <otherwise>
1294 <value-of select="@text:name"/>
1295 </otherwise>
1296 </choose>
1297 </variable>
1298 <text>{{anchor|</text>
1299 <value-of select="$bookmark"/>
1300 <text>}} </text>
1301 </if>
1302 <apply-templates/>
1303 </template>
1305 <!--
1306 == Plain text ==
1309 <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()">
1310 <choose>
1311 <when test="boolean(./ancestor::table:table-header-rows) or boolean(./ancestor::text:h)">
1312 <!--
1313 No explicit styles within table headings or section headings,
1314 because those styles are consistently declared by the Wiki engine. -->
1315 <value-of select="."/>
1316 </when>
1318 <when test="string-length(.) &gt; 0">
1319 <variable name="style">
1320 <call-template name="mk-style-set">
1321 <with-param name="node" select="./parent::node()"/>
1322 </call-template>
1323 </variable>
1325 <variable name="current-paragraph"
1326 select="./ancestor::text:p[1]"/>
1327 <variable name="paragraph-id"
1328 select="generate-id($current-paragraph)"/>
1329 <variable name="frames"
1330 select="$current-paragraph/descendant::draw:frame"/>
1331 <variable name="frame-count"
1332 select="count($frames)"/>
1334 <!--
1335 The current style context consists of all text nodes that are
1336 descendants of the paragraph ancestor of this text node but not
1337 descendants of any frame nodes that are descendants of the current
1338 text nodes paragraph.
1340 <variable name="context"
1341 select="$current-paragraph//text()[not(boolean(./ancestor::draw:frame[1]) and count(./ancestor::draw:frame[1] | $frames) = $frame-count)]"/>
1342 <variable name="context-size" select="count($context)"/>
1344 <variable name="context-index">
1345 <call-template name="mk-context-index">
1346 <with-param name="current-id" select="generate-id(.)"/>
1347 <with-param name="context" select="$context"/>
1348 <with-param name="test-index" select="1"/>
1349 </call-template>
1350 </variable>
1352 <variable name="style-left">
1353 <choose>
1354 <when test="$context-index &gt; 1">
1355 <variable name="left" select="$context[$context-index - 1]"/>
1356 <!--
1357 The preceding text node is a child of this nodes topmost
1358 styled ancestor. This means that the result of the
1359 transformation will be directly concatenated.
1361 <call-template name="mk-style-set">
1362 <with-param name="node" select="$left"/>
1363 </call-template>
1364 </when>
1365 <otherwise>
1366 <value-of select="$NO_STYLE"/>
1367 </otherwise>
1368 </choose>
1369 </variable>
1370 <variable name="style-right">
1371 <choose>
1372 <when test="$context-index &lt; count($context)">
1373 <variable name="right" select="$context[$context-index + 1]"/>
1374 <!--
1375 The preceding text node is a child of this nodes topmost
1376 styled ancestor. This means that the result of the
1377 transformation will be directly concatenated.
1379 <call-template name="mk-style-set">
1380 <with-param name="node" select="$right"/>
1381 </call-template>
1382 </when>
1383 <otherwise>
1384 <value-of select="$NO_STYLE"/>
1385 </otherwise>
1386 </choose>
1387 </variable>
1389 <variable name="bold"
1390 select="($style mod (2 * $BOLD_BIT)) != 0"/>
1391 <variable name="italic"
1392 select="($style mod (2 * $ITALIC_BIT)) - ($style mod ($ITALIC_BIT)) != 0"/>
1393 <variable name="underline"
1394 select="($style mod (2 * $UNDERLINE_BIT)) - ($style mod ($UNDERLINE_BIT)) != 0"/>
1395 <variable name="superscript"
1396 select="($style mod (2 * $SUPERSCRIPT_BIT)) - ($style mod ($SUPERSCRIPT_BIT)) != 0"/>
1397 <variable name="subscript"
1398 select="($style mod (2 * $SUBSCRIPT_BIT)) - ($style mod ($SUBSCRIPT_BIT)) != 0"/>
1399 <variable name="code"
1400 select="($style mod (2 * $CODE_BIT)) - ($style mod ($CODE_BIT)) != 0"/>
1401 <variable name="typewriter"
1402 select="($style mod (2 * $TYPEWRITER_BIT)) - ($style mod ($TYPEWRITER_BIT)) != 0"/>
1404 <variable name="bold-left"
1405 select="($style-left mod (2 * $BOLD_BIT)) != 0"/>
1406 <variable name="italic-left"
1407 select="($style-left mod (2 * $ITALIC_BIT)) - ($style-left mod ($ITALIC_BIT)) != 0"/>
1408 <variable name="underline-left"
1409 select="($style-left mod (2 * $UNDERLINE_BIT)) - ($style-left mod ($UNDERLINE_BIT)) != 0"/>
1410 <variable name="superscript-left"
1411 select="($style-left mod (2 * $SUPERSCRIPT_BIT)) - ($style-left mod ($SUPERSCRIPT_BIT)) != 0"/>
1412 <variable name="subscript-left"
1413 select="($style-left mod (2 * $SUBSCRIPT_BIT)) - ($style-left mod ($SUBSCRIPT_BIT)) != 0"/>
1414 <variable name="typewriter-left"
1415 select="($style-left mod (2 * $TYPEWRITER_BIT)) - ($style-left mod ($TYPEWRITER_BIT)) != 0"/>
1417 <variable name="bold-right"
1418 select="($style-right mod (2 * $BOLD_BIT)) != 0"/>
1419 <variable name="italic-right"
1420 select="($style-right mod (2 * $ITALIC_BIT)) - ($style-right mod ($ITALIC_BIT)) != 0"/>
1421 <variable name="underline-right"
1422 select="($style-right mod (2 * $UNDERLINE_BIT)) - ($style-right mod ($UNDERLINE_BIT)) != 0"/>
1423 <variable name="superscript-right"
1424 select="($style-right mod (2 * $SUPERSCRIPT_BIT)) - ($style-right mod ($SUPERSCRIPT_BIT)) != 0"/>
1425 <variable name="subscript-right"
1426 select="($style-right mod (2 * $SUBSCRIPT_BIT)) - ($style-right mod ($SUBSCRIPT_BIT)) != 0"/>
1427 <variable name="typewriter-right"
1428 select="($style-right mod (2 * $TYPEWRITER_BIT)) - ($style-right mod ($TYPEWRITER_BIT)) != 0"/>
1430 <!-- Debugging: Add style infos to the output. -->
1431 <!--
1432 <value-of select="'{'"/>
1433 <value-of select="$style-left"/>
1434 <value-of select="'-'"/>
1435 <value-of select="$style"/>
1436 <value-of select="','"/>
1437 <value-of select="$context-size"/>
1438 <value-of select="'}'"/>
1441 <if test="$superscript and not($superscript-left) and not(boolean(ancestor::text:note))">
1442 <text>&lt;sup&gt;</text>
1443 </if>
1444 <if test="$subscript and not($subscript-left)">
1445 <text>&lt;sub&gt;</text>
1446 </if>
1447 <if test="not($code) and $typewriter and not($typewriter-left)">
1448 <text>&lt;tt&gt;</text>
1449 </if>
1450 <if test="$underline and not($underline-left)">
1451 <text>&lt;u&gt;</text>
1452 </if>
1453 <if test="$bold and not($bold-left)">
1454 <text>'''</text>
1455 </if>
1456 <if test="$italic and not($italic-left)">
1457 <text>''</text>
1458 </if>
1460 <call-template name="render-quoted-text">
1461 <with-param name="text" select="."/>
1462 </call-template>
1464 <if test="$italic and not($italic-right)">
1465 <text>''</text>
1466 </if>
1467 <if test="$bold and not($bold-right)">
1468 <text>'''</text>
1469 </if>
1470 <if test="$underline and not($underline-right)">
1471 <text>&lt;/u&gt;</text>
1472 </if>
1473 <if test="not($code) and $typewriter and not($typewriter-right)">
1474 <text>&lt;/tt&gt;</text>
1475 </if>
1476 <if test="$subscript and not($subscript-right)">
1477 <text>&lt;/sub&gt;</text>
1478 </if>
1479 <if test="$superscript and not($superscript-right) and not(boolean(ancestor::text:note))">
1480 <text>&lt;/sup&gt;</text>
1481 </if>
1483 <!-- Debugging: Add style details to the output. -->
1484 <!--
1485 <value-of select="'{'"/>
1486 <value-of select="$style"/>
1487 <value-of select="'-'"/>
1488 <value-of select="$style-right"/>
1489 <value-of select="'}'"/>
1492 </when>
1493 </choose>
1494 </template>
1496 <!--
1497 Function for looking up the position of a node identified by the given
1498 'current-id' within a node set 'context'.
1500 The search starts with the index 'test-index'. The search is recursive
1501 in the 'test-index' argument. To save recursion depth, each recursive call
1502 iteratively tests a fixed number of indexes (by loop unrolling).
1504 <template name="mk-context-index">
1505 <param name="current-id"/>
1506 <param name="context"/>
1507 <param name="test-index"/>
1509 <variable name="context-size" select="count($context)"/>
1511 <choose>
1512 <when test="context-size &lt; $test-index">
1513 </when>
1514 <when test="$current-id = generate-id($context[$test-index])">
1515 <value-of select="$test-index"/>
1516 </when>
1517 <when test="context-size &lt; ($test-index + 1)">
1518 </when>
1519 <when test="$current-id = generate-id($context[$test-index + 1])">
1520 <value-of select="$test-index + 1"/>
1521 </when>
1522 <when test="context-size &lt; ($test-index + 2)">
1523 </when>
1524 <when test="$current-id = generate-id($context[$test-index + 2])">
1525 <value-of select="$test-index + 2"/>
1526 </when>
1527 <when test="context-size &lt; ($test-index + 3)">
1528 </when>
1529 <when test="$current-id = generate-id($context[$test-index + 3])">
1530 <value-of select="$test-index + 3"/>
1531 </when>
1532 <when test="context-size &lt; ($test-index + 4)">
1533 </when>
1534 <when test="$current-id = generate-id($context[$test-index + 4])">
1535 <value-of select="$test-index + 4"/>
1536 </when>
1537 <when test="context-size &lt; ($test-index + 5)">
1538 </when>
1539 <when test="$current-id = generate-id($context[$test-index + 5])">
1540 <value-of select="$test-index + 5"/>
1541 </when>
1542 <when test="context-size &lt; ($test-index + 6)">
1543 </when>
1544 <otherwise>
1545 <call-template name="mk-context-index">
1546 <with-param name="current-id" select="$current-id"/>
1547 <with-param name="context" select="$context"/>
1548 <with-param name="test-index" select="$test-index + 6"/>
1549 </call-template>
1550 </otherwise>
1551 </choose>
1552 </template>
1554 <template name="render-quoted-text">
1555 <param name="text"/>
1557 <choose>
1558 <when test="contains($text, '[[') or starts-with($text, '----') or starts-with($text, '=') or starts-with($text, '*') or starts-with($text, ';') or starts-with($text, '#')">
1559 <text>&lt;nowiki&gt;</text>
1560 <call-template name="render-encoded-text">
1561 <with-param name="text" select="$text"/>
1562 </call-template>
1563 <text>&lt;/nowiki&gt;</text>
1564 </when>
1565 <otherwise>
1566 <call-template name="render-encoded-text">
1567 <with-param name="text" select="$text"/>
1568 </call-template>
1569 </otherwise>
1570 </choose>
1571 </template>
1573 <template name="render-escaped-text">
1574 <param name="text"/>
1576 <choose>
1577 <when test="contains($text, '&lt;')">
1578 <call-template name="render-encoded-text">
1579 <with-param name="text" select="substring-before($text, '&lt;')"/>
1580 </call-template>
1581 <value-of select="'&amp;lt;'"/>
1582 <call-template name="render-escaped-text">
1583 <with-param name="text" select="substring-after($text, '&lt;')"/>
1584 </call-template>
1585 </when>
1586 <otherwise>
1587 <call-template name="render-encoded-text">
1588 <with-param name="text" select="$text"/>
1589 </call-template>
1590 </otherwise>
1591 </choose>
1592 </template>
1594 <template name="render-encoded-text">
1595 <param name="text"/>
1597 <choose>
1598 <when test="contains($text, '&#160;')">
1599 <value-of select="substring-before($text, '&#160;')"/>
1600 <value-of select="'&amp;nbsp;'"/>
1601 <call-template name="render-encoded-text">
1602 <with-param name="text" select="substring-after($text, '&#160;')"/>
1603 </call-template>
1604 </when>
1605 <otherwise>
1606 <value-of select="$text"/>
1607 </otherwise>
1608 </choose>
1609 </template>
1611 <!--
1612 == Wiki styles: bold, italics, ... ==
1615 <template name="mk-style-set">
1616 <param name="node"/>
1618 <choose>
1619 <when test="$node/ancestor-or-self::*[@text:style-name]">
1620 <variable name="context" select="$node/ancestor-or-self::*[@text:style-name][1]"/>
1621 <call-template name="mk-style-set-internal">
1622 <with-param name="node" select="$context"/>
1623 <with-param name="style" select="key('style-ref', $context/@text:style-name)"/>
1624 <with-param name="style-set" select="$NO_STYLE"/>
1625 <with-param name="style-mask" select="$NO_STYLE"/>
1626 </call-template>
1627 </when>
1628 <otherwise>
1629 <value-of select="$NO_STYLE"/>
1630 </otherwise>
1631 </choose>
1632 </template>
1634 <!--
1635 Compute the wiki style set that corresponds
1636 to the given office style at the given context node.
1638 @param node
1639 A node in which context the style is computed. If neither the given style
1640 nor one of its linked styles does specify a style of the given type,
1641 ancestor nodes of the given context node are considered.
1642 @param style
1643 A style:style element node. The style of the requested type is searched
1644 in the given style and its linked styles.
1645 @style-set
1646 A bit set of styles already defined by the context.
1647 @style-mask
1648 A bit set of styles that must not be taken from the currently inspected
1649 style, because those styles are already defined by the context.
1651 @return A bit set composed of the wiki style constants.
1653 <template name="mk-style-set-internal">
1654 <param name="node"/>
1655 <param name="style"/>
1656 <param name="style-set"/>
1657 <param name="style-mask"/>
1659 <variable name="text-properties" select="$style/style:text-properties"/>
1661 <!-- Decompose style-mask into individual bits. -->
1662 <variable name="bold-requested"
1663 select="($style-mask mod (2 * $BOLD_BIT)) = 0"/>
1664 <variable name="italic-requested"
1665 select="($style-mask mod (2 * $ITALIC_BIT)) - ($style-mask mod ($ITALIC_BIT)) = 0"/>
1666 <variable name="underline-requested"
1667 select="($style-mask mod (2 * $UNDERLINE_BIT)) - ($style-mask mod ($UNDERLINE_BIT)) = 0"/>
1668 <variable name="superscript-requested"
1669 select="($style-mask mod (2 * $SUPERSCRIPT_BIT)) - ($style-mask mod ($SUPERSCRIPT_BIT)) = 0"/>
1670 <variable name="subscript-requested"
1671 select="($style-mask mod (2 * $SUBSCRIPT_BIT)) - ($style-mask mod ($SUBSCRIPT_BIT)) = 0"/>
1672 <variable name="typewriter-requested"
1673 select="($style-mask mod (2 * $TYPEWRITER_BIT)) - ($style-mask mod ($TYPEWRITER_BIT)) = 0"/>
1674 <variable name="code-requested"
1675 select="($style-mask mod (2 * $CODE_BIT)) - ($style-mask mod ($CODE_BIT)) = 0"/>
1676 <variable name="center-requested"
1677 select="($style-mask mod (2 * $CENTER_BIT)) - ($style-mask mod ($CENTER_BIT)) = 0"/>
1678 <variable name="right-requested"
1679 select="($style-mask mod (2 * $RIGHT_BIT)) - ($style-mask mod ($RIGHT_BIT)) = 0"/>
1681 <!-- Extract styles that are not already defined by the context. -->
1682 <variable name="bold-style">
1683 <choose>
1684 <when test="$bold-requested and boolean($text-properties/@fo:font-weight='bold')">
1685 <!-- Bold found in current style. -->
1686 <value-of select="$BOLD_BIT"/>
1687 </when>
1688 <otherwise>
1689 <value-of select="$NO_STYLE"/>
1690 </otherwise>
1691 </choose>
1692 </variable>
1693 <variable name="bold-mask">
1694 <choose>
1695 <when test="$bold-requested and boolean($text-properties/@fo:font-weight)">
1696 <!--
1697 Other value than "bold" means that the character style is not
1698 bold and no parent style must be considered.
1700 <value-of select="$BOLD_BIT"/>
1701 </when>
1702 <otherwise>
1703 <value-of select="$NO_STYLE"/>
1704 </otherwise>
1705 </choose>
1706 </variable>
1708 <variable name="italic-style">
1709 <choose>
1710 <when test="$italic-requested and boolean($text-properties/@fo:font-style='italic')">
1711 <!-- Italic found in current style. -->
1712 <value-of select="$ITALIC_BIT"/>
1713 </when>
1714 <otherwise>
1715 <value-of select="$NO_STYLE"/>
1716 </otherwise>
1717 </choose>
1718 </variable>
1719 <variable name="italic-mask">
1720 <choose>
1721 <when test="$italic-requested and boolean($text-properties/@fo:font-style)">
1722 <!--
1723 Other value than "italic" means that the character style is not
1724 italic and no parent style must be considered.
1726 <value-of select="$ITALIC_BIT"/>
1727 </when>
1728 <otherwise>
1729 <value-of select="$NO_STYLE"/>
1730 </otherwise>
1731 </choose>
1732 </variable>
1734 <variable name="underline-style">
1735 <choose>
1736 <when test="$underline-requested and boolean($text-properties/@style:text-underline-style='solid')">
1737 <!-- Underline found in current style. -->
1738 <value-of select="$UNDERLINE_BIT"/>
1739 </when>
1740 <otherwise>
1741 <value-of select="$NO_STYLE"/>
1742 </otherwise>
1743 </choose>
1744 </variable>
1745 <variable name="underline-mask">
1746 <choose>
1747 <when test="$underline-requested and boolean($text-properties/@style:text-underline-style='solid')">
1748 <!--
1749 Other value than "underline" means that the character style is not
1750 underline and no parent style must be considered.
1752 <value-of select="$UNDERLINE_BIT"/>
1753 </when>
1754 <otherwise>
1755 <value-of select="$NO_STYLE"/>
1756 </otherwise>
1757 </choose>
1758 </variable>
1760 <variable name="superscript-style">
1761 <choose>
1762 <when test="$superscript-requested and contains($text-properties/@style:text-position, 'super')">
1763 <value-of select="$SUPERSCRIPT_BIT"/>
1764 </when>
1765 <otherwise>
1766 <value-of select="$NO_STYLE"/>
1767 </otherwise>
1768 </choose>
1769 </variable>
1770 <variable name="superscript-mask">
1771 <choose>
1772 <when test="$superscript-requested and boolean($text-properties/@style:text-position)">
1773 <value-of select="$SUPERSCRIPT_BIT"/>
1774 </when>
1775 <otherwise>
1776 <value-of select="$NO_STYLE"/>
1777 </otherwise>
1778 </choose>
1779 </variable>
1781 <variable name="subscript-style">
1782 <choose>
1783 <when test="$subscript-requested and contains($text-properties/@style:text-position, 'sub')">
1784 <value-of select="$SUBSCRIPT_BIT"/>
1785 </when>
1786 <otherwise>
1787 <value-of select="$NO_STYLE"/>
1788 </otherwise>
1789 </choose>
1790 </variable>
1791 <variable name="subscript-mask">
1792 <choose>
1793 <when test="$subscript-requested and boolean($text-properties/@style:text-position)">
1794 <value-of select="$SUBSCRIPT_BIT"/>
1795 </when>
1796 <otherwise>
1797 <value-of select="$NO_STYLE"/>
1798 </otherwise>
1799 </choose>
1800 </variable>
1802 <variable name="typewriter-style">
1803 <choose>
1804 <when test="$typewriter-requested and ($style/@style:family='text') and boolean($text-properties/@style:font-name)">
1805 <variable name="font-face"
1806 select="key('font-face-ref', $text-properties/@style:font-name)"/>
1807 <choose>
1808 <when test="$font-face/@style:font-pitch='fixed'">
1809 <value-of select="$TYPEWRITER_BIT"/>
1810 </when>
1811 <otherwise>
1812 <value-of select="$NO_STYLE"/>
1813 </otherwise>
1814 </choose>
1815 </when>
1816 <otherwise>
1817 <value-of select="$NO_STYLE"/>
1818 </otherwise>
1819 </choose>
1820 </variable>
1821 <variable name="typewriter-mask">
1822 <choose>
1823 <!-- Note: Suppress the typewriter style on text within a code paragraph. -->
1824 <when test="$typewriter-requested and boolean($text-properties/@style:font-name)">
1825 <value-of select="$TYPEWRITER_BIT"/>
1826 </when>
1827 <otherwise>
1828 <value-of select="$NO_STYLE"/>
1829 </otherwise>
1830 </choose>
1831 </variable>
1833 <variable name="code-style">
1834 <choose>
1835 <when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
1836 <variable name="font-face"
1837 select="key('font-face-ref', $text-properties/@style:font-name)"/>
1838 <choose>
1839 <when test="$font-face/@style:font-pitch='fixed' or (boolean(@style:display-name) and contains($CODE_STYLES, $style/@style:display-name))">
1840 <value-of select="$CODE_BIT"/>
1841 </when>
1842 <otherwise>
1843 <value-of select="$NO_STYLE"/>
1844 </otherwise>
1845 </choose>
1846 </when>
1847 <otherwise>
1848 <value-of select="$NO_STYLE"/>
1849 </otherwise>
1850 </choose>
1851 </variable>
1852 <variable name="code-mask">
1853 <choose>
1854 <when test="$code-requested and ($style/@style:family='paragraph') and boolean($text-properties/@style:font-name)">
1855 <value-of select="$CODE_BIT"/>
1856 </when>
1857 <otherwise>
1858 <value-of select="$NO_STYLE"/>
1859 </otherwise>
1860 </choose>
1861 </variable>
1863 <variable name="center-style">
1864 <choose>
1865 <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align='center')">
1866 <value-of select="$CENTER_BIT"/>
1867 </when>
1868 <otherwise>
1869 <value-of select="$NO_STYLE"/>
1870 </otherwise>
1871 </choose>
1872 </variable>
1873 <variable name="center-mask">
1874 <choose>
1875 <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align)">
1876 <value-of select="$CENTER_BIT"/>
1877 </when>
1878 <otherwise>
1879 <value-of select="$NO_STYLE"/>
1880 </otherwise>
1881 </choose>
1882 </variable>
1884 <variable name="right-style">
1885 <choose>
1886 <when test="$right-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align='end')">
1887 <value-of select="$RIGHT_BIT"/>
1888 </when>
1889 <otherwise>
1890 <value-of select="$NO_STYLE"/>
1891 </otherwise>
1892 </choose>
1893 </variable>
1894 <variable name="right-mask">
1895 <choose>
1896 <when test="$center-requested and ($style/@style:family='paragraph') and boolean($style/style:paragraph-properties/@fo:text-align)">
1897 <value-of select="$RIGHT_BIT"/>
1898 </when>
1899 <otherwise>
1900 <value-of select="$NO_STYLE"/>
1901 </otherwise>
1902 </choose>
1903 </variable>
1906 <!-- Compute the updated styles and mask. -->
1907 <!--
1908 Note: The bit masks style-mask, bold-style, italic-style,... are
1909 guaranteed to be disjoint, therefore, addition can be use instead
1910 of bitwise or (which is missing in XPath). -->
1911 <variable name="updated-style"
1912 select="$style-set + $bold-style + $italic-style + $underline-style + $superscript-style + $subscript-style + $code-style + $typewriter-style + $center-style + $right-style"/>
1913 <variable name="updated-mask"
1914 select="$style-mask + $bold-mask + $italic-mask + $underline-mask + $superscript-mask + $subscript-mask + $code-mask + $typewriter-mask + $center-mask + $right-mask"/>
1916 <!-- Inspect linked and nested styles. -->
1917 <choose>
1918 <when test="boolean($style/@style:parent-style-name)">
1919 <!-- Look through the style, the current style is based on. -->
1920 <call-template name="mk-style-set-internal">
1921 <with-param name="node" select="$node"/>
1922 <with-param name="style" select="key('style-ref', $style/@style:parent-style-name)"/>
1923 <with-param name="style-set" select="$updated-style"/>
1924 <with-param name="style-mask" select="$updated-mask"/>
1925 </call-template>
1926 </when>
1927 <otherwise>
1928 <variable name="ancestors" select="$node/ancestor::*[@text:style-name][1]"/>
1930 <!-- Debugging: Print currently inspected style. -->
1931 <!--
1932 <message>
1933 <value-of select="'{'"/>
1934 <value-of select="$style/@style:name"/>
1935 <value-of select="','"/>
1936 <value-of select="$updated-style"/>
1937 <value-of select="','"/>
1938 <value-of select="$updated-mask"/>
1939 <value-of select="','"/>
1940 <value-of select="local-name($ancestors)"/>
1941 <value-of select="',('"/>
1942 <value-of select="$node"/>
1943 <value-of select="')'"/>
1944 <value-of select="'}'"/>
1945 </message>
1948 <!--
1949 If there is an ancestor that has a style, use that style,
1950 otherwise, a style is not found. -->
1951 <choose>
1952 <when test="boolean($ancestors)">
1953 <!-- Look through the style of the nearest ancestor that has a style. -->
1954 <call-template name="mk-style-set-internal">
1955 <with-param name="node" select="$ancestors"/>
1956 <with-param name="style" select="key('style-ref', $ancestors/@text:style-name)"/>
1957 <with-param name="style-set" select="$updated-style"/>
1958 <with-param name="style-mask" select="$updated-mask"/>
1959 </call-template>
1960 </when>
1961 <otherwise>
1962 <!-- No more styles to inspect. Return the result. -->
1963 <value-of select="$updated-style"/>
1964 </otherwise>
1965 </choose>
1966 </otherwise>
1967 </choose>
1968 </template>
1971 <!--
1972 == Descending the tree ==
1975 <template match="/">
1976 <apply-templates/>
1977 <value-of select="$NL"/>
1978 <if test="boolean(//text:note[@text:note-class='footnote'])">
1979 <value-of select="$NL"/>
1980 <text>----</text>
1981 <value-of select="$NL"/>
1982 <text>&lt;references/&gt;</text>
1983 <value-of select="$NL"/>
1984 </if>
1985 </template>
1987 <template match="office:document-content">
1988 <apply-templates/>
1989 </template>
1991 <template match="office:body">
1992 <apply-templates/>
1993 </template>
1995 <template match="text:tracked-changes">
1996 <!-- Ignore change history. -->
1997 </template>
1999 <template match="office:* | text:* | draw:text-box | draw:a">
2000 <apply-templates/>
2001 </template>
2003 <template match="node()">
2004 </template>
2005 </stylesheet>
2007 <!--
2008 Local Variables:
2009 tab-width: 4
2010 sgml-indent-step: 4
2011 End: