home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Bureautique / OpenOffice / Apache_OpenOffice_4.1.1_Win_x86_install_fr.exe / openoffice1.cab / wordml2ooo_text.xsl < prev    next >
Extensible Markup Language  |  2014-02-25  |  63KB  |  1,055 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--***********************************************************
  3.  * 
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  * 
  21.  ***********************************************************-->
  22.  
  23.  
  24. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" exclude-result-prefixes="w wx aml o dt  v">
  25.     <xsl:template name="create-default-paragraph-styles">
  26.         <xsl:variable name="default-paragraph-style" select="w:style[@w:default = 'on' and @w:type = 'paragraph']"/>
  27.         <xsl:if test="$default-paragraph-style">
  28.             <style:default-style style:family="paragraph">
  29.                 <style:paragraph-properties>
  30.                     <xsl:attribute name="style:tab-stop-distance">
  31.                         <xsl:call-template name="ConvertMeasure">
  32.                             <xsl:with-param name="value" select="concat(/w:wordDocument/w:docPr/w:defaultTabStop/@w:val,'twip')"/>
  33.                         </xsl:call-template>cm</xsl:attribute>
  34.                 </style:paragraph-properties>
  35.                 <style:text-properties style:use-window-font-color="true">
  36.                     <xsl:choose>
  37.                         <xsl:when test="/w:wordDocument/w:fonts/w:defaultFonts">
  38.                             <xsl:attribute name="style:font-name">
  39.                                 <xsl:value-of select="/w:wordDocument/w:fonts/w:defaultFonts/@w:ascii"/>
  40.                             </xsl:attribute>
  41.                             <xsl:attribute name="style:font-name-asian">
  42.                                 <xsl:value-of select="/w:wordDocument/w:fonts/w:defaultFonts/@w:fareast"/>
  43.                             </xsl:attribute>
  44.                             <xsl:attribute name="style:font-name-complex">
  45.                                 <xsl:value-of select="/w:wordDocument/w:fonts/w:defaultFonts/@w:cs"/>
  46.                             </xsl:attribute>
  47.                         </xsl:when>
  48.                         <xsl:otherwise>
  49.                             <xsl:attribute name="style:font-name">Times New Roman</xsl:attribute>
  50.                         </xsl:otherwise>
  51.                     </xsl:choose>
  52.                     <xsl:if test="$default-paragraph-style/w:rPr/w:sz">
  53.                         <xsl:attribute name="fo:font-size">
  54.                             <xsl:value-of select="translate($default-paragraph-style/w:rPr/w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  55.                         <xsl:attribute name="style:font-size-asian">
  56.                             <xsl:value-of select="translate($default-paragraph-style/w:rPr/w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  57.                     </xsl:if>
  58.                     <xsl:if test="$default-paragraph-style/w:rPr/w:sz-cs">
  59.                         <xsl:attribute name="style:font-size-complex">
  60.                             <xsl:value-of select="$default-paragraph-style/w:rPr/w:sz-cs/@w:val div 2"/>pt</xsl:attribute>
  61.                     </xsl:if>
  62.                     <!-- if not defined default font size in Word, make it out as 10pt. glu -->
  63.                     <xsl:if test="not($default-paragraph-style/w:rPr/w:sz or w:rPr/w:sz-cs)">
  64.                         <xsl:attribute name="fo:font-size">10pt</xsl:attribute>
  65.                         <xsl:attribute name="style:font-size-asian">10pt</xsl:attribute>
  66.                         <xsl:attribute name="style:font-size-complex">10pt</xsl:attribute>
  67.                     </xsl:if>
  68.                     <xsl:if test="$default-paragraph-style/w:rPr/w:lang">
  69.                         <xsl:if test="$default-paragraph-style/w:rPr/w:lang/@w:val">
  70.                             <xsl:attribute name="fo:language">
  71.                                 <xsl:choose>
  72.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:val, '-')">
  73.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/>
  74.                                     </xsl:when>
  75.                                     <xsl:otherwise>
  76.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:val"/>
  77.                                     </xsl:otherwise>
  78.                                 </xsl:choose>
  79.                                 <!--xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/ -->
  80.                             </xsl:attribute>
  81.                             <xsl:attribute name="fo:country">
  82.                                 <xsl:choose>
  83.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:val, '-')">
  84.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/>
  85.                                     </xsl:when>
  86.                                     <xsl:otherwise>
  87.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:val"/>
  88.                                     </xsl:otherwise>
  89.                                 </xsl:choose>
  90.                                 <!--xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/-->
  91.                             </xsl:attribute>
  92.                         </xsl:if>
  93.                         <xsl:if test="$default-paragraph-style/w:rPr/w:lang/@w:fareast">
  94.                             <xsl:attribute name="style:language-asian">
  95.                                 <xsl:choose>
  96.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')">
  97.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/>
  98.                                     </xsl:when>
  99.                                     <xsl:otherwise>
  100.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:fareast"/>
  101.                                     </xsl:otherwise>
  102.                                 </xsl:choose>
  103.                                 <!--xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/-->
  104.                             </xsl:attribute>
  105.                             <xsl:attribute name="style:country-asian">
  106.                                 <xsl:choose>
  107.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')">
  108.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/>
  109.                                     </xsl:when>
  110.                                     <xsl:otherwise>
  111.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:fareast"/>
  112.                                     </xsl:otherwise>
  113.                                 </xsl:choose>
  114.                                 <!--xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/ -->
  115.                             </xsl:attribute>
  116.                         </xsl:if>
  117.                         <xsl:if test="$default-paragraph-style/w:rPr/w:lang/@w:bidi">
  118.                             <xsl:attribute name="style:language-complex">
  119.                                 <xsl:choose>
  120.                                     <xsl:when test="contains( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-') ">
  121.                                         <xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/>
  122.                                     </xsl:when>
  123.                                     <xsl:otherwise>
  124.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:bidi "/>
  125.                                     </xsl:otherwise>
  126.                                 </xsl:choose>
  127.                                 <!--xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/-->
  128.                             </xsl:attribute>
  129.                             <xsl:attribute name="style:country-complex">
  130.                                 <xsl:choose>
  131.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')">
  132.                                         <xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/>
  133.                                     </xsl:when>
  134.                                     <xsl:otherwise>
  135.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:bidi"/>
  136.                                     </xsl:otherwise>
  137.                                 </xsl:choose>
  138.                                 <!-- xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/ -->
  139.                             </xsl:attribute>
  140.                         </xsl:if>
  141.                     </xsl:if>
  142.                 </style:text-properties>
  143.             </style:default-style>
  144.         </xsl:if>
  145.     </xsl:template>
  146.     <xsl:template name="create-default-text-styles">
  147.         <style:style style:name="Footnote_20_Symbol" style:display-name="Footnote Symbol" style:family="text"/>
  148.         <style:style style:name="Numbering_20_Symbols" style:display-name="Numbering Symbols" style:family="text"/>
  149.         <style:style style:name="Bullet_20_Symbols" style:display-name="Bullet Symbols" style:family="text">
  150.             <style:text-properties style:font-name="StarSymbol" fo:font-size="9pt" style:font-name-asian="StarSymbol" style:font-size-asian="9pt" style:font-name-complex="StarSymbol" style:font-size-complex="9pt"/>
  151.         </style:style>
  152.         <style:style style:name="Endnote_20_Symbol" style:display-name="Endnote Symbol" style:family="text"/>
  153.         <style:style style:name="Footnote_20_anchor" style:display-name="Footnote anchor" style:family="text">
  154.             <style:text-properties style:text-position="super 58%"/>
  155.         </style:style>
  156.     </xsl:template>
  157.     <xsl:template match="w:p" mode="style">
  158.         <xsl:variable name="paragraph-number">
  159.             <xsl:number from="/w:wordDocument/w:body" level="any" count="w:p" format="1"/>
  160.         </xsl:variable>
  161.         <xsl:variable name="section-property-number" select="count(preceding::w:sectPr)"/>
  162.         <xsl:variable name="last-section-property" select="preceding::w:pPr/w:sectPr[1]"/>
  163.         <xsl:variable name="next-section-property" select="following::w:sectPr[1]"/>
  164.         <style:style style:family="paragraph" style:name="P{$paragraph-number}">
  165.             <xsl:choose>
  166.               <xsl:when test="w:pPr/w:pStyle">
  167.                 <xsl:attribute name="style:parent-style-name">
  168.                   <xsl:value-of select="concat('w',translate(w:pPr/w:pStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))" />
  169.                 </xsl:attribute>
  170.               </xsl:when>
  171.             <xsl:otherwise>
  172.               <xsl:attribute name="style:parent-style-name">wNormal</xsl:attribute>
  173.             </xsl:otherwise>
  174.             </xsl:choose>
  175.             <xsl:choose>
  176.                 <xsl:when test="not($next-section-property/w:type/@w:val = 'continuous') and  generate-id($last-section-property[last()]/following::w:p[1]) = generate-id(.) and not(ancestor::w:sectPr or ancestor::w:tbl)">
  177.                     <xsl:attribute name="style:master-page-name">Standard-1<xsl:value-of select="$section-property-number + 1"/>
  178.                     </xsl:attribute>
  179.                 </xsl:when>
  180.                 <xsl:when test="$paragraph-number = 1">
  181.                     <xsl:attribute name="style:master-page-name">First_20_Page</xsl:attribute>
  182.                 </xsl:when>
  183.             </xsl:choose>
  184.             <style:paragraph-properties>
  185.                 <xsl:apply-templates select="w:pPr"/>
  186.             </style:paragraph-properties>
  187.             <style:text-properties>
  188.                 <xsl:apply-templates select="w:pPr/w:rPr"/>
  189.                 <xsl:apply-templates select="w:rPr"/>
  190.             </style:text-properties>
  191.         </style:style>
  192.         <xsl:if test="w:r/w:br/@w:type='page'">
  193.             <style:style style:family="paragraph" style:name="P{$paragraph-number}page-break">
  194.                 <xsl:if test="w:pPr/w:pStyle">
  195.                     <xsl:attribute name="style:parent-style-name">
  196.                         <xsl:value-of select="concat('w',translate(w:pPr/w:pStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  197.                     </xsl:attribute>
  198.                 </xsl:if>
  199.                 <xsl:choose>
  200.                     <xsl:when test="generate-id($last-section-property[last()]/following::w:p[1]) = generate-id(.) and not(ancestor::w:sectPr or ancestor::w:tbl)">
  201.                         <xsl:attribute name="style:master-page-name">Standard-1<xsl:value-of select="$section-property-number + 1"/>
  202.                         </xsl:attribute>
  203.                     </xsl:when>
  204.                     <xsl:when test="$paragraph-number = 1">
  205.                         <xsl:attribute name="style:master-page-name">First_20_Page</xsl:attribute>
  206.                     </xsl:when>
  207.                 </xsl:choose>
  208.                 <style:paragraph-properties fo:break-before="page">
  209.                     <xsl:apply-templates select="w:pPr"/>
  210.                 </style:paragraph-properties>
  211.             </style:style>
  212.         </xsl:if>
  213.         <xsl:if test="w:r/w:br/@w:type='column'">
  214.             <style:style style:family="paragraph" style:name="P{$paragraph-number}column-break">
  215.                 <xsl:if test="w:pPr/w:pStyle">
  216.                     <xsl:attribute name="style:parent-style-name">
  217.                         <xsl:value-of select="concat('w',translate(w:pPr/w:pStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  218.                     </xsl:attribute>
  219.                 </xsl:if>
  220.                 <xsl:choose>
  221.                     <xsl:when test="generate-id($last-section-property[last()]/following::w:p[1]) = generate-id(.) and not(ancestor::w:sectPr or ancestor::w:tbl)">
  222.                         <xsl:attribute name="style:master-page-name">Standard-1<xsl:value-of select="$section-property-number + 1"/>
  223.                         </xsl:attribute>
  224.                     </xsl:when>
  225.                     <xsl:when test="$paragraph-number = 1">
  226.                         <xsl:attribute name="style:master-page-name">First_20_Page</xsl:attribute>
  227.                     </xsl:when>
  228.                 </xsl:choose>
  229.                 <style:paragraph-properties fo:break-before="column">
  230.                     <xsl:apply-templates select="w:pPr"/>
  231.                 </style:paragraph-properties>
  232.             </style:style>
  233.         </xsl:if>
  234.     </xsl:template>
  235.     <xsl:template match="w:pPr">
  236.         <xsl:if test="w:ind/@w:left">
  237.             <xsl:attribute name="fo:margin-left">
  238.                 <xsl:call-template name="ConvertMeasure">
  239.                     <xsl:with-param name="value" select="concat(w:ind/@w:left, 'twip')"/>
  240.                 </xsl:call-template>cm</xsl:attribute>
  241.         </xsl:if>
  242.         <xsl:if test="w:ind/@w:right">
  243.             <xsl:attribute name="fo:margin-right">
  244.                 <xsl:call-template name="ConvertMeasure">
  245.                     <xsl:with-param name="value" select="concat(w:ind/@w:right, 'twip')"/>
  246.                 </xsl:call-template>cm</xsl:attribute>
  247.         </xsl:if>
  248.         <xsl:if test="w:ind/@w:first-line">
  249.             <xsl:attribute name="fo:text-indent">
  250.                 <xsl:call-template name="ConvertMeasure">
  251.                     <xsl:with-param name="value" select="concat(w:ind/@w:first-line, 'twip')"/>
  252.                 </xsl:call-template>cm</xsl:attribute>
  253.         </xsl:if>
  254.         <xsl:if test="w:ind/@w:hanging">
  255.             <xsl:attribute name="fo:text-indent">
  256.                 <xsl:call-template name="ConvertMeasure">
  257.                     <xsl:with-param name="value" select="concat('-',w:ind/@w:hanging, 'twip')"/>
  258.                 </xsl:call-template>cm</xsl:attribute>
  259.         </xsl:if>
  260.         <!-- bi-directional support-->
  261.         <xsl:if test="w:bidi">
  262.             <xsl:choose>
  263.                 <xsl:when test="w:bidi/@w:val = 'off'">
  264.                     <xsl:attribute name="fo:text-align">start</xsl:attribute>
  265.                 </xsl:when>
  266.                 <xsl:otherwise>
  267.                     <xsl:attribute name="style:writing-mode">rl-tb</xsl:attribute>
  268.                     <xsl:attribute name="fo:text-align">end</xsl:attribute>
  269.                 </xsl:otherwise>
  270.             </xsl:choose>
  271.         </xsl:if>
  272.         <xsl:if test="w:jc">
  273.             <xsl:choose>
  274.                 <xsl:when test="w:jc/@w:val = 'center'">
  275.                     <xsl:attribute name="fo:text-align">center</xsl:attribute>
  276.                 </xsl:when>
  277.                 <xsl:when test="w:jc/@w:val = 'left'">
  278.                     <xsl:choose>
  279.                         <xsl:when test="w:bidi and not(w:bidi/@w:val = 'off')">
  280.                             <xsl:attribute name="fo:text-align">end</xsl:attribute>
  281.                         </xsl:when>
  282.                         <xsl:otherwise>
  283.                             <xsl:attribute name="fo:text-align">start</xsl:attribute>
  284.                         </xsl:otherwise>
  285.                     </xsl:choose>
  286.                 </xsl:when>
  287.                 <xsl:when test="w:jc/@w:val = 'right'">
  288.                     <xsl:choose>
  289.                         <xsl:when test="w:bidi and not(w:bidi/@w:val = 'off')">
  290.                             <xsl:attribute name="fo:text-align">start</xsl:attribute>
  291.                         </xsl:when>
  292.                         <xsl:otherwise>
  293.                             <xsl:attribute name="fo:text-align">end</xsl:attribute>
  294.                         </xsl:otherwise>
  295.                     </xsl:choose>
  296.                 </xsl:when>
  297.                 <xsl:otherwise>
  298.                     <xsl:attribute name="fo:text-align">justify</xsl:attribute>
  299.                     <xsl:attribute name="style:justify-single-word">false</xsl:attribute>
  300.                 </xsl:otherwise>
  301.             </xsl:choose>
  302.         </xsl:if>
  303.         <xsl:if test="w:spacing">
  304.             <xsl:choose>
  305.                 <xsl:when test="w:spacing/@w:line-rule = 'at-least'">
  306.                     <xsl:attribute name="style:line-height-at-least">
  307.                         <xsl:call-template name="ConvertMeasure">
  308.                             <xsl:with-param name="value" select="concat(w:spacing/@w:line, 'twip')"/>
  309.                         </xsl:call-template>cm</xsl:attribute>
  310.                 </xsl:when>
  311.                 <xsl:when test="w:spacing/@w:line-rule = 'auto'">
  312.                     <xsl:attribute name="fo:line-height">
  313.                         <xsl:value-of select="round(w:spacing/@w:line div 240 * 100)"/>%</xsl:attribute>
  314.                 </xsl:when>
  315.                 <xsl:when test="w:spacing/@w:line-rule = 'exact'">
  316.                     <xsl:attribute name="fo:line-height">
  317.                         <xsl:call-template name="ConvertMeasure">
  318.                             <xsl:with-param name="value" select="concat(w:spacing/@w:line, 'twip')"/>
  319.                         </xsl:call-template>cm</xsl:attribute>
  320.                 </xsl:when>
  321.             </xsl:choose>
  322.             <xsl:if test="w:spacing/@w:before">
  323.                 <xsl:attribute name="fo:margin-top">
  324.                     <xsl:call-template name="ConvertMeasure">
  325.                         <xsl:with-param name="value" select="concat(w:spacing/@w:before, 'twip')"/>
  326.                     </xsl:call-template>cm</xsl:attribute>
  327.             </xsl:if>
  328.             <xsl:if test="w:spacing/@w:after">
  329.                 <xsl:attribute name="fo:margin-bottom">
  330.                     <xsl:call-template name="ConvertMeasure">
  331.                         <xsl:with-param name="value" select="concat(w:spacing/@w:after, 'twip')"/>
  332.                     </xsl:call-template>cm</xsl:attribute>
  333.             </xsl:if>
  334.         </xsl:if>
  335.         <xsl:if test="w:shd">
  336.             <xsl:variable name="background-color">
  337.                 <xsl:choose>
  338.                     <xsl:when test="string-length(w:shd/@w:fill) = 6">
  339.                         <xsl:value-of select="concat('#', w:shd/@w:fill)"/>
  340.                     </xsl:when>
  341.                     <xsl:otherwise>#000000</xsl:otherwise>
  342.                 </xsl:choose>
  343.             </xsl:variable>
  344.             <xsl:choose>
  345.                 <xsl:when test="w:shd/@w:val = 'solid'">
  346.                     <xsl:attribute name="fo:background-color">
  347.                         <xsl:value-of select="$background-color"/>
  348.                     </xsl:attribute>
  349.                 </xsl:when>
  350.                 <!-- patterns are necessary in the future. glu -->
  351.                 <xsl:otherwise/>
  352.             </xsl:choose>
  353.         </xsl:if>
  354.         <xsl:if test="w:pageBreakBefore and not(w:pageBreakBefore/@w:val = 'off')">
  355.             <xsl:attribute name="fo:break-before">page</xsl:attribute>
  356.         </xsl:if>
  357.         <xsl:if test="w:pageBreakBefore and w:pageBreakBefore/@w:val = 'off'">
  358.             <xsl:attribute name="fo:break-before">auto</xsl:attribute>
  359.         </xsl:if>
  360.         <xsl:if test="w:keepNext">
  361.             <xsl:attribute name="fo:keep-with-next">always</xsl:attribute>
  362.         </xsl:if>
  363.         <!--
  364.         <xsl:if test="w:keepLines">
  365.             <xsl:attribute name="style:break-inside">avoid</xsl:attribute>
  366.         </xsl:if>
  367.         -->
  368.         <xsl:if test="w:widowControl='on'">
  369.             <xsl:attribute name="fo:widows">2</xsl:attribute>
  370.             <xsl:attribute name="fo:orphans">2</xsl:attribute>
  371.         </xsl:if>
  372.         <!--
  373.         <xsl:if test="w:suppressAutoHyphens">
  374.             <xsl:attribute name="fo:hyphenate">false</xsl:attribute>
  375.         </xsl:if>
  376.         -->
  377.         <xsl:if test="w:kinsoku/@w:val='off'">
  378.             <xsl:attribute name="style:line-break">normal</xsl:attribute>
  379.         </xsl:if>
  380.         <xsl:if test="w:overflowPunct/@w:val='off'">
  381.             <xsl:attribute name="style:punctuation-wrap">simple</xsl:attribute>
  382.         </xsl:if>
  383.         <xsl:if test="w:autoSpaceDE/@w:val='off' or w:autoSpaceDN/@w:val='off'">
  384.             <xsl:attribute name="style:text-autospace">none</xsl:attribute>
  385.         </xsl:if>
  386.         <xsl:if test="w:textAlignment">
  387.             <xsl:choose>
  388.                 <xsl:when test="w:textAlignment/@w:val='center'">
  389.                     <xsl:attribute name="style:vertical-align">middle</xsl:attribute>
  390.                 </xsl:when>
  391.                 <xsl:when test="w:textAlignment/@w:val='baseline'">
  392.                     <xsl:attribute name="style:vertical-align">bottom</xsl:attribute>
  393.                 </xsl:when>
  394.                 <xsl:otherwise>
  395.                     <xsl:attribute name="style:vertical-align">
  396.                         <xsl:value-of select="w:textAlignment/@w:val"/>
  397.                     </xsl:attribute>
  398.                 </xsl:otherwise>
  399.             </xsl:choose>
  400.         </xsl:if>
  401.         <xsl:if test="w:pBdr">
  402.             <xsl:if test="w:pBdr/w:top">
  403.                 <xsl:call-template name="get-table-border">
  404.                     <xsl:with-param name="style-pos" select="'top'"/>
  405.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:top"/>
  406.                 </xsl:call-template>
  407.                 <xsl:attribute name="fo:padding-top">
  408.                     <xsl:call-template name="ConvertMeasure">
  409.                         <xsl:with-param name="value" select="concat(w:pBdr/w:top/@w:space,'pt')"/>
  410.                     </xsl:call-template>cm</xsl:attribute>
  411.             </xsl:if>
  412.             <xsl:if test="w:pBdr/w:left">
  413.                 <xsl:call-template name="get-table-border">
  414.                     <xsl:with-param name="style-pos" select="'left'"/>
  415.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:left"/>
  416.                 </xsl:call-template>
  417.                 <xsl:attribute name="fo:padding-left">
  418.                     <xsl:call-template name="ConvertMeasure">
  419.                         <xsl:with-param name="value" select="concat(w:pBdr/w:left/@w:space,'pt')"/>
  420.                     </xsl:call-template>cm</xsl:attribute>
  421.             </xsl:if>
  422.             <xsl:if test="w:pBdr/w:right">
  423.                 <xsl:call-template name="get-table-border">
  424.                     <xsl:with-param name="style-pos" select="'right'"/>
  425.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:right"/>
  426.                 </xsl:call-template>
  427.                 <xsl:attribute name="fo:padding-right">
  428.                     <xsl:call-template name="ConvertMeasure">
  429.                         <xsl:with-param name="value" select="concat(w:pBdr/w:right/@w:space,'pt')"/>
  430.                     </xsl:call-template>cm</xsl:attribute>
  431.             </xsl:if>
  432.             <xsl:if test="w:pBdr/w:bottom">
  433.                 <xsl:call-template name="get-table-border">
  434.                     <xsl:with-param name="style-pos" select="'bottom'"/>
  435.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:bottom"/>
  436.                 </xsl:call-template>
  437.                 <xsl:attribute name="fo:padding-bottom">
  438.                     <xsl:call-template name="ConvertMeasure">
  439.                         <xsl:with-param name="value" select="concat(w:pBdr/w:bottom/@w:space,'pt')"/>
  440.                     </xsl:call-template>cm</xsl:attribute>
  441.             </xsl:if>
  442.             <xsl:if test="w:pBdr/*/@w:shadow='on'">
  443.                 <xsl:attribute name="style:shadow">#000000 0.15cm 0.15cm</xsl:attribute>
  444.             </xsl:if>
  445.         </xsl:if>
  446.         <xsl:if test="w:snapToGrid/@w:val='off'">
  447.             <xsl:attribute name="style:snap-to-layout-grid">false</xsl:attribute>
  448.         </xsl:if>
  449.         <xsl:if test="w:tabs">
  450.             <xsl:element name="style:tab-stops">
  451.                 <xsl:for-each select="w:tabs/w:tab">
  452.                     <xsl:element name="style:tab-stop">
  453.                         <xsl:attribute name="style:position">
  454.                             <xsl:if test="@w:pos < 0">
  455.                                 <xsl:message>
  456.                                     We meet a negative w:pos:<xsl:value-of select="@w:pos"/>.
  457.                                 </xsl:message>
  458.                                 <xsl:value-of select="'0cm'"/>
  459.                             </xsl:if>
  460.                             <xsl:if test="not(@w:pos < 0)">
  461.                                 <xsl:call-template name="ConvertMeasure">
  462.                                     <xsl:with-param name="value" select="concat(@w:pos, 'twip')"/>
  463.                                 </xsl:call-template>cm</xsl:if>
  464.                         </xsl:attribute>
  465.                         <xsl:choose>
  466.                             <xsl:when test="@w:val = 'decimal'">
  467.                                 <xsl:attribute name="style:type">char</xsl:attribute>
  468.                                 <xsl:attribute name="style:char">
  469.                                     <xsl:value-of select="' '"/>
  470.                                 </xsl:attribute>
  471.                             </xsl:when>
  472.                             <xsl:when test="@w:val = 'left' or @w:val = 'right' or @w:val = 'center' ">
  473.                                 <xsl:attribute name="style:type">
  474.                                     <xsl:value-of select="@w:val"/>
  475.                                 </xsl:attribute>
  476.                             </xsl:when>
  477.                             <xsl:otherwise>
  478.                                 <xsl:attribute name="style:type">char</xsl:attribute>
  479.                                 <xsl:attribute name="style:char">
  480.                                     <xsl:value-of select="' '"/>
  481.                                 </xsl:attribute>
  482.                             </xsl:otherwise>
  483.                         </xsl:choose>
  484.                         <!-- Detect leader chars in tabs (rp) -->
  485.                         <xsl:choose>
  486.                             <xsl:when test="@w:leader = 'hyphen'">
  487.                                 <xsl:attribute name="style:leader-style">solid</xsl:attribute>
  488.                                 <xsl:attribute name="style:leader-text">-</xsl:attribute>
  489.                             </xsl:when>
  490.                             <xsl:when test="@w:leader = 'underscore'">
  491.                                 <xsl:attribute name="style:leader-style">solid</xsl:attribute>
  492.                                 <xsl:attribute name="style:leader-text">_</xsl:attribute>
  493.                             </xsl:when>
  494.                             <xsl:when test="@w:leader = 'dot'">
  495.                                 <xsl:attribute name="style:leader-style">dotted</xsl:attribute>
  496.                                 <xsl:attribute name="style:leader-text">.</xsl:attribute>
  497.                             </xsl:when>
  498.                         </xsl:choose>
  499.                         <!-- end leader chars (rp) -->
  500.                     </xsl:element>
  501.                 </xsl:for-each>
  502.             </xsl:element>
  503.         </xsl:if>
  504.         <xsl:apply-templates select="w:rPr" mode="paragraph-properties"/>
  505.     </xsl:template>
  506.     <xsl:template match="w:rPr" mode="style">
  507.         <xsl:element name="style:style">
  508.             <xsl:attribute name="style:name">T<xsl:number from="/w:wordDocument/w:body" level="any" count="w:rPr" format="1"/>
  509.             </xsl:attribute>
  510.             <xsl:attribute name="style:family">text</xsl:attribute>
  511.             <xsl:if test="w:rStyle">
  512.                 <xsl:attribute name="style:parent-style-name">
  513.                     <xsl:value-of select="concat('w',translate(w:rStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  514.                 </xsl:attribute>
  515.             </xsl:if>
  516.             <xsl:element name="style:text-properties">
  517.  
  518.                 <xsl:apply-templates select="current()"/>
  519. <!--        <xsl:call-template name="text-properties"/> -->
  520.             </xsl:element>
  521.         </xsl:element>
  522.     </xsl:template>
  523.     <xsl:template match="w:rPr">
  524.         <xsl:if test="w:rFonts">
  525.             <xsl:if test="w:rFonts/@w:ascii">
  526.                 <xsl:attribute name="style:font-name">
  527.                     <xsl:value-of select="w:rFonts/@w:ascii"/>
  528.                 </xsl:attribute>
  529.                 <xsl:if test="ancestor::w:body">
  530.                     <xsl:attribute name="style:font-name-asian">
  531.                         <xsl:value-of select="w:rFonts/@w:ascii"/>
  532.                     </xsl:attribute>
  533.                     <xsl:attribute name="style:font-name-complex">
  534.                         <xsl:value-of select="w:rFonts/@w:ascii"/>
  535.                     </xsl:attribute>
  536.                 </xsl:if>
  537.             </xsl:if>
  538.             <xsl:if test="ancestor::w:styles">
  539.                 <xsl:if test="w:rFonts/@w:fareast">
  540.                     <xsl:attribute name="style:font-name-asian">
  541.                         <xsl:value-of select="w:rFonts/@w:fareast"/>
  542.                     </xsl:attribute>
  543.                 </xsl:if>
  544.                 <xsl:if test="w:rFonts/@w:cs">
  545.                     <xsl:attribute name="style:font-name-complex">
  546.                         <xsl:value-of select="w:rFonts/@w:cs"/>
  547.                     </xsl:attribute>
  548.                 </xsl:if>
  549.             </xsl:if>
  550.         </xsl:if>
  551.         <xsl:if test="parent::w:r">
  552.             <xsl:if test="w:b">
  553.                 <xsl:attribute name="fo:font-weight">bold</xsl:attribute>
  554.                 <xsl:attribute name="style:font-weight-asian">bold</xsl:attribute>
  555.             </xsl:if>
  556.             <xsl:if test="w:b-cs">
  557.                 <xsl:attribute name="style:font-weight-complex">bold</xsl:attribute>
  558.             </xsl:if>
  559.             <xsl:if test="w:i">
  560.                 <xsl:attribute name="fo:font-style">italic</xsl:attribute>
  561.                 <xsl:attribute name="style:font-style-asian">italic</xsl:attribute>
  562.             </xsl:if>
  563.             <xsl:if test="w:i-cs">
  564.                 <xsl:attribute name="style:font-style-complex">italic</xsl:attribute>
  565.             </xsl:if>
  566.         </xsl:if>
  567.         <xsl:if test="w:caps">
  568.             <xsl:attribute name="fo:text-transform">uppercase</xsl:attribute>
  569.         </xsl:if>
  570.         <xsl:if test="w:smallCaps">
  571.             <xsl:attribute name="fo:font-variant">small-caps</xsl:attribute>
  572.         </xsl:if>
  573.         <xsl:if test="w:strike">
  574.             <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  575.         </xsl:if>
  576.         <xsl:if test="w:dstrike">
  577.             <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  578.             <xsl:attribute name="style:text-line-through-type">double</xsl:attribute>
  579.         </xsl:if>
  580.         <xsl:if test="w:outline">
  581.             <xsl:attribute name="style:text-outline">true</xsl:attribute>
  582.         </xsl:if>
  583.         <xsl:if test="w:shadow">
  584.             <xsl:attribute name="fo:text-shadow">1pt 1pt</xsl:attribute>
  585.         </xsl:if>
  586.         <xsl:if test="w:imprint">
  587.             <xsl:attribute name="style:font-relief">engraved</xsl:attribute>
  588.         </xsl:if>
  589.         <xsl:if test="w:emboss">
  590.             <xsl:attribute name="style:font-relief">embossed</xsl:attribute>
  591.         </xsl:if>
  592.         <xsl:if test="w:vanish">
  593.             <xsl:attribute name="text:display">true</xsl:attribute>
  594.         </xsl:if>
  595.         <xsl:if test="w:color[not(@w:val = 'auto')]">
  596.             <xsl:attribute name="fo:color">#<xsl:value-of select="w:color/@w:val"/>
  597.             </xsl:attribute>
  598.         </xsl:if>
  599.         <xsl:if test="w:spacing">
  600.             <xsl:attribute name="fo:letter-spacing">
  601.                 <xsl:call-template name="ConvertMeasure">
  602.                     <xsl:with-param name="value" select="concat(w:spacing/@w:val,'twip')"/>
  603.                 </xsl:call-template>cm</xsl:attribute>
  604.         </xsl:if>
  605.         <xsl:if test="w:w/@w:val">
  606.             <xsl:attribute name="style:text-scale">
  607.                 <xsl:value-of select="concat(w:w/@w:val, '%')"/>
  608.             </xsl:attribute>
  609.         </xsl:if>
  610.         <xsl:if test="w:vertAlign or w:position">
  611.             <xsl:variable name="height">
  612.                 <xsl:choose>
  613.                     <xsl:when test="w:vertAlign[@w:val = 'superscript' or @w:val = 'subscript']">58%</xsl:when>
  614.                     <xsl:otherwise>100%</xsl:otherwise>
  615.                 </xsl:choose>
  616.             </xsl:variable>
  617.             <xsl:variable name="position">
  618.                 <xsl:choose>
  619.                     <xsl:when test="w:position">
  620.                         <!-- con't get font height easily, so just set w:val as percentage. glu -->
  621.                         <xsl:value-of select="concat( w:position/@w:val, '%')"/>
  622.                     </xsl:when>
  623.                     <xsl:when test="w:vertAlign[@w:val = 'superscript']">super</xsl:when>
  624.                     <xsl:when test="w:vertAlign[@w:val = 'subscript']">sub</xsl:when>
  625.                 </xsl:choose>
  626.             </xsl:variable>
  627.             <xsl:attribute name="style:text-position">
  628.                 <xsl:value-of select="concat($position, ' ', $height)"/>
  629.             </xsl:attribute>
  630.         </xsl:if>
  631.         <xsl:if test="w:sz">
  632.             <xsl:attribute name="fo:font-size">
  633.                 <xsl:value-of select="translate(w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  634.             <xsl:attribute name="style:font-size-asian">
  635.                 <xsl:value-of select="translate(w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  636.         </xsl:if>
  637.         <xsl:if test="w:sz-cs">
  638.             <xsl:attribute name="style:font-size-complex">
  639.                 <xsl:value-of select="w:sz-cs/@w:val div 2"/>pt</xsl:attribute>
  640.         </xsl:if>
  641.         <xsl:if test="w:highlight">
  642.             <xsl:choose>
  643.                 <xsl:when test="w:highlight/@w:val='black'">
  644.                     <xsl:attribute name="fo:background-color">#000000</xsl:attribute>
  645.                 </xsl:when>
  646.                 <xsl:when test="w:highlight/@w:val='yellow'">
  647.                     <xsl:attribute name="fo:background-color">#ffff00</xsl:attribute>
  648.                 </xsl:when>
  649.                 <xsl:when test="w:highlight/@w:val='green'">
  650.                     <xsl:attribute name="fo:background-color">#00ff00</xsl:attribute>
  651.                 </xsl:when>
  652.                 <xsl:when test="w:highlight/@w:val='cyan'">
  653.                     <xsl:attribute name="fo:background-color">#00ffff</xsl:attribute>
  654.                 </xsl:when>
  655.                 <xsl:when test="w:highlight/@w:val='magenta'">
  656.                     <xsl:attribute name="fo:background-color">#ff00ff</xsl:attribute>
  657.                 </xsl:when>
  658.                 <xsl:when test="w:highlight/@w:val='blue'">
  659.                     <xsl:attribute name="fo:background-color">#0000ff</xsl:attribute>
  660.                 </xsl:when>
  661.                 <xsl:when test="w:highlight/@w:val='red'">
  662.                     <xsl:attribute name="fo:background-color">#ff0000</xsl:attribute>
  663.                 </xsl:when>
  664.                 <xsl:when test="w:highlight/@w:val='dark-blue'">
  665.                     <xsl:attribute name="fo:background-color">#000080</xsl:attribute>
  666.                 </xsl:when>
  667.                 <xsl:when test="w:highlight/@w:val='dark-cyan'">
  668.                     <xsl:attribute name="fo:background-color">#008080</xsl:attribute>
  669.                 </xsl:when>
  670.                 <xsl:when test="w:highlight/@w:val='dark-green'">
  671.                     <xsl:attribute name="fo:background-color">#008000</xsl:attribute>
  672.                 </xsl:when>
  673.                 <xsl:when test="w:highlight/@w:val='dark-magenta'">
  674.                     <xsl:attribute name="fo:background-color">#800080</xsl:attribute>
  675.                 </xsl:when>
  676.                 <xsl:when test="w:highlight/@w:val='dark-red'">
  677.                     <xsl:attribute name="fo:background-color">#800000</xsl:attribute>
  678.                 </xsl:when>
  679.                 <xsl:when test="w:highlight/@w:val='dark-yellow'">
  680.                     <xsl:attribute name="fo:background-color">#808000</xsl:attribute>
  681.                 </xsl:when>
  682.                 <xsl:when test="w:highlight/@w:val='dark-gray'">
  683.                     <xsl:attribute name="fo:background-color">#808080</xsl:attribute>
  684.                 </xsl:when>
  685.                 <xsl:when test="w:highlight/@w:val='light-gray'">
  686.                     <xsl:attribute name="fo:background-color">#c0c0c0</xsl:attribute>
  687.                 </xsl:when>
  688.             </xsl:choose>
  689.         </xsl:if>
  690.         <xsl:if test="w:u">
  691.             <xsl:if test="w:u/@w:val = 'thick' or contains(w:u/@w:val,'-heavy')">
  692.                 <xsl:attribute name="style:text-underline-width">bold</xsl:attribute>
  693.             </xsl:if>
  694.             <xsl:if test="w:u/@w:val = 'double' or contains(w:u/@w:val,'-double')">
  695.                 <xsl:attribute name="style:text-underline-type">double</xsl:attribute>
  696.             </xsl:if>
  697.             <xsl:choose>
  698.                 <xsl:when test="w:u/@w:val = 'words' or w:u/@w:val = 'single' or w:u/@w:val = 'thick' or w:u/@w:val = 'double'">
  699.                     <xsl:attribute name="style:text-underline-style">solid</xsl:attribute>
  700.                 </xsl:when>
  701.                 <xsl:when test="contains(w:u/@w:val , 'dotted')">
  702.                     <xsl:attribute name="style:text-underline-style">dotted</xsl:attribute>
  703.                 </xsl:when>
  704.                 <xsl:when test="w:u/@w:val = 'dashed-heavy' or w:u/@w:val = 'dash'">
  705.                     <xsl:attribute name="style:text-underline-style">dash</xsl:attribute>
  706.                 </xsl:when>
  707.                 <xsl:when test="w:u/@w:val = 'dash-long' or w:u/@w:val = 'dash-long-heavy'">
  708.                     <xsl:attribute name="style:text-underline-style">long-dash</xsl:attribute>
  709.                 </xsl:when>
  710.                 <xsl:when test="w:u/@w:val = 'dash-dot-heavy' or w:u/@w:val = 'dot-dash'">
  711.                     <xsl:attribute name="style:text-underline-style">dot-dash</xsl:attribute>
  712.                 </xsl:when>
  713.                 <xsl:when test="w:u/@w:val = 'dash-dot-dot-heavy' or w:u/@w:val = 'dot-dot-dash'">
  714.                     <xsl:attribute name="style:text-underline-style">dot-dot-dash</xsl:attribute>
  715.                 </xsl:when>
  716.                 <xsl:when test="w:u/@w:val = 'wavy-heavy' or w:u/@w:val = 'wavy-double' or w:u/@w:val = 'wavy'">
  717.                     <xsl:attribute name="style:text-underline-style">wave</xsl:attribute>
  718.                 </xsl:when>
  719.                 <xsl:otherwise>
  720.                     <xsl:if test="string-length(style:text-underline-style) > 0">
  721.                         <xsl:attribute name="style:text-underline-style">
  722.                             <xsl:value-of select="w:u/@w:val"/>
  723.                         </xsl:attribute>
  724.                     </xsl:if>
  725.                 </xsl:otherwise>
  726.             </xsl:choose>
  727.             <xsl:if test="w:u/@w:color and not(w:u/@w:color = 'auto')">
  728.                 <xsl:attribute name="style:text-underline-color">#<xsl:value-of select="w:u/@w:color"/>
  729.                 </xsl:attribute>
  730.             </xsl:if>
  731.         </xsl:if>
  732.         <xsl:if test="w:effect[@w:val = 'blink-background']">
  733.             <xsl:attribute name="style:text-blinking">true</xsl:attribute>
  734.         </xsl:if>
  735.         <xsl:if test="w:shd and not(w:highlight)">
  736.             <xsl:if test="string-length(w:shd/@w:fill) = 6">
  737.                 <xsl:attribute name="fo:background-color">#<xsl:value-of select="w:shd/@w:fill"/>
  738.                 </xsl:attribute>
  739.             </xsl:if>
  740.         </xsl:if>
  741.         <xsl:if test="w:em">
  742.             <xsl:choose>
  743.                 <xsl:when test="w:em/@w:val = 'comma'">
  744.                     <xsl:attribute name="style:text-emphasize">accent below</xsl:attribute>
  745.                 </xsl:when>
  746.                 <xsl:when test="w:em/@w:val = 'under-dot'">
  747.                     <xsl:attribute name="style:text-emphasize">disc below</xsl:attribute>
  748.                 </xsl:when>
  749.                 <xsl:when test="w:em/@w:val = 'dot' or w:em/@w:val = 'circle' ">
  750.                     <xsl:attribute name="style:text-emphasize">
  751.                         <xsl:value-of select=" concat(w:em/@w:val,' below') "/>
  752.                     </xsl:attribute>
  753.                 </xsl:when>
  754.                 <xsl:otherwise>
  755.                     <xsl:attribute name="style:text-emphasize">none</xsl:attribute>
  756.                 </xsl:otherwise>
  757.             </xsl:choose>
  758.         </xsl:if>
  759.         <xsl:if test="w:lang">
  760.             <xsl:if test="w:lang/@w:val">
  761.                 <xsl:attribute name="fo:language">
  762.                     <xsl:choose>
  763.                         <xsl:when test="contains(w:lang/@w:val, '-')">
  764.                             <xsl:value-of select="substring-before( w:lang/@w:val, '-')"/>
  765.                         </xsl:when>
  766.                         <xsl:otherwise>
  767.                             <xsl:value-of select="w:lang/@w:val"/>
  768.                         </xsl:otherwise>
  769.                     </xsl:choose>
  770.                     <!--xsl:value-of select="substring-before( w:lang/@w:val, '-')"/-->
  771.                 </xsl:attribute>
  772.                 <xsl:attribute name="fo:country">
  773.                     <xsl:choose>
  774.                         <xsl:when test="contains(w:lang/@w:val, '-')">
  775.                             <xsl:value-of select="substring-before( w:lang/@w:val, '-')"/>
  776.                         </xsl:when>
  777.                         <xsl:otherwise>
  778.                             <xsl:value-of select="w:lang/@w:val"/>
  779.                         </xsl:otherwise>
  780.                     </xsl:choose>
  781.                     <!--xsl:value-of select="substring-after( w:lang/@w:val, '-')"/-->
  782.                 </xsl:attribute>
  783.             </xsl:if>
  784.         </xsl:if>
  785.     </xsl:template>
  786.     <xsl:template match="w:rPr" mode="paragraph-properties">
  787.         <!--  right-to-left support-->
  788.         <xsl:if test="w:rtl and not(w:rtl/@w:val = 'off')">
  789.             <xsl:attribute name="style:writing-mode">rl-tb</xsl:attribute>
  790.             <xsl:attribute name="fo:text-align">end</xsl:attribute>
  791.         </xsl:if>
  792.     </xsl:template>
  793.     <xsl:template match="w:p">
  794.         <xsl:choose>
  795.             <!-- because word treats page breaks as separate tags, we must split some paragraphs up so that we can
  796.             give the sub para a fo:break-before ="page" or column attribute. -->
  797.             <xsl:when test="w:r[w:br/@w:type='page' or w:br/@w:type='column']">
  798.                 <xsl:call-template name="process-breaks-in-paragraph"/>
  799.             </xsl:when>
  800.             <xsl:otherwise>
  801.                 <xsl:call-template name="process-common-paragraph"/>
  802.             </xsl:otherwise>
  803.         </xsl:choose>
  804.     </xsl:template>
  805.     <xsl:template name="process-breaks-in-paragraph">
  806.         <xsl:variable name="textruns-with-break" select="w:r[w:br/@w:type='page' or w:br/@w:type='column']"/>
  807.         <xsl:call-template name="create-sub-paragraph">
  808.             <xsl:with-param name="textruns" select="$textruns-with-break[1]/preceding-sibling::w:r"/>
  809.         </xsl:call-template>
  810.         <xsl:for-each select="$textruns-with-break">
  811.             <xsl:variable name="break-position" select="position()"/>
  812.             <xsl:call-template name="create-sub-paragraph">
  813.                 <!-- added following-sibling::w:fldSimple | following-sibling::w:hlink | following-sibling::aml:annotation to enable these elements to be processed when there are breaks happen  G.Yang -->
  814.                 <xsl:with-param name="textruns" select="following-sibling::w:r[not(w:br/@w:type='page' or w:br/@w:type='column') and (count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position)] | following-sibling::w:fldSimple[count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position] | following-sibling::w:hlink[count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position] | following-sibling::aml:annotation[count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position] "/>
  815.                 <xsl:with-param name="textruns-with-break" select="current()"/>
  816.             </xsl:call-template>
  817.         </xsl:for-each>
  818.     </xsl:template>
  819.     <xsl:template name="create-sub-paragraph">
  820.         <xsl:param name="textruns"/>
  821.         <xsl:param name="textruns-with-break"/>
  822.         <xsl:if test="$textruns or $textruns-with-break">
  823.             <xsl:variable name="curr-num">
  824.                 <xsl:number from="/w:wordDocument/w:body" level="any" count="w:p" format="1"/>
  825.             </xsl:variable>
  826.             <text:p>
  827.                 <xsl:choose>
  828.                     <xsl:when test="$textruns-with-break">
  829.                         <xsl:attribute name="text:style-name">
  830.                             <xsl:value-of select="concat('P',$curr-num,w:br/@w:type, '-break')"/>
  831.                         </xsl:attribute>
  832.                         <xsl:apply-templates select="$textruns-with-break"/>
  833.                     </xsl:when>
  834.                     <xsl:otherwise>
  835.                         <xsl:attribute name="text:style-name">
  836.                             <xsl:value-of select="concat( 'P', $curr-num)"/>
  837.                         </xsl:attribute>
  838.                     </xsl:otherwise>
  839.                 </xsl:choose>
  840.                 <xsl:if test="$textruns">
  841.                     <xsl:apply-templates select="$textruns"/>
  842.                 </xsl:if>
  843.             </text:p>
  844.         </xsl:if>
  845.     </xsl:template>
  846.     <xsl:template name="process-common-paragraph">
  847.         <xsl:variable name="heading-or-paragraph">
  848.             <xsl:choose>
  849.                 <xsl:when test="key('heading-style', w:pPr/w:pStyle/@w:val)">text:h</xsl:when>
  850.                 <xsl:otherwise>text:p</xsl:otherwise>
  851.             </xsl:choose>
  852.         </xsl:variable>
  853.         <xsl:element name="{$heading-or-paragraph}">
  854.             <xsl:if test="$heading-or-paragraph = 'text:h'">
  855.                 <xsl:attribute name="text:outline-level">
  856.                     <xsl:value-of select="key('heading-style',w:pPr/w:pStyle/@w:val)/w:pPr/w:outlineLvl/@w:val + 1"/>
  857.                 </xsl:attribute>
  858.             </xsl:if>
  859.             <xsl:variable name="curr-num">
  860.                 <xsl:number from="/w:wordDocument/w:body" level="any" count="w:p" format="1"/>
  861.             </xsl:variable>
  862.             <xsl:attribute name="text:style-name">
  863.                 <xsl:value-of select="concat( 'P', $curr-num)"/>
  864.             </xsl:attribute>
  865.             <xsl:variable name="bookmark-and-paragraph" select="preceding::aml:annotation[(@w:type = 'Word.Bookmark.Start' or @w:type = 'Word.Bookmark.End') and not(ancestor::w:p)] | preceding::w:p"/>
  866.             <xsl:if test="count($bookmark-and-paragraph) > 0 and name($bookmark-and-paragraph[last()]) = 'aml:annotation'">
  867.                 <xsl:call-template name="create-bookmark">
  868.                     <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  869.                     <xsl:with-param name="position" select="count($bookmark-and-paragraph)"/>
  870.                 </xsl:call-template>
  871.             </xsl:if>
  872.             <xsl:apply-templates mode="dispatch"/>
  873.             <xsl:if test="not(following::w:p)">
  874.                 <xsl:apply-templates select="following::aml:annotation[(@w:type = 'Word.Bookmark.Start' or @w:type = 'Word.Bookmark.End') and not(ancestor::w:p)]"/>
  875.             </xsl:if>
  876.         </xsl:element>
  877.     </xsl:template>
  878.     <xsl:template name="create-bookmark">
  879.         <xsl:param name="bookmark-and-paragraph"/>
  880.         <xsl:param name="position"/>
  881.         <xsl:choose>
  882.             <xsl:when test="name($bookmark-and-paragraph[$position]) = 'aml:annotation'">
  883.                 <xsl:if test="$position > 0">
  884.                     <xsl:call-template name="create-bookmark">
  885.                         <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  886.                         <xsl:with-param name="position" select="$position - 1"/>
  887.                     </xsl:call-template>
  888.                 </xsl:if>
  889.             </xsl:when>
  890.             <xsl:otherwise>
  891.                 <xsl:call-template name="output-bookmark">
  892.                     <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  893.                     <xsl:with-param name="position" select="$position + 1"/>
  894.                 </xsl:call-template>
  895.             </xsl:otherwise>
  896.         </xsl:choose>
  897.     </xsl:template>
  898.     <xsl:template name="output-bookmark">
  899.         <xsl:param name="bookmark-and-paragraph"/>
  900.         <xsl:param name="position"/>
  901.         <xsl:apply-templates select="$bookmark-and-paragraph[$position]"/>
  902.         <xsl:if test="$position < count($bookmark-and-paragraph)">
  903.             <xsl:call-template name="output-bookmark">
  904.                 <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  905.                 <xsl:with-param name="position" select="$position + 1"/>
  906.             </xsl:call-template>
  907.         </xsl:if>
  908.     </xsl:template>
  909.     <!-- WordML contains multiple w:t within one w:r, so in Star Writer text:span should correspond to w:t glu -->
  910.     <xsl:template match="w:r">
  911.         <xsl:choose>
  912.             <xsl:when test="(preceding-sibling::w:r) or (w:rPr)">
  913.                 <!-- add this condition to prevent from  printing the value of DATE, TIME, PRINTDATE, CREATEDATE, SAVEDATE, PAGE, NUMPAGES etc. fields  in-between w:fldchar begin and w:fldchar end   G.Yang.-->
  914.                 <xsl:if test="not (preceding-sibling::w:r/w:instrText[substring(normalize-space(.),1,4) = 'DATE'  or substring(normalize-space(.),1,4) = 'TIME'  or  substring(normalize-space(.),1,9) = 'PRINTDATE'  or substring(normalize-space(.),1,10) = 'CREATEDATE'  or substring(normalize-space(.),1,8) = 'SAVEDATE' or substring(normalize-space(.),1,4) = 'PAGE' or substring(normalize-space(.),1,8) = 'NUMPAGES'  or substring(normalize-space(.),1,8) = 'NUMWORDS' or substring(normalize-space(.),1,8) = 'NUMCHARS' or substring(normalize-space(.),1,6) = 'REVNUM' or substring(normalize-space(.),1,7) = 'AUTONUM'  or  substring(normalize-space(.),1,10) = 'AUTONUMLGL' or substring(normalize-space(.),1,10) = 'AUTONUMOUT' or substring(normalize-space(.),1,3) = 'SEQ' or substring(normalize-space(.),1,6) = 'AUTHOR' or substring(normalize-space(.),1,5) = 'TITLE'  or substring(normalize-space(.),1,7) = 'SUBJECT'  or substring(normalize-space(.),1,8) = 'KEYWORDS' or substring(normalize-space(.),1,6) = 'FILLIN'  or substring(normalize-space(.),1,11) = 'DOCPROPERTY' or substring(normalize-space(.),1,10) = 'MERGEFIELD' or substring(normalize-space(.),1,8) = 'MERGEREC' or substring(normalize-space(.),1,4) = 'NEXT' or substring( normalize-space(.),1,9) = 'HYPERLINK' or substring( normalize-space(.),1,3) = 'REF' ][1]  and (following-sibling::w:r/w:fldChar[@w:fldCharType='end'] or (  not(preceding-sibling::w:r/w:fldChar[@w:fldCharType='end'] ) and parent::w:p/following-sibling::w:p/w:r/w:fldChar[@w:fldCharType='end'])) )">
  915.                     <text:span>
  916.                         <xsl:choose>
  917.                             <xsl:when test="w:rPr/w:rStyle">
  918.                                 <xsl:attribute name="text:style-name">
  919.                                     <xsl:value-of select="concat('w', translate(w:rPr/w:rStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  920.                                 </xsl:attribute>
  921.                             </xsl:when>
  922.                             <xsl:when test="w:rPr">
  923.                                 <xsl:variable name="position">
  924.                                     <xsl:number from="/w:wordDocument/w:body" level="any" count="w:rPr" format="1"/>
  925.                                 </xsl:variable>
  926.                                 <xsl:attribute name="text:style-name">T<xsl:value-of select="$position + 1"/>
  927.                                 </xsl:attribute>
  928.                             </xsl:when>
  929.                         </xsl:choose>
  930.                         <xsl:apply-templates mode="dispatch"/>
  931.                     </text:span>
  932.                 </xsl:if>
  933.             </xsl:when>
  934.             <xsl:otherwise>
  935.                 <!-- add this condition to prevent from printing the value of DATE, TIME, PRINTDATE, CREATEDATE, SAVEDATE, PAGE, NUMPAGES, etc. fields in-between w:fldchar begin and w:fldchar end  G.Yang.-->
  936.                 <xsl:if test="not( preceding-sibling::w:r/w:instrText[substring(normalize-space(.),1,4) = 'DATE'  or substring(normalize-space(.),1,4) = 'TIME'  or  substring(normalize-space(.),1,9) = 'PRINTDATE'  or substring(normalize-space(.),1,10) = 'CREATEDATE'  or substring(normalize-space(.),1,8) = 'SAVEDATE' or substring(normalize-space(.),1,4) = 'PAGE' or substring(normalize-space(.),1,8) = 'NUMPAGES'  or substring(normalize-space(.),1,8) = 'NUMWORDS' or substring(normalize-space(.),1,8) = 'NUMCHARS' or substring(normalize-space(.),1,6) = 'REVNUM' or substring(normalize-space(.),1,7) = 'AUTONUM'  or  substring(normalize-space(.),1,10) = 'AUTONUMLGL' or substring(normalize-space(.),1,10) = 'AUTONUMOUT' or substring(normalize-space(.),1,3) = 'SEQ' or substring(normalize-space(.),1,6) = 'AUTHOR' or substring(normalize-space(.),1,5) = 'TITLE'  or substring(normalize-space(.),1,7) = 'SUBJECT'  or substring(normalize-space(.),1,8) = 'KEYWORDS' or substring(normalize-space(.),1,6) = 'FILLIN' or substring(normalize-space(.),1,11) = 'DOCPROPERTY' or substring(normalize-space(.),1,10) = 'MERGEFIELD' or substring(normalize-space(.),1,8) = 'MERGEREC' or substring(normalize-space(.),1,4) = 'NEXT' or substring( normalize-space(.),1,9) = 'HYPERLINK' or substring( normalize-space(.),1,3) = 'REF' ][1]  and (following-sibling::w:r/w:fldChar[@w:fldCharType='end'] or (  not(preceding-sibling::w:r/w:fldChar[@w:fldCharType='end'] ) and parent::w:p/following-sibling::w:p/w:r/w:fldChar[@w:fldCharType='end'])) )">
  937.                     <xsl:apply-templates mode="dispatch"/>
  938.                 </xsl:if>
  939.             </xsl:otherwise>
  940.         </xsl:choose>
  941.     </xsl:template>
  942.     <xsl:template match="aml:annotation">
  943.         <xsl:choose>
  944.             <xsl:when test="@w:type = 'Word.Bookmark.Start'">
  945.                 <text:bookmark-start text:name="{@w:name}"/>
  946.             </xsl:when>
  947.             <xsl:when test="@w:type = 'Word.Bookmark.End'">
  948.                 <xsl:variable name="id" select="@aml:id"/>
  949.                 <text:bookmark-end text:name="{preceding::aml:annotation[@aml:id = $id]/@w:name}"/>
  950.             </xsl:when>
  951.             <xsl:when test="@w:type = 'Word.Comment'">
  952.                 <office:annotation office:display="true">
  953.                     <dc:creator>
  954.                         <xsl:value-of select="@aml:author"/>
  955.                     </dc:creator>
  956.                     <dc:date>
  957.                         <xsl:value-of select="substring(@aml:createdate,1,10)"/>
  958.                     </dc:date>
  959.                     <xsl:apply-templates select="aml:content/w:p"/>
  960.                 </office:annotation>
  961.             </xsl:when>
  962.         </xsl:choose>
  963.     </xsl:template>
  964.     <xsl:template match="w:hlink">
  965.         <xsl:element name="text:a">
  966.             <xsl:attribute name="xlink:type">simple</xsl:attribute>
  967.             <xsl:choose>
  968.                 <xsl:when test="@w:dest and @w:bookmark">
  969.                     <xsl:attribute name="xlink:href">
  970.                         <xsl:value-of select="concat( @w:dest, concat('#', @w:bookmark) )"/>
  971.                     </xsl:attribute>
  972.                 </xsl:when>
  973.                 <xsl:when test="@w:dest">
  974.                     <xsl:attribute name="xlink:href">
  975.                         <xsl:value-of select="@w:dest"/>
  976.                     </xsl:attribute>
  977.                 </xsl:when>
  978.                 <xsl:when test="@w:bookmark">
  979.                     <xsl:attribute name="xlink:href">
  980.                         <xsl:value-of select="concat('#', @w:bookmark)"/>
  981.                     </xsl:attribute>
  982.                 </xsl:when>
  983.             </xsl:choose>
  984.             <xsl:if test="@w:target">
  985.                 <xsl:attribute name="office:target-frame-name">
  986.                     <xsl:value-of select="@w:target"/>
  987.                 </xsl:attribute>
  988.             </xsl:if>
  989.             <xsl:apply-templates mode="dispatch"/>
  990.         </xsl:element>
  991.     </xsl:template>
  992.     <xsl:template match="w:t">
  993.         <xsl:choose>
  994.             <xsl:when test="string(.) = ' ' ">
  995.                 <xsl:element name="text:s"/>
  996.             </xsl:when>
  997.             <xsl:when test="contains(.,'  ')">
  998.                 <xsl:call-template name="replace-spaces">
  999.                     <xsl:with-param name="curr-string" select="."/>
  1000.                 </xsl:call-template>
  1001.             </xsl:when>
  1002.             <xsl:otherwise>
  1003.                 <xsl:value-of select="."/>
  1004.             </xsl:otherwise>
  1005.         </xsl:choose>
  1006.     </xsl:template>
  1007.     <xsl:template name="replace-spaces">
  1008.         <xsl:param name="curr-string"/>
  1009.         <xsl:if test="contains($curr-string,'  ')">
  1010.             <xsl:value-of select="substring-before($curr-string,'  ')"/>
  1011.             <text:s text:c="2"/>
  1012.             <xsl:variable name="next-string" select="substring-after($curr-string,'  ')"/>
  1013.             <xsl:choose>
  1014.                 <xsl:when test="contains($next-string, '  ')">
  1015.                     <xsl:call-template name="replace-spaces">
  1016.                         <xsl:with-param name="curr-string" select="$next-string"/>
  1017.                     </xsl:call-template>
  1018.                 </xsl:when>
  1019.                 <xsl:otherwise>
  1020.                     <xsl:value-of select="$next-string"/>
  1021.                 </xsl:otherwise>
  1022.             </xsl:choose>
  1023.         </xsl:if>
  1024.     </xsl:template>
  1025.     <xsl:template match="w:tab">
  1026.         <xsl:element name="text:tab"/>
  1027.     </xsl:template>
  1028.     <xsl:template match="w:br">
  1029.         <xsl:if test="@w:type='text-wrapping' or not(@w:type)">
  1030.             <text:line-break/>
  1031.         </xsl:if>
  1032.     </xsl:template>
  1033.     <xsl:template match="w:footnote">
  1034.         <xsl:variable name="footnote-position">
  1035.             <xsl:number from="/w:wordDocument/w:body" count="w:footnote" level="any"/>
  1036.         </xsl:variable>
  1037.         <text:note text:note-class="footnote" text:id="ftn{$footnote-position}">
  1038.             <text:note-citation/>
  1039.             <text:note-body>
  1040.                 <xsl:apply-templates mode="dispatch"/>
  1041.             </text:note-body>
  1042.         </text:note>
  1043.     </xsl:template>
  1044.     <xsl:template match="w:endnote">
  1045.         <xsl:variable name="endnote-position">
  1046.             <xsl:number from="/w:wordDocument/w:body" count="w:endnote" level="any" format="1"/>
  1047.         </xsl:variable>
  1048.         <text:endnote text:id="edn{$endnote-position}">
  1049.             <text:endnote-body>
  1050.                 <xsl:apply-templates mode="dispatch"/>
  1051.             </text:endnote-body>
  1052.         </text:endnote>
  1053.     </xsl:template>
  1054. </xsl:stylesheet>
  1055.