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 / styles.xsl < prev    next >
Extensible Markup Language  |  2014-02-25  |  30KB  |  692 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"
  25.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  26.     xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  27.     xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
  28.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  29.     xmlns:dom="http://www.w3.org/2001/xml-events"
  30.     xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  31.     xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  32.     xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  33.     xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  34.     xmlns:math="http://www.w3.org/1998/Math/MathML"
  35.     xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  36.     xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  37.     xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  38.     xmlns:ooo="http://openoffice.org/2004/office"
  39.     xmlns:oooc="http://openoffice.org/2004/calc"
  40.     xmlns:ooow="http://openoffice.org/2004/writer"
  41.     xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  42.     xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  43.     xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  44.     xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  45.     xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  46.     xmlns:xlink="http://www.w3.org/1999/xlink"
  47.     xmlns:xt="http://www.jclark.com/xt"
  48.     xmlns:common="http://exslt.org/common"
  49.     xmlns:xalan="http://xml.apache.org/xalan"
  50.     xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  51.     exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xlink xt common xalan">
  52.  
  53.     <!-- Used in case of 'style:map', conditional formatting, where a style references to another -->
  54.     <xsl:key name="styles" match="/*/office:styles/style:style | /*/office:automatic-styles/style:style" use="@style:name" />
  55.     <!--
  56.         Mapping of OOo style:name and style:family to excel ss:ID
  57.         Styles form style:style map from style:name to ss:Name
  58.         style:parent-style map to ss:Parent
  59.     -->
  60.     <!--   default styles of the application
  61.     <xsl:template match="style:default-style" mode="styles" >
  62.         <xsl:call-template name="style:style">
  63.             <xsl:with-param name="styleName" select="'Default'" />
  64.         </xsl:call-template>
  65.     </xsl:template>
  66.      -->
  67.  
  68.     <xsl:template match="style:style" mode="styles">
  69.         <xsl:param name="isAutomatic" />
  70.         <xsl:param name="styleName" select="@style:name" />
  71.         <xsl:param name="styleParentName" select="@style:parent-style-name" />
  72.  
  73.         <!-- only row styles used by cells are exported,
  74.             as usual row style properties are already exported as row attributes -->
  75.         <xsl:if test="not(@style:family='table-row') or @style:family='table-row' and key('getCellByStyle', '.')">
  76.             <xsl:element name="Style">
  77.                 <xsl:attribute name="ss:ID">
  78.                     <!-- neglecting that a style is only unique in conjunction with it's family name -->
  79.                     <xsl:value-of select="@style:name" />
  80.                 </xsl:attribute>
  81.                 <xsl:choose>
  82.                     <xsl:when test="not($isAutomatic)">
  83.                         <xsl:choose>
  84.                             <xsl:when test="@style:display-name">
  85.                                 <xsl:attribute name="ss:Name"><xsl:value-of select="@style:display-name"/></xsl:attribute>
  86.                             </xsl:when>
  87.                             <xsl:otherwise>
  88.                                 <xsl:attribute name="ss:Name"><xsl:value-of select="@style:name" /></xsl:attribute>
  89.                             </xsl:otherwise>
  90.                         </xsl:choose>
  91.                         <xsl:choose>
  92.                             <!-- when a non-allowed parent style is found
  93.                                 (in spreadsheetml no style with ss:Name is able to have a ss:Parent)  -->
  94.                             <xsl:when test="@style:parent-style-name">
  95.                                 <!-- styles have to be merged (flatting heritance tree) -->
  96.                                 <xsl:variable name="stylePropertiesContainer">
  97.                                     <xsl:call-template name="merge-all-parent-styles">
  98.                                         <xsl:with-param name="currentStyle" select="." />
  99.                                     </xsl:call-template>
  100.                                 </xsl:variable>
  101.                                 <xsl:choose>
  102.                                     <xsl:when test="function-available('xalan:nodeset')">
  103.                                         <xsl:call-template name="write-style-properties">
  104.                                             <xsl:with-param name="styleProperties" select="xalan:nodeset($stylePropertiesContainer)/*" />
  105.                                         </xsl:call-template>
  106.                                     </xsl:when>
  107.                                     <xsl:when test="function-available('common:node-set')">
  108.                                         <xsl:call-template name="write-style-properties">
  109.                                             <xsl:with-param name="styleProperties" select="common:node-set($stylePropertiesContainer)/*" />
  110.                                         </xsl:call-template>
  111.                                     </xsl:when>
  112.                                     <xsl:when test="function-available('xt:node-set')">
  113.                                         <xsl:call-template name="write-style-properties">
  114.                                             <xsl:with-param name="styleProperties" select="xt:node-set($stylePropertiesContainer)/*" />
  115.                                         </xsl:call-template>
  116.                                     </xsl:when>
  117.                                     <xsl:otherwise>
  118.                                         <xsl:message terminate="yes">WARNING: The required node set function was not found!</xsl:message>
  119.                                     </xsl:otherwise>
  120.                                 </xsl:choose>
  121.                             </xsl:when>
  122.                             <xsl:otherwise>
  123.                                 <xsl:call-template name="write-style-properties" />
  124.                             </xsl:otherwise>
  125.                         </xsl:choose>
  126.                     </xsl:when>
  127.                     <xsl:otherwise>
  128.                         <!-- automatic styles are implicit inherting from a style called 'Default',
  129.                         furthermore nor in spreadsheetml nor in OpenDocument automatic styles are able to inherit from each other -->
  130.                         <xsl:choose>
  131.                             <xsl:when test="@style:parent-style-name and not(@style:parent-style-name = 'Default')">
  132.                                 <xsl:attribute name="ss:Parent"><xsl:value-of select="@style:parent-style-name" /></xsl:attribute>
  133.                             </xsl:when>
  134.                         </xsl:choose>
  135.                         <xsl:call-template name="write-style-properties" />
  136.                     </xsl:otherwise>
  137.                 </xsl:choose>
  138.             </xsl:element>
  139.         </xsl:if>
  140.     </xsl:template>
  141.  
  142.     <!-- resolving the style inheritance by starting from uppermost parent and
  143.          overriding exisiting style properties by new found child properties -->
  144.     <xsl:template name="merge-all-parent-styles">
  145.         <xsl:param name="currentStyle" />
  146.  
  147.         <xsl:choose>
  148.             <!-- in case of a parent, styles have to be merged (flatting heritance tree) -->
  149.             <xsl:when test="$currentStyle/@style:parent-style-name">
  150.                 <!-- collect parent style properties -->
  151.                 <xsl:variable name="parentStyleContainer">
  152.                     <!-- take a look if the parent style has a parent himself -->
  153.                     <xsl:call-template name="merge-all-parent-styles" >
  154.                         <xsl:with-param name="currentStyle" select="key('styles', $currentStyle/@style:parent-style-name)" />
  155.                     </xsl:call-template>
  156.                 </xsl:variable>
  157.                 <xsl:choose>
  158.                     <xsl:when test="function-available('xalan:nodeset')">
  159.                         <xsl:call-template name="merge-style-properties">
  160.                             <xsl:with-param name="childStyleContainer"  select="$currentStyle" />
  161.                             <xsl:with-param name="parentStyleContainer" select="xalan:nodeset($parentStyleContainer)" />
  162.                         </xsl:call-template>
  163.                     </xsl:when>
  164.                     <xsl:when test="function-available('common:node-set')">
  165.                         <xsl:call-template name="merge-style-properties">
  166.                             <xsl:with-param name="childStyleContainer"  select="$currentStyle" />
  167.                             <xsl:with-param name="parentStyleContainer" select="common:node-set($parentStyleContainer)" />
  168.                         </xsl:call-template>
  169.                     </xsl:when>
  170.                     <xsl:when test="function-available('xt:node-set')">
  171.                         <xsl:call-template name="merge-style-properties">
  172.                             <xsl:with-param name="childStyleContainer"  select="$currentStyle" />
  173.                             <xsl:with-param name="parentStyleContainer" select="xt:node-set($parentStyleContainer)" />
  174.                         </xsl:call-template>
  175.                     </xsl:when>
  176.                     <xsl:otherwise>
  177.                         <xsl:message terminate="yes">WARNING: The required node-set function was not found!</xsl:message>
  178.                     </xsl:otherwise>
  179.                 </xsl:choose>
  180.             </xsl:when>
  181.             <!-- called for top parents (or styles without parents) -->
  182.             <xsl:otherwise>
  183.                 <xsl:copy-of select="$currentStyle/*"/>
  184.             </xsl:otherwise>
  185.         </xsl:choose>
  186.     </xsl:template>
  187.  
  188.     <xsl:template name="merge-style-properties">
  189.         <xsl:param name="childStyleContainer" />
  190.         <xsl:param name="parentStyleContainer" />
  191.  
  192.         <xsl:choose>
  193.             <xsl:when test="$parentStyleContainer/*">
  194.                 <xsl:apply-templates select="$parentStyleContainer/*" mode="inheritance">
  195.                     <xsl:with-param name="childStyleContainer" select="$childStyleContainer" />
  196.                 </xsl:apply-templates>
  197.             </xsl:when>
  198.             <xsl:otherwise>
  199.                 <xsl:copy-of select="$childStyleContainer/*"/>
  200.             </xsl:otherwise>
  201.         </xsl:choose>
  202.     </xsl:template>
  203.  
  204.     <xsl:template match="*" mode="inheritance">
  205.         <xsl:param name="childStyleContainer" />
  206.  
  207.         <!-- create an element named equal to the current properties parent element (e.g. style:table-cell-properties) -->
  208.         <xsl:element name="{name()}" namespace="urn:oasis:names:tc:opendocument:xmlns:style:1.0">
  209.             <!-- attributes will be automatically replaced    -->
  210.             <xsl:copy-of select="@*" />
  211.             <xsl:copy-of select="$childStyleContainer/*[name() = name(current()    )]/@*"/>
  212.  
  213.             <!-- elements are not needed yet, will be neglected for simplicity reasons -->
  214.         </xsl:element>
  215.     </xsl:template>
  216.  
  217.     <xsl:key match="/*/office:styles/number:date-style |
  218.                     /*/office:styles/number:time-style |
  219.                     /*/office:styles/number:number-style |
  220.                     /*/office:styles/number:percentage-style |
  221.                     /*/office:styles/number:currency-style |
  222.                     /*/office:automatic-styles/number:date-style |
  223.                     /*/office:automatic-styles/number:time-style |
  224.                     /*/office:automatic-styles/number:number-style  |
  225.                     /*/office:automatic-styles/number:percentage-style |
  226.                     /*/office:automatic-styles/number:currency-style" name="number-style" use="@style:name" />
  227.  
  228.  
  229.     <xsl:template name="write-style-properties">
  230.         <xsl:param name="styleProperties" select="key('styles', @style:name)/*" />
  231.  
  232.         <xsl:call-template name="Alignment">
  233.             <xsl:with-param name="styleProperties" select="$styleProperties" />
  234.         </xsl:call-template>
  235.         <xsl:call-template name="Border">
  236.             <xsl:with-param name="styleProperties" select="$styleProperties" />
  237.         </xsl:call-template>
  238.         <xsl:call-template name="Font">
  239.             <xsl:with-param name="styleProperties" select="$styleProperties" />
  240.             <xsl:with-param name="styleParentName" select="@style:parent-style-name" />
  241.         </xsl:call-template>
  242.         <xsl:call-template name="Interior">
  243.             <xsl:with-param name="styleProperties" select="$styleProperties" />
  244.         </xsl:call-template>
  245.         <xsl:call-template name="NumberFormat">
  246.             <xsl:with-param name="styleProperties" select="$styleProperties" />
  247.         </xsl:call-template>
  248.     </xsl:template>
  249.  
  250.     <!-- context is element 'style:style' -->
  251.     <xsl:template name="NumberFormat">
  252.         <xsl:if test="@style:data-style-name">
  253.             <xsl:variable name="numberStyleName" select="@style:data-style-name" />
  254.             <xsl:variable name="numberStyle" select="key('number-style', $numberStyleName)" />
  255.  
  256.             <xsl:element name="NumberFormat">
  257.                 <xsl:attribute name="ss:Format">
  258.                 <xsl:choose>
  259.                     <xsl:when test="not($numberStyle/node())">
  260.                         <!-- Excel2003sp1 issue: 'General' and 'General Number' is not supported -->
  261.                          <xsl:text>General</xsl:text>
  262.                     </xsl:when>
  263.                     <xsl:when test="name($numberStyle) = 'number:number-style'">
  264.                         <xsl:choose>
  265.                             <xsl:when test="$numberStyle/number:scientific-number">
  266.                                 <xsl:text>Scientific</xsl:text>
  267.                             </xsl:when>
  268.                             <!-- Excel2003sp1 issue: 'General Number' not supported -->
  269.                             <xsl:when test="$numberStyle/number:number/@number:decimal-places and
  270.                                             $numberStyle/number:number/@number:decimal-places='0'">
  271.                                 <xsl:text>General</xsl:text>
  272.                             </xsl:when>
  273.                             <xsl:when test="$numberStyle/number:text">
  274.                                 <xsl:choose>
  275.                                     <xsl:when test="$numberStyle/number:text = 'No' or $numberStyle/number:text = 'Nein'">
  276.                                         <xsl:text>Yes/No</xsl:text>
  277.                                     </xsl:when>
  278.                                     <xsl:when test="$numberStyle/number:text = 'False' or $numberStyle/number:text = 'Falsch'">
  279.                                         <xsl:text>True/False</xsl:text>
  280.                                     </xsl:when>
  281.                                     <xsl:when test="$numberStyle/number:text = 'Off' or $numberStyle/number:text = 'Aus'">
  282.                                         <xsl:text>On/Off</xsl:text>
  283.                                     </xsl:when>
  284.                                     <!-- Excel2003sp1 issue: currency is saved as 'float' -->
  285.                                     <xsl:when test="$numberStyle/number:currency-symbol">
  286.                                         <xsl:choose>
  287.                                             <xsl:when test="contains($numberStyle/number:currency-symbol, 'Γé¼')">
  288.                                                 <xsl:text>Euro Currency</xsl:text>
  289.                                             </xsl:when>
  290.                                             <xsl:otherwise>
  291.                                                 <xsl:text>Currency</xsl:text>
  292.                                             </xsl:otherwise>
  293.                                         </xsl:choose>
  294.                                     </xsl:when>
  295.                                     <!-- Excel2003sp1 issue: 'Currency' is saved as 'float' -->
  296.                                     <xsl:when test="contains($numberStyle/number:text, '$')">
  297.                                         <xsl:text>Currency</xsl:text>
  298.                                     </xsl:when>
  299.                                     <!-- OASIS XML adapation -->
  300.                                     <xsl:otherwise>
  301.                                         <xsl:text>General</xsl:text>
  302.                                     </xsl:otherwise>
  303.                                 </xsl:choose>
  304.                             </xsl:when>
  305.                             <xsl:when test="$numberStyle/number:grouping">
  306.                                 <xsl:text>Standard</xsl:text>
  307.                             </xsl:when>
  308.                             <xsl:otherwise>
  309.                                 <xsl:text>Fixed</xsl:text>
  310.                             </xsl:otherwise>
  311.                         </xsl:choose>
  312.                     </xsl:when>
  313.                     <xsl:when test="name($numberStyle) = 'number:time-style'">
  314.                         <xsl:choose>
  315.                             <xsl:when test="$numberStyle/number:am-pm">
  316.                                 <xsl:choose>
  317.                                     <xsl:when test="$numberStyle/number:seconds">
  318.                                         <xsl:text>Long Time</xsl:text>
  319.                                     </xsl:when>
  320.                                     <xsl:otherwise>
  321.                                         <xsl:text>Medium Time</xsl:text>
  322.                                     </xsl:otherwise>
  323.                                 </xsl:choose>
  324.                             </xsl:when>
  325.                             <xsl:otherwise>
  326.                                 <xsl:text>Short Time</xsl:text>
  327.                             </xsl:otherwise>
  328.                         </xsl:choose>
  329.                     </xsl:when>
  330.                     <xsl:when test="name($numberStyle) = 'number:percentage-style'">
  331.                         <xsl:text>Percent</xsl:text>
  332.                     </xsl:when>
  333.                     <xsl:when test="name($numberStyle) = 'number:currency-style'">
  334.                         <xsl:choose>
  335.                             <xsl:when test="contains($numberStyle/number:currency-symbol, 'Γé¼')">
  336.                                 <xsl:text>Euro Currency</xsl:text>
  337.                             </xsl:when>
  338.                             <xsl:otherwise>
  339.                                 <xsl:text>Currency</xsl:text>
  340.                             </xsl:otherwise>
  341.                         </xsl:choose>
  342.                     </xsl:when>
  343.                     <xsl:otherwise>
  344.                         <xsl:choose>
  345.                             <xsl:when test="$numberStyle/number:month">
  346.                                 <xsl:choose>
  347.                                     <xsl:when test="$numberStyle/number:month/@number:textual and
  348.                                                     $numberStyle/number:month/@number:textual=true()">
  349.                                         <xsl:text>Medium Date</xsl:text>
  350.                                         <!--  Excel2003 sp1 issue: No difference between 'Long Date' and 'Medium Date' -->
  351.                                     </xsl:when>
  352.                                     <xsl:when test="$numberStyle/number:hours">
  353.                                         <xsl:text>General Date</xsl:text>
  354.                                     </xsl:when>
  355.                                     <xsl:when test="$numberStyle/number:year/@number:style and
  356.                                                     $numberStyle/number:year/@number:style='long'">
  357.                                         <xsl:text>Short Date</xsl:text>
  358.                                     </xsl:when>
  359.                                     <!-- OASIS XML adapation -->
  360.                                     <xsl:otherwise>
  361.                                         <xsl:text>Short Date</xsl:text>
  362.                                     </xsl:otherwise>
  363.                                 </xsl:choose>
  364.                             </xsl:when>
  365.                             <!-- OASIS XML adapation -->
  366.                             <xsl:otherwise>
  367.                                 <xsl:text>General</xsl:text>
  368.                             </xsl:otherwise>
  369.                         </xsl:choose>
  370.                     </xsl:otherwise>
  371.                 </xsl:choose>
  372.                 </xsl:attribute>
  373.             </xsl:element>
  374.         </xsl:if>
  375.     </xsl:template>
  376.  
  377.     <xsl:template name="Alignment">
  378.         <xsl:param name="styleProperties" />
  379.  
  380.         <!-- An empty Alignment element, might overwrite parents setting by
  381.              the default attributes -->
  382.         <xsl:if test="$styleProperties/@fo:text-align or
  383.                       $styleProperties/@style:vertical-align or
  384.                       $styleProperties/@fo:wrap-option or
  385.                       $styleProperties/@fo:margin-left or
  386.                       $styleProperties/@style:rotation-angle or
  387.                       $styleProperties/@style:direction">
  388.             <xsl:element name="Alignment">
  389.                 <xsl:if test="$styleProperties/@fo:text-align">
  390.                     <xsl:attribute name="ss:Horizontal">
  391.                         <xsl:choose>
  392.                             <xsl:when test="$styleProperties/@fo:text-align = 'center'">Center</xsl:when>
  393.                             <xsl:when test="$styleProperties/@fo:text-align = 'end'">Right</xsl:when>
  394.                             <xsl:when test="$styleProperties/@fo:text-align = 'justify'">Justify</xsl:when>
  395.                             <xsl:otherwise>Left</xsl:otherwise>
  396.                         </xsl:choose>
  397.                     </xsl:attribute>
  398.                 </xsl:if>
  399.                 <xsl:if test="$styleProperties/@style:vertical-align">
  400.                     <xsl:attribute name="ss:Vertical">
  401.                         <xsl:choose>
  402.                             <xsl:when test="$styleProperties/@style:vertical-align = 'top'">Top</xsl:when>
  403.                             <xsl:when test="$styleProperties/@style:vertical-align = 'bottom'">Bottom</xsl:when>
  404.                             <xsl:when test="$styleProperties/@style:vertical-align = 'middle'">Center</xsl:when>
  405.                             <xsl:otherwise>Automatic</xsl:otherwise>
  406.                         </xsl:choose>
  407.                     </xsl:attribute>
  408.                 </xsl:if>
  409.                 <xsl:if test="$styleProperties/@fo:wrap-option = 'wrap'">
  410.                     <xsl:attribute name="ss:WrapText">1</xsl:attribute>
  411.                 </xsl:if>
  412.                 <xsl:if test="$styleProperties/@fo:margin-left">
  413.                     <xsl:attribute name="ss:Indent">
  414.                         <xsl:variable name="margin">
  415.                             <xsl:call-template name="convert2pt">
  416.                                 <xsl:with-param name="value" select="$styleProperties/@fo:margin-left" />
  417.                                 <xsl:with-param name="rounding-factor" select="1" />
  418.                             </xsl:call-template>
  419.                         </xsl:variable>
  420.                         <!-- one ss:Indent is equal to 10 points -->
  421.                         <xsl:value-of select="number($margin) div 10"/>
  422.                     </xsl:attribute>
  423.                 </xsl:if>
  424.                 <!-- Excel is only able to rotate between 90 and -90 degree (inclusive).
  425.                      Other degrees will be mapped by 180 degrees -->
  426.                 <xsl:if test="$styleProperties/@style:rotation-angle">
  427.                     <xsl:attribute name="ss:Rotate">
  428.                         <xsl:choose>
  429.                             <xsl:when test="$styleProperties/@style:rotation-angle > 90">
  430.                                 <xsl:choose>
  431.                                     <xsl:when test="$styleProperties/@style:rotation-angle >= 270">
  432.                                         <xsl:value-of select="$styleProperties/@style:rotation-angle - 360" />
  433.                                     </xsl:when>
  434.                                     <xsl:otherwise>
  435.                                         <xsl:value-of select="$styleProperties/@style:rotation-angle - 180" />
  436.                                     </xsl:otherwise>
  437.                                 </xsl:choose>
  438.                             </xsl:when>
  439.                             <xsl:when test="$styleProperties/@style:rotation-angle < -90">
  440.                                 <xsl:choose>
  441.                                     <xsl:when test="$styleProperties/@style:rotation-angle <= -270">
  442.                                         <xsl:value-of select="$styleProperties/@style:rotation-angle + 360" />
  443.                                     </xsl:when>
  444.                                     <xsl:otherwise>
  445.                                         <xsl:value-of select="$styleProperties/@style:rotation-angle + 180" />
  446.                                     </xsl:otherwise>
  447.                                 </xsl:choose>
  448.                             </xsl:when>
  449.                             <xsl:otherwise>
  450.                                 <xsl:value-of select="$styleProperties/@style:rotation-angle" />
  451.                             </xsl:otherwise>
  452.                         </xsl:choose>
  453.                     </xsl:attribute>
  454.                 </xsl:if>
  455.                 <xsl:if test="$styleProperties/@style:direction = 'ttb'">
  456.                     <xsl:attribute name="ss:VerticalText">1</xsl:attribute>
  457.                 </xsl:if>
  458.             </xsl:element>
  459.         </xsl:if>
  460.     </xsl:template>
  461.  
  462.  
  463.     <xsl:template name="Border">
  464.         <xsl:param name="styleProperties" />
  465.  
  466.         <!-- An empty border element, might overwrite parents setting by
  467.              the default attributes -->
  468.         <xsl:if test="$styleProperties/@fo:border or
  469.                       $styleProperties/@fo:border-bottom or
  470.                       $styleProperties/@fo:border-left or
  471.                       $styleProperties/@fo:border-right or
  472.                       $styleProperties/@fo:border-top">
  473.             <xsl:element name="Borders">
  474.                 <xsl:if test="$styleProperties/@fo:border-bottom and not($styleProperties/@fo:border-bottom = 'none')">
  475.                     <xsl:element name="Border">
  476.                         <xsl:attribute name="ss:Position">Bottom</xsl:attribute>
  477.                         <xsl:call-template name="border-attributes">
  478.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-bottom" />
  479.                         </xsl:call-template>
  480.                     </xsl:element>
  481.                 </xsl:if>
  482.                 <xsl:if test="$styleProperties/@fo:border-left and not($styleProperties/@fo:border-left = 'none')">
  483.                     <xsl:element name="Border">
  484.                         <xsl:attribute name="ss:Position">Left</xsl:attribute>
  485.                         <xsl:call-template name="border-attributes">
  486.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-left" />
  487.                         </xsl:call-template>
  488.                     </xsl:element>
  489.                 </xsl:if>
  490.                 <xsl:if test="$styleProperties/@fo:border-right and not($styleProperties/@fo:border-right = 'none')">
  491.                     <xsl:element name="Border">
  492.                         <xsl:attribute name="ss:Position">Right</xsl:attribute>
  493.                         <xsl:call-template name="border-attributes">
  494.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-right" />
  495.                         </xsl:call-template>
  496.                     </xsl:element>
  497.                 </xsl:if>
  498.                 <xsl:if test="$styleProperties/@fo:border-top  and not($styleProperties/@fo:border-top = 'none')">
  499.                     <xsl:element name="Border">
  500.                         <xsl:attribute name="ss:Position">Top</xsl:attribute>
  501.                         <xsl:call-template name="border-attributes">
  502.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-top" />
  503.                         </xsl:call-template>
  504.                     </xsl:element>
  505.                 </xsl:if>
  506.                 <!-- write out all table border  -->
  507.                 <xsl:if test="$styleProperties/@fo:border and not($styleProperties/@fo:border = 'none')">
  508.                     <xsl:element name="Border">
  509.                         <xsl:attribute name="ss:Position">Bottom</xsl:attribute>
  510.                         <xsl:call-template name="border-attributes">
  511.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  512.                         </xsl:call-template>
  513.                     </xsl:element>
  514.                     <xsl:element name="Border">
  515.                         <xsl:attribute name="ss:Position">Left</xsl:attribute>
  516.                         <xsl:call-template name="border-attributes">
  517.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  518.                         </xsl:call-template>
  519.                     </xsl:element>
  520.                     <xsl:element name="Border">
  521.                         <xsl:attribute name="ss:Position">Right</xsl:attribute>
  522.                         <xsl:call-template name="border-attributes">
  523.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  524.                         </xsl:call-template>
  525.                     </xsl:element>
  526.                     <xsl:element name="Border">
  527.                         <xsl:attribute name="ss:Position">Top</xsl:attribute>
  528.                         <xsl:call-template name="border-attributes">
  529.                             <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  530.                         </xsl:call-template>
  531.                     </xsl:element>
  532.                 </xsl:if>
  533.             </xsl:element>
  534.         </xsl:if>
  535.     </xsl:template>
  536.  
  537.  
  538.     <xsl:template name="border-attributes">
  539.         <xsl:param name="border_properties" />
  540.  
  541.         <xsl:variable name="border-width">
  542.             <xsl:call-template name="convert2cm">
  543.                 <xsl:with-param name="value" select="substring-before($border_properties, ' ')" />
  544.             </xsl:call-template>
  545.         </xsl:variable>
  546.         <xsl:variable name="border-style" select="substring-before(substring-after($border_properties, ' '), ' ')" />
  547.         <xsl:variable name="border-color" select="substring-after(substring-after($border_properties, ' '), ' ')" />
  548. <!--
  549.         <xsl:message>border-width:<xsl:value-of select="$border-width" /></xsl:message>
  550.         <xsl:message>border-style:<xsl:value-of select="$border-style" /></xsl:message>
  551.         <xsl:message>border-color:<xsl:value-of select="$border-color" /></xsl:message>
  552.  -->
  553.  
  554.         <!-- Dash, Dot, DashDot, DashDotDot, SlantDashDot are not supported yet -->
  555.         <xsl:attribute name="ss:LineStyle">
  556.             <xsl:choose>
  557.                 <xsl:when test="$border-style = 'none'">None</xsl:when>
  558.                 <xsl:when test="$border-style = 'double'">Double</xsl:when>
  559.                 <xsl:otherwise>Continuous</xsl:otherwise>
  560.             </xsl:choose>
  561.         </xsl:attribute>
  562.  
  563.         <xsl:attribute name="ss:Weight">
  564.             <xsl:choose>
  565.                 <!-- 0: Hairline -->
  566.                 <xsl:when test="$border-width <= 0.002">0</xsl:when>
  567.                 <!-- 1: Thin -->
  568.                 <xsl:when test="$border-width <= 0.035">1</xsl:when>
  569.                 <!-- 2: Medium -->
  570.                 <xsl:when test="$border-width <= 0.088">2</xsl:when>
  571.                 <!-- 3: Thick -->
  572.                 <xsl:otherwise>3</xsl:otherwise>
  573.             </xsl:choose>
  574.         </xsl:attribute>
  575.  
  576.         <xsl:attribute name="ss:Color">
  577.             <xsl:choose>
  578.                 <xsl:when test="$border-color"><xsl:value-of select="$border-color" /></xsl:when>
  579.                 <xsl:otherwise>Automatic</xsl:otherwise>
  580.             </xsl:choose>
  581.         </xsl:attribute>
  582.     </xsl:template>
  583.  
  584.  
  585.     <xsl:template name="Font">
  586.         <xsl:param name="styleProperties" />
  587.         <xsl:param name="styleParentName" />
  588.  
  589.         <!-- An empty font element, might overwrite parents setting by
  590.              the default attributes -->
  591.         <xsl:if test="$styleProperties/@style:font-weight or
  592.                       $styleProperties/@fo:color or
  593.                       $styleProperties/@style:font-name or
  594.                       $styleProperties/@fo:font-style or
  595.                       $styleProperties/@style:text-outline or
  596.                       $styleProperties/@style:text-shadow or
  597.                       $styleProperties/@style:font-size or
  598.                       $styleProperties/@style:text-line-through-style or
  599.                       $styleProperties/@style:text-underline-type or
  600.                       $styleProperties/@style:text-underline-style or
  601.                       $styleProperties/@style:text-position">
  602.  
  603.  
  604.             <xsl:element name="Font">
  605.                 <xsl:call-template name="getParentBold">
  606.                     <xsl:with-param name="styleProperties" select="$styleProperties" />
  607.                     <xsl:with-param name="styleParentName" select="$styleParentName" />
  608.                 </xsl:call-template>
  609.                 <xsl:if test="$styleProperties/@fo:color">
  610.                     <xsl:attribute name="ss:Color"><xsl:value-of select="$styleProperties/@fo:color" /></xsl:attribute>
  611.                 </xsl:if>
  612.                 <xsl:if test="$styleProperties/@style:font-name">
  613.                     <xsl:attribute name="ss:FontName"><xsl:value-of select="$styleProperties/@style:font-name" /></xsl:attribute>
  614.                 </xsl:if>
  615.                 <xsl:if test="$styleProperties/@fo:font-style = 'italic'">
  616.                     <xsl:attribute name="ss:Italic">1</xsl:attribute>
  617.                 </xsl:if>
  618.                 <xsl:if test="$styleProperties/@style:text-outline = 'true'">
  619.                     <xsl:attribute name="ss:Outline">1</xsl:attribute>
  620.                 </xsl:if>
  621.                 <xsl:if test="$styleProperties/@style:text-shadow = 'shadow'">
  622.                     <xsl:attribute name="ss:Shadow">1</xsl:attribute>
  623.                 </xsl:if>
  624.                 <xsl:if test="$styleProperties/@fo:font-size">
  625.                     <xsl:attribute name="ss:Size">
  626.                         <xsl:call-template name="convert2pt">
  627.                             <xsl:with-param name="value" select="$styleProperties/@fo:font-size" />
  628.                         </xsl:call-template>
  629.                     </xsl:attribute>
  630.                 </xsl:if>
  631.                 <xsl:if test="$styleProperties/@style:text-line-through-style and $styleProperties/@style:text-line-through-style != 'none'">
  632.                     <xsl:attribute name="ss:StrikeThrough">1</xsl:attribute>
  633.                 </xsl:if>
  634.                 <xsl:if test="($styleProperties/@style:text-underline-type and $styleProperties/@style:text-underline-type != 'none') or
  635.                               ($styleProperties/@style:text-underline-style and $styleProperties/@style:text-underline-style != 'none')">
  636.                     <xsl:attribute name="ss:Underline">
  637.                         <xsl:choose>
  638.                             <xsl:when test="$styleProperties/@style:text-underline-type = 'double'">Double</xsl:when>
  639.                             <xsl:otherwise>Single</xsl:otherwise>
  640.                         </xsl:choose>
  641.                     </xsl:attribute>
  642.                 </xsl:if>
  643.                 <xsl:if test="$styleProperties/@style:text-position">
  644.                     <xsl:attribute name="ss:VerticalAlign">
  645.                         <xsl:choose>
  646.                             <xsl:when test="substring-before($styleProperties/@style:text-position, '% ') > 0">Superscript</xsl:when>
  647.                             <xsl:otherwise>Subscript</xsl:otherwise>
  648.                         </xsl:choose>
  649.                     </xsl:attribute>
  650.                 </xsl:if>
  651.             </xsl:element>
  652.         </xsl:if>
  653.     </xsl:template>
  654.  
  655.     <xsl:template name="Interior">
  656.         <xsl:param name="styleProperties" />
  657.         <xsl:if test="$styleProperties/@fo:background-color and not($styleProperties/@fo:background-color = 'transparent')">
  658.             <xsl:element name="Interior">
  659.                 <xsl:attribute name="ss:Color">
  660.                     <xsl:value-of select="$styleProperties/@fo:background-color" />
  661.                 </xsl:attribute>
  662.                 <!-- Background color (i.e. Interior/ss:Color) not shown without ss:Pattern (or with 'none')
  663.                 Therefore a default is set -->
  664.                 <xsl:attribute name="ss:Pattern">Solid</xsl:attribute>
  665.             </xsl:element>
  666.         </xsl:if>
  667.     </xsl:template>
  668.  
  669.     <!-- Excel issue workaround: <Font ss:Bold="1"> is not inherited -->
  670.     <xsl:template name="getParentBold">
  671.         <xsl:param name="styleProperties" />
  672.         <xsl:param name="styleParentName" />
  673.         <xsl:param name="styleName" />
  674.  
  675.         <xsl:if test="$styleParentName and $styleParentName != $styleName">
  676.             <xsl:choose>
  677.                 <xsl:when test="$styleProperties/@fo:font-weight = 'bold'">
  678.                     <xsl:attribute name="ss:Bold">1</xsl:attribute>
  679.                 </xsl:when>
  680.                 <xsl:otherwise>
  681.                     <xsl:call-template name="getParentBold">
  682.                         <xsl:with-param name="styleProperties" select="key('styles', $styleParentName)/*" />
  683.                         <xsl:with-param name="styleParentName" select="key('styles', $styleParentName)/@style:parent-style-name" />
  684.                         <xsl:with-param name="styleName" select="$styleParentName" />
  685.                     </xsl:call-template>
  686.                 </xsl:otherwise>
  687.             </xsl:choose>
  688.         </xsl:if>
  689.     </xsl:template>
  690.  
  691. </xsl:stylesheet>
  692.