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