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.xsl < prev    next >
Extensible Markup Language  |  2014-02-25  |  21KB  |  345 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" xmlns:fla="urn:experimental:fla">
  25.     <xsl:output method="xml" indent="no" encoding="UTF-8" version="1.0"/>
  26.     <xsl:include href="../../common/measure_conversion.xsl"/>
  27.     <xsl:include href="../common/ms2ooo_docpr.xsl"/>
  28.     <xsl:include href="wordml2ooo_text.xsl"/>
  29.     <xsl:include href="wordml2ooo_settings.xsl"/>
  30.     <xsl:include href="wordml2ooo_table.xsl"/>
  31.     <xsl:include href="wordml2ooo_page.xsl"/>
  32.     <xsl:include href="wordml2ooo_list.xsl"/>
  33.     <xsl:include href="wordml2ooo_draw.xsl"/>
  34.     <xsl:include href="wordml2ooo_field.xsl"/>
  35.     <xsl:include href="wordml2ooo_props.xsl"/>
  36.     <xsl:key name="paragraph-style" match="w:style[@w:type = 'paragraph']" use="@w:styleId"/>
  37.     <xsl:key name="heading-style" match="w:style[@w:type = 'paragraph' and w:pPr/w:outlineLvl]" use="@w:styleId"/>
  38.     <xsl:variable name="preserve-alien-markup">no</xsl:variable>
  39.     <xsl:variable name="native-namespace-prefixes">,w,o,v,wx,aml,w10,dt,</xsl:variable>
  40.     <xsl:variable name="to-dispatch-elements">,wx:sect,wx:sub-section,w:p,w:tbl,w:sectPr,w:r,w:fldSimple,w:hlink,w:t,w:pict,w:br,w:instrText,w:fldChar,w:tab,w:footnote,w:endnote,aml:annotation,w:hlink,w:footnote,w:endnote,w:tblGrid,w:tr,w:tc,wx:pBdrGroup,</xsl:variable>
  41.     <xsl:template match="/">
  42.         <xsl:apply-templates select="w:wordDocument"/>
  43.     </xsl:template>
  44.     <xsl:template match="*" mode="dispatch">
  45.         <xsl:choose>
  46.             <xsl:when test="not(contains($native-namespace-prefixes, concat(',', substring-before(name(), ':'), ',')))">
  47.                 <!-- if alien namespace dispatch -->
  48.                 <xsl:choose>
  49.                     <xsl:when test="$preserve-alien-markup = 'yes'">
  50.                         <xsl:copy>
  51.                            <xsl:copy-of select="@*"/>
  52.                            <xsl:apply-templates mode="dispatch"/>
  53.                         </xsl:copy>
  54.                     </xsl:when>
  55.                     <xsl:otherwise>
  56.                         <xsl:apply-templates mode="dispatch"/>
  57.                     </xsl:otherwise>
  58.                 </xsl:choose>
  59.             </xsl:when>
  60.             <xsl:when test="contains($to-dispatch-elements, concat(',',name(),','))">
  61.                 <xsl:apply-templates select="current()"/>
  62.             </xsl:when>
  63.         </xsl:choose>
  64.     </xsl:template>
  65.     <xsl:template match="w:wordDocument">
  66.         <office:document office:mimetype="application/vnd.oasis.opendocument.text" office:version="1.0">
  67.         <fla:fla.activate/>
  68.             <xsl:apply-templates select="o:DocumentProperties"/>
  69.             <xsl:apply-templates select="w:docOleData" mode="init"/>
  70.             <xsl:apply-templates select="w:docPr"/>
  71.             <xsl:apply-templates select="w:fonts"/>
  72.             <xsl:apply-templates select="w:styles"/>
  73.             <xsl:apply-templates select="w:body"/>
  74.             <xsl:apply-templates select="w:docOleData" mode="exit"/>
  75.         </office:document>
  76.     </xsl:template>
  77.     <xsl:template match="w:fonts">
  78.         <xsl:element name="office:font-face-decls">
  79.             <!-- MS Word's default font declaration, added for Writer automatically. glu -->
  80.             <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="roman" style:font-pitch="variable"/>
  81.             <style:font-face style:name="Times New Roman" svg:font-family="'Times New Roman'" style:font-family-generic="roman" style:font-pitch="variable"/>
  82.             <style:font-face style:name="Symbol" svg:font-family="Symbol" style:font-family-generic="roman" style:font-pitch="variable" style:font-charset="x-symbol"/>
  83.             <style:font-face style:name="Courier New" svg:font-family="'Courier New'" style:font-family-generic="modern" style:font-pitch="fixed"/>
  84.             <xsl:if test="not(w:font[@w:name='StarSymbol'])">
  85.                 <style:font-face style:name="StarSymbol" svg:font-family="StarSymbol" style:font-charset="x-symbol"/>
  86.             </xsl:if>
  87.             <xsl:for-each select="w:font">
  88.                 <xsl:element name="style:font-face">
  89.                     <xsl:attribute name="style:name">
  90.                         <xsl:value-of select="@w:name"/>
  91.                     </xsl:attribute>
  92.                     <xsl:attribute name="svg:font-family">
  93.                         <xsl:value-of select="@w:name"/>
  94.                     </xsl:attribute>
  95.                     <!-- added by glu, for process special fonts e.g. Marlett, -->
  96.                     <xsl:if test="w:charset/@w:val = '02'">
  97.                         <xsl:attribute name="style:font-charset">x-symbol</xsl:attribute>
  98.                     </xsl:if>
  99.                     <xsl:if test="w:family">
  100.                         <xsl:choose>
  101.                             <xsl:when test="w:family/@w:val = 'Swiss'">
  102.                                 <xsl:attribute name="style:font-family-generic">swiss</xsl:attribute>
  103.                             </xsl:when>
  104.                             <xsl:when test="w:family/@w:val='Modern'">
  105.                                 <xsl:attribute name="style:font-family-generic">modern</xsl:attribute>
  106.                             </xsl:when>
  107.                             <xsl:when test="w:family/@w:val='Roman'">
  108.                                 <xsl:attribute name="style:font-family-generic">roman</xsl:attribute>
  109.                             </xsl:when>
  110.                             <xsl:when test="w:family/@w:val='Script'">
  111.                                 <xsl:attribute name="style:font-family-generic">script</xsl:attribute>
  112.                             </xsl:when>
  113.                             <xsl:when test="w:family/@w:val='Decorative'">
  114.                                 <xsl:attribute name="style:font-family-generic">decorative</xsl:attribute>
  115.                             </xsl:when>
  116.                             <xsl:when test="w:family/@w:val='System'">
  117.                                 <xsl:attribute name="style:font-family-generic">system</xsl:attribute>
  118.                             </xsl:when>
  119.                             <xsl:otherwise>
  120.                                 <xsl:attribute name="style:font-family-generic">system</xsl:attribute>
  121.                             </xsl:otherwise>
  122.                         </xsl:choose>
  123.                     </xsl:if>
  124.                     <xsl:if test="w:pitch and string-length(w:pitch/@w:val) > 0">
  125.                         <xsl:attribute name="style:font-pitch">
  126.                             <xsl:choose>
  127.                                 <xsl:when test="w:pitch/@w:val = 'default'">variable</xsl:when>
  128.                                 <xsl:otherwise>
  129.                                     <xsl:value-of select="w:pitch/@w:val"/>
  130.                                 </xsl:otherwise>
  131.                             </xsl:choose>
  132.                         </xsl:attribute>
  133.                     </xsl:if>
  134.                 </xsl:element>
  135.             </xsl:for-each>
  136.         </xsl:element>
  137.     </xsl:template>
  138.     <xsl:template match="w:styles">
  139.         <office:styles>
  140.             <!--The next statement Added by wguo,collect the pict's dash and mark-style.The template is implemented in file wordml2ooo_draw.xsl-->
  141.             <xsl:apply-templates select="/w:wordDocument/w:body//w:pict" mode="style4dash_mark"/>
  142.             <xsl:apply-templates select="//v:fill" mode="office-style"/>
  143.             <xsl:call-template name="create-default-paragraph-styles"/>
  144.             <xsl:call-template name="create-default-text-styles"/>
  145.             <xsl:call-template name="create-default-frame-style"/>
  146.             <!-- StarWriter has no default style family 'list'. glu -->
  147.             <xsl:if test="w:style[@w:type = 'paragraph' and w:pPr/w:outlineLvl and w:pPr/w:listPr]">
  148.                 <xsl:call-template name="create-outline-style"/>
  149.             </xsl:if>
  150.             <xsl:apply-templates select="w:style[@w:type='table']" mode="table"/>
  151.             <xsl:apply-templates select="w:style[@w:type='list']" mode="list"/>
  152.             <xsl:apply-templates select="w:style[@w:type!='list']"/>
  153.             <xsl:apply-templates select="/w:wordDocument/w:docPr/w:footnotePr" mode="config"/>
  154.             <xsl:apply-templates select="/w:wordDocument/w:docPr/w:endnotePr" mode="config"/>
  155.         </office:styles>
  156.         <office:automatic-styles>
  157.             <xsl:apply-templates select="/w:wordDocument/w:body//w:p" mode="style"/>
  158.             <xsl:apply-templates select="/w:wordDocument/w:body//w:rPr[not(parent::w:pPr)]" mode="style"/>
  159.             <!--The next statement Added by wguo for the pict's draw-style.The template is implemented in file wordml2ooo_draw.xsl-->
  160.             <xsl:apply-templates select="/w:wordDocument/w:body//w:pict" mode="style"/>
  161.             <xsl:apply-templates select="/w:wordDocument/w:body//w:tblPr" mode="style"/>
  162.             <xsl:apply-templates select="/w:wordDocument/w:body//w:gridCol" mode="style"/>
  163.             <xsl:apply-templates select="/w:wordDocument/w:body//w:trPr" mode="style"/>
  164.             <xsl:apply-templates select="/w:wordDocument/w:body//w:tcPr" mode="style"/>
  165.             <xsl:apply-templates select="/w:wordDocument/w:body//w:listPr" mode="style"/>
  166.             <xsl:apply-templates select="/w:wordDocument/w:body//w:sectPr" mode="page-layout"/>
  167.             <xsl:call-template name="default_date_style"/>
  168.             <!--add for generate the date , time style for date , time field  G.Y.-->
  169.             <xsl:apply-templates select="/w:wordDocument/w:body//w:instrText | /w:wordDocument/w:body//w:fldSimple " mode="style"/>
  170.         </office:automatic-styles>
  171.         <office:master-styles>
  172.             <xsl:apply-templates select="/w:wordDocument/w:body//w:sectPr" mode="master-page"/>
  173.         </office:master-styles>
  174.     </xsl:template>
  175.     <xsl:template match="w:style">
  176.         <style:style>
  177.             <xsl:attribute name="style:name">
  178.                 <xsl:value-of select="concat('w',translate(@w:styleId,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  179.             </xsl:attribute>
  180.             <xsl:if test="w:basedOn">
  181.                 <xsl:attribute name="style:parent-style-name">
  182.                     <xsl:value-of select="concat('w',translate(w:basedOn/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  183.                 </xsl:attribute>
  184.             </xsl:if>
  185.             <xsl:if test="w:next">
  186.                 <xsl:attribute name="style:next-style-name">
  187.                     <xsl:value-of select="concat('w',translate(w:basedOn/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  188.                 </xsl:attribute>
  189.             </xsl:if>
  190.             <xsl:choose>
  191.                 <xsl:when test="@w:type = 'character'">
  192.                     <xsl:attribute name="style:family">text</xsl:attribute>
  193.                 </xsl:when>
  194.                 <!-- table, paragraph are the same as in Writer . glu -->
  195.                 <xsl:when test="@w:type">
  196.                     <xsl:attribute name="style:family">
  197.                         <xsl:value-of select="@w:type"/>
  198.                     </xsl:attribute>
  199.                 </xsl:when>
  200.                 <xsl:otherwise>
  201.                     <xsl:attribute name="style:family">text</xsl:attribute>
  202.                 </xsl:otherwise>
  203.             </xsl:choose>
  204.             <xsl:choose>
  205.                 <xsl:when test="@w:type = 'table'">
  206.                     <xsl:element name="style:table-properties">
  207.                         <!-- xsl:apply-templates select="w:tblPr" mode="style"/ -->
  208.                     </xsl:element>
  209.                 </xsl:when>
  210.                 <xsl:when test="@w:type = 'character' ">
  211.                     <xsl:element name="style:text-properties">
  212. <!--
  213.                         <xsl:apply-templates select="w:pPr/w:rPr"/>
  214.                         <xsl:apply-templates select="w:rPr"/>
  215. -->
  216.             <xsl:for-each select="w:rPr">
  217.             <xsl:call-template name="text-properties"/>
  218.             </xsl:for-each>
  219.                     </xsl:element>
  220.                 </xsl:when>
  221.                 <xsl:otherwise>
  222.                     <xsl:element name="style:paragraph-properties">
  223.                         <xsl:apply-templates select="w:pPr"/>
  224.                     </xsl:element>
  225.                     <xsl:element name="style:text-properties">
  226.                         <xsl:apply-templates select="w:rPr"/>
  227.                         <xsl:apply-templates select="w:pPr/w:rPr"/>
  228.                     </xsl:element>
  229.                 </xsl:otherwise>
  230.             </xsl:choose>
  231.         </style:style>
  232.     </xsl:template>
  233.     <xsl:template match="w:body">
  234.         <xsl:element name="office:body">
  235.             <xsl:element name="office:text">
  236.                 <!-- to add the sequece variable declaration at the begining of the office:body  G.Y.-->
  237.                 <text:sequence-decls>
  238.                     <xsl:call-template name="default_seqence_declaration"/>
  239.                     <xsl:apply-templates select="/w:wordDocument/w:body//w:instrText[substring(normalize-space(text()),1,3) = 'SEQ' ] | /w:wordDocument/w:body//w:fldSimple[substring(normalize-space(@w:instr),1,3) = 'SEQ' ]  " mode="sequence_declare"/>
  240.                 </text:sequence-decls>
  241.                 <!--  add the user field variables declare for Docpropety fields importing G.Y.-->
  242.                 <text:user-field-decls>
  243.                     <xsl:call-template name="user_fields_declare_docproperty"/>
  244.                 </text:user-field-decls>
  245.                 <xsl:apply-templates mode="dispatch"/>
  246.             </xsl:element>
  247.         </xsl:element>
  248.     </xsl:template>
  249.     <xsl:template match="wx:sect">
  250.         <xsl:apply-templates mode="dispatch"/>
  251.     </xsl:template>
  252.     <xsl:template match="wx:sub-section">
  253.         <xsl:apply-templates mode="dispatch"/>
  254.     </xsl:template>
  255.     <xsl:template name="create-default-frame-style">
  256.         <!--add for default frame style -->
  257.         <style:style style:name="Frame" style:family="graphic">
  258.             <style:graphic-properties text:anchor-type="paragraph" svg:x="0in" svg:y="0in" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" style:wrap-contour="false" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="center" style:horizontal-rel="paragraph-content"/>
  259.         </style:style>
  260.     </xsl:template>
  261.     <xsl:template name="ConvertMeasure">
  262.         <xsl:param name="TargetMeasure" select="'cm'"/>
  263.         <xsl:param name="TargetTruncate" select=" 'all' "/>
  264.         <xsl:param name="value"/>
  265.         <!-- When TargetTruncate ='all'  it returns the number whichsoever the return value is negative or positive
  266.                When TargetTruncate ='nonNegative' it only returns nonNegative number, all negative number to be returned as 0
  267.                When TargetTruncate ='positive" it only returns positive number, all nonPositive number to be returned as 1 -->
  268.         <xsl:variable name="return_value">
  269.             <xsl:choose>
  270.                 <!-- remove the measure mark, if the value is null, the result should be 0. Must be the first case  -->
  271.                 <xsl:when test="string-length(translate($value,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ','')) = 0">0</xsl:when>
  272.                 <xsl:when test="string-length(translate($value,'-.0123456789 ','')) = 0">
  273.                     <xsl:value-of select="$value"/>
  274.                 </xsl:when>
  275.                 <xsl:when test="$TargetMeasure = 'cm'">
  276.                     <xsl:call-template name="convert2cm">
  277.                         <xsl:with-param name="value" select="$value"/>
  278.                     </xsl:call-template>
  279.                 </xsl:when>
  280.                 <xsl:when test="$TargetMeasure = 'pt'">
  281.                     <xsl:call-template name="convert2pt">
  282.                         <xsl:with-param name="value" select="$value"/>
  283.                     </xsl:call-template>
  284.                 </xsl:when>
  285.                 <xsl:when test="$TargetMeasure = 'twip'">
  286.                     <xsl:call-template name="convert2twip">
  287.                         <xsl:with-param name="value" select="$value"/>
  288.                     </xsl:call-template>
  289.                 </xsl:when>
  290.                 <xsl:when test="$TargetMeasure = 'in'">
  291.                     <xsl:call-template name="convert2in">
  292.                         <xsl:with-param name="value" select="$value"/>
  293.                     </xsl:call-template>
  294.                 </xsl:when>
  295.             </xsl:choose>
  296.         </xsl:variable>
  297.         <xsl:choose>
  298.             <xsl:when test="$TargetTruncate = 'all' ">
  299.                 <xsl:choose>
  300.                     <xsl:when test="number($TargetMeasure) = 'NaN' ">
  301.                         <xsl:value-of select=" '0' "/>
  302.                     </xsl:when>
  303.                     <xsl:otherwise>
  304.                         <xsl:value-of select="$return_value"/>
  305.                     </xsl:otherwise>
  306.                 </xsl:choose>
  307.             </xsl:when>
  308.             <xsl:when test="$TargetTruncate = 'nonNegative' ">
  309.                 <xsl:choose>
  310.                     <xsl:when test="number($TargetMeasure) = 'NaN' ">
  311.                         <xsl:value-of select=" '0' "/>
  312.                     </xsl:when>
  313.                     <xsl:otherwise>
  314.                         <xsl:choose>
  315.                             <xsl:when test=" $return_value < 0  ">
  316.                                 <xsl:value-of select=" '0' "/>
  317.                             </xsl:when>
  318.                             <xsl:otherwise>
  319.                                 <xsl:value-of select="$return_value"/>
  320.                             </xsl:otherwise>
  321.                         </xsl:choose>
  322.                     </xsl:otherwise>
  323.                 </xsl:choose>
  324.             </xsl:when>
  325.             <xsl:when test="$TargetTruncate = 'positive' ">
  326.                 <xsl:choose>
  327.                     <xsl:when test="number($TargetMeasure) = 'NaN' ">
  328.                         <xsl:value-of select=" '1' "/>
  329.                     </xsl:when>
  330.                     <xsl:otherwise>
  331.                         <xsl:choose>
  332.                             <xsl:when test=" $return_value <= 0 ">
  333.                                 <xsl:value-of select=" '1' "/>
  334.                             </xsl:when>
  335.                             <xsl:otherwise>
  336.                                 <xsl:value-of select="$return_value"/>
  337.                             </xsl:otherwise>
  338.                         </xsl:choose>
  339.                     </xsl:otherwise>
  340.                 </xsl:choose>
  341.             </xsl:when>
  342.         </xsl:choose>
  343.     </xsl:template>
  344. </xsl:stylesheet>
  345.