home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / odt2mediawiki.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2010-12-01  |  47.5 KB  |  1,568 lines

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