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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.   DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5.   
  6.   Copyright 2000, 2010 Oracle and/or its affiliates.
  7.  
  8.   OpenOffice.org - a multi-platform office productivity suite
  9.  
  10.   This file is part of OpenOffice.org.
  11.  
  12.   OpenOffice.org is free software: you can redistribute it and/or modify
  13.   it under the terms of the GNU Lesser General Public License version 3
  14.   only, as published by the Free Software Foundation.
  15.  
  16.   OpenOffice.org is distributed in the hope that it will be useful,
  17.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.   GNU Lesser General Public License version 3 for more details
  20.   (a copy is included in the LICENSE file that accompanied this code).
  21.  
  22.   You should have received a copy of the GNU Lesser General Public License
  23.   version 3 along with OpenOffice.org.  If not, see
  24.   <http://www.openoffice.org/license.html>
  25.   for a copy of the LGPLv3 License.
  26.  
  27. -->
  28. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 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:SL="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="aml dt html o ss SL v w10 w wx x">
  29.     <!--+++++ INCLUDED XSL MODULES +++++-->
  30.     <!-- helper collection, to convert measures (e.g. inch to pixel using DPI (dots per inch) parameter)-->
  31.     <xsl:import href="../../common/measure_conversion.xsl"/>
  32.     <xsl:output indent="no" version="1.0" encoding="UTF-8" method="xml"/>
  33.     <xsl:template match="/">
  34.         <office:document office:mimetype="application/vnd.oasis.opendocument.spreadsheet" office:version="1.0">
  35.             <xsl:apply-templates select="ss:Workbook/o:DocumentProperties"/>
  36.             <xsl:apply-templates select="ss:Workbook/x:ExcelWorkbook"/>
  37.             <xsl:call-template name="font-declaration"/>
  38.             <xsl:apply-templates select="ss:Workbook/ss:Worksheet[1]" mode="styles"/>
  39.             <xsl:element name="office:body">
  40.                 <xsl:element name="office:spreadsheet">
  41.                     <xsl:call-template name="set-calculation"/>
  42.                     <!-- for DataValidation -->
  43.                     <xsl:if test="ss:Workbook/ss:Worksheet/x:DataValidation">
  44.                         <xsl:element name="table:content-validations">
  45.                             <xsl:apply-templates select="ss:Workbook/ss:Worksheet/x:DataValidation"/>
  46.                         </xsl:element>
  47.                     </xsl:if>
  48.                     <xsl:apply-templates select="ss:Workbook/ss:Worksheet"/>
  49.                     <xsl:call-template name="Names"/>
  50.                     <xsl:element name="table:database-ranges">
  51.                         <!-- these descriptions located in every Worksheet in Excel, but at the same path in Calc -->
  52.                         <xsl:for-each select="ss:Workbook/ss:Worksheet">
  53.                             <xsl:apply-templates select="./x:Sorting"/>
  54.                             <xsl:apply-templates select="./x:AutoFilter"/>
  55.                             <!-- for Advanced Filter.the position is same as AutoFilter -->
  56.                             <xsl:if test="./ss:Names/ss:NamedRange and ./ss:Names/ss:NamedRange/@ss:Name='_FilterDatabase'">
  57.                                 <xsl:call-template name="transform-advanced-filter">
  58.                                     <xsl:with-param name="target-value" select="substring-after(./ss:Names/ss:NamedRange[@ss:Name='_FilterDatabase']/@ss:RefersTo, '=')"/>
  59.                                     <xsl:with-param name="condition-pos" select="substring-after(./ss:Names/ss:NamedRange[@ss:Name='Criteria']/@ss:RefersTo, '=')"/>
  60.                                 </xsl:call-template>
  61.                             </xsl:if>
  62.                         </xsl:for-each>
  63.                     </xsl:element>
  64.                 </xsl:element>
  65.             </xsl:element>
  66.         </office:document>
  67.     </xsl:template>
  68.     <xsl:template match="o:DocumentProperties">
  69.         <office:meta>
  70.             <meta:generator>Microsoft Excel 2003</meta:generator>
  71.             <xsl:if test="o:Title">
  72.                 <dc:title>
  73.                     <xsl:value-of select="o:Title"/>
  74.                 </dc:title>
  75.             </xsl:if>
  76.             <xsl:if test="o:Description">
  77.                 <dc:description>
  78.                     <xsl:value-of select="o:Description"/>
  79.                 </dc:description>
  80.             </xsl:if>
  81.             <xsl:if test="o:Subject">
  82.                 <dc:subject>
  83.                     <xsl:value-of select="o:Subject"/>
  84.                 </dc:subject>
  85.             </xsl:if>
  86.             <xsl:if test="o:Author">
  87.                 <meta:initial-creator>
  88.                     <xsl:value-of select="o:Author"/>
  89.                 </meta:initial-creator>
  90.             </xsl:if>
  91.             <xsl:if test="o:Created">
  92.                 <meta:creation-date>
  93.                     <xsl:value-of select="substring-before( o:Created, 'Z')"/>
  94.                 </meta:creation-date>
  95.             </xsl:if>
  96.             <xsl:if test="o:LastAuthor">
  97.                 <dc:creator>
  98.                     <xsl:value-of select="o:LastAuthor"/>
  99.                 </dc:creator>
  100.             </xsl:if>
  101.             <xsl:if test="o:LastSaved">
  102.                 <dc:date>
  103.                     <xsl:value-of select="substring-before( o:LastSaved, 'Z')"/>
  104.                 </dc:date>
  105.             </xsl:if>
  106.             <!--
  107.             <meta:printed-by/>
  108.             <meta:print-date/>
  109.                 <!~~ removed in OASIS Open Office XML
  110.                 <meta:keywords>
  111.                     <meta:keyword>
  112.                         <xsl:value-of select="o:Keywords" />
  113.                     </meta:keyword>
  114.                 </meta:keywords>
  115.                 ~~>
  116.             <dc:language/>
  117.             -->
  118.             <xsl:if test="o:Revision">
  119.                 <meta:editing-cycles>
  120.                     <xsl:value-of select="o:Revision"/>
  121.                 </meta:editing-cycles>
  122.             </xsl:if>
  123.             <xsl:if test="o:TotalTime">
  124.                 <meta:editing-duration>
  125.                     <xsl:value-of select="concat('PT', floor(o:TotalTime div 60), 'H', o:TotalTime mod 60, 'M0S')"/>
  126.                 </meta:editing-duration>
  127.             </xsl:if>
  128.             <xsl:if test="o:Category">
  129.                 <meta:user-defined meta:name="Category">
  130.                     <xsl:value-of select="o:Category"/>
  131.                 </meta:user-defined>
  132.             </xsl:if>
  133.             <xsl:if test="o:Manager">
  134.                 <meta:user-defined meta:name="Manager">
  135.                     <xsl:value-of select="o:Manager"/>
  136.                 </meta:user-defined>
  137.             </xsl:if>
  138.             <xsl:if test="o:Company">
  139.                 <meta:user-defined meta:name="Company">
  140.                     <xsl:value-of select="o:Company"/>
  141.                 </meta:user-defined>
  142.             </xsl:if>
  143.             <xsl:if test="o:Version">
  144.                 <meta:user-defined meta:name="Version">
  145.                     <xsl:value-of select="o:Version"/>
  146.                 </meta:user-defined>
  147.             </xsl:if>
  148.             <xsl:if test="o:HyperlinkBase">
  149.                 <meta:user-defined meta:name="HyperlinkBase">
  150.                     <xsl:value-of select="o:HyperlinkBase"/>
  151.                 </meta:user-defined>
  152.             </xsl:if>
  153.             <xsl:apply-templates select="../o:CustomDocumentProperties"/>
  154.             <!--Note:  <meta:document-statistic/>-->
  155.         </office:meta>
  156.     </xsl:template>
  157.     <xsl:template match="o:CustomDocumentProperties">
  158.         <xsl:for-each select="node()[@dt:dt]">
  159.             <meta:user-defined meta:name="{name()}">
  160.                 <xsl:value-of select="."/>
  161.             </meta:user-defined>
  162.         </xsl:for-each>
  163.     </xsl:template>
  164.     <xsl:template match="x:ExcelWorkbook">
  165.         <!-- Configuration in 'ooo:view-settings' and 'ooo:configuration-settings'
  166.         "GridColor"
  167.         "HasColumnRowHeaders"
  168.         "HasSheetTabs"
  169.         "IsOutlineSymbolsSet"
  170.         "IsRasterAxisSynchronized"
  171.         "IsSnapToRaster"
  172.         "RasterIsVisible"
  173.         "RasterResolutionX"
  174.         "RasterResolutionY"
  175.         "RasterSubdivisionX"
  176.         "RasterSubdivisionY"
  177.         "ShowGrid"
  178.         "ShowNotes"
  179.         "ShowPageBreaks"
  180.         "ShowZeroValues"
  181.         -->
  182.         <xsl:variable name="sharedConfiguration">
  183.             <xsl:if test="../ss:Worksheet/x:WorksheetOptions/x:GridlineColor">
  184.                 <config:config-item config:name="GridColor" config:type="long">
  185.                     <xsl:variable name="temp-code" select="substring-after(normalize-space(../ss:Worksheet/x:WorksheetOptions/x:GridlineColor), '#')"/>
  186.                     <xsl:variable name="temp-value">
  187.                         <xsl:call-template name="hex2decimal">
  188.                             <xsl:with-param name="hex-number" select="$temp-code"/>
  189.                             <xsl:with-param name="index" select="1"/>
  190.                             <xsl:with-param name="str-length" select="string-length($temp-code)"/>
  191.                             <xsl:with-param name="last-value" select="0"/>
  192.                         </xsl:call-template>
  193.                     </xsl:variable>
  194.                     <xsl:value-of select="$temp-value"/>
  195.                 </config:config-item>
  196.             </xsl:if>
  197.             <xsl:choose>
  198.                 <xsl:when test="../ss:Worksheet/x:WorksheetOptions/x:DoNotDisplayHeadings">
  199.                     <config:config-item config:name="HasColumnRowHeaders" config:type="boolean">false</config:config-item>
  200.                 </xsl:when>
  201.                 <xsl:otherwise>
  202.                     <config:config-item config:name="HasColumnRowHeaders" config:type="boolean">true</config:config-item>
  203.                 </xsl:otherwise>
  204.             </xsl:choose>
  205.             <xsl:choose>
  206.                 <xsl:when test="x:HideWorkbookTabs">
  207.                     <config:config-item config:name="HasSheetTabs" config:type="boolean">false</config:config-item>
  208.                 </xsl:when>
  209.                 <xsl:otherwise>
  210.                     <config:config-item config:name="HasSheetTabs" config:type="boolean">true</config:config-item>
  211.                 </xsl:otherwise>
  212.             </xsl:choose>
  213.             <xsl:choose>
  214.             <xsl:when test="../ss:Worksheet/x:WorksheetOptions/x:DoNotDisplayOutline">
  215.                 <config:config-item config:name="IsOutlineSymbolsSet" config:type="boolean">false</config:config-item>
  216.             </xsl:when>
  217.                 <xsl:otherwise>
  218.                 <config:config-item config:name="IsOutlineSymbolsSet" config:type="boolean">true</config:config-item>
  219.                 </xsl:otherwise>
  220.             </xsl:choose>
  221.             <xsl:choose>
  222.                 <xsl:when test="../ss:Worksheet/x:WorksheetOptions/x:DoNotDisplayGridlines">
  223.                     <config:config-item config:name="ShowGrid" config:type="boolean">false</config:config-item>
  224.                 </xsl:when>
  225.                 <xsl:otherwise>
  226.                     <config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item>
  227.                 </xsl:otherwise>
  228.             </xsl:choose>
  229.             <xsl:choose>
  230.                 <xsl:when test="../ss:Worksheet/x:WorksheetOptions/x:DoNotDisplayZeros">
  231.                     <config:config-item config:name="ShowZeroValues" config:type="boolean">false</config:config-item>
  232.                 </xsl:when>
  233.                 <xsl:otherwise>
  234.                     <config:config-item config:name="ShowZeroValues" config:type="boolean">true</config:config-item>
  235.                 </xsl:otherwise>
  236.             </xsl:choose>
  237.         </xsl:variable>
  238.         <office:settings>
  239.             <config:config-item-set config:name="ooo:view-settings">
  240.                 <config:config-item config:type="int" config:name="VisibleAreaTop">
  241.                     <xsl:value-of select="x:WindowTopY"/>
  242.                 </config:config-item>
  243.                 <config:config-item config:name="VisibleAreaLeft" config:type="int">
  244.                     <xsl:value-of select="x:WindowTopX"/>
  245.                 </config:config-item>
  246.                 <config:config-item config:name="VisibleAreaWidth" config:type="int">
  247.                     <xsl:value-of select="x:WindowWidth"/>
  248.                 </config:config-item>
  249.                 <config:config-item config:name="VisibleAreaHeight" config:type="int">
  250.                     <xsl:value-of select="x:WindowHeight"/>
  251.                 </config:config-item>
  252.                 <xsl:variable name="ratio" select="15"/>
  253.                 <config:config-item-map-indexed config:name="Views">
  254.                     <config:config-item-map-entry>
  255.                         <config:config-item config:name="ViewId" config:type="string">View1</config:config-item>
  256.                         <config:config-item-map-named config:name="Tables">
  257.                             <!--  The panes of a table is like 3   |   1   or  3 |  1, or   3 , while 3 is the default one. glu
  258.                                                      - - - -        - - -
  259.                                                     2  |  0         2    -->
  260.                             <xsl:for-each select="../ss:Worksheet">
  261.                                 <config:config-item-map-entry config:name="{@ss:Name}">
  262.                                     <xsl:variable name="active-pane">
  263.                                         <xsl:choose>
  264.                                             <xsl:when test="x:WorksheetOptions/x:ActivePane">
  265.                                                 <xsl:value-of select="x:WorksheetOptions/x:ActivePane"/>
  266.                                             </xsl:when>
  267.                                             <xsl:otherwise/>
  268.                                         </xsl:choose>
  269.                                     </xsl:variable>
  270.                                     <xsl:if test="not( $active-pane = '' ) and ( x:WorksheetOptions/x:SplitVertical or x:WorksheetOptions/x:SplitHorizontal )">
  271.                                         <config:config-item config:name="ActiveSplitRange" config:type="short">
  272.                                             <xsl:choose>
  273.                                                 <xsl:when test="x:WorksheetOptions/x:SplitVertical and not(x:WorksheetOptions/x:SplitHorizontal)">
  274.                                                     <xsl:value-of select="'3'"/>
  275.                                                 </xsl:when>
  276.                                                 <xsl:otherwise>
  277.                                                     <xsl:value-of select="$active-pane"/>
  278.                                                 </xsl:otherwise>
  279.                                             </xsl:choose>
  280.                                         </config:config-item>
  281.                                     </xsl:if>
  282.                                     <xsl:choose>
  283.                                         <xsl:when test="not( $active-pane = '')">
  284.                                             <config:config-item config:name="CursorPositionX" config:type="int">
  285.                                                 <xsl:value-of select="x:WorksheetOptions/x:Panes/x:Pane[x:Number = $active-pane ]/x:ActiveCol"/>
  286.                                             </config:config-item>
  287.                                             <config:config-item config:name="CursorPositionY" config:type="int">
  288.                                                 <xsl:value-of select="x:WorksheetOptions/x:Panes/x:Pane[x:Number = $active-pane ]/x:ActiveRow"/>
  289.                                             </config:config-item>
  290.                                         </xsl:when>
  291.                                         <xsl:otherwise>
  292.                                             <config:config-item config:name="CursorPositionX" config:type="int">
  293.                                                 <xsl:value-of select="x:WorksheetOptions/x:Panes/x:Pane/x:ActiveCol"/>
  294.                                             </config:config-item>
  295.                                             <config:config-item config:name="CursorPositionY" config:type="int">
  296.                                                 <xsl:value-of select="x:WorksheetOptions/x:Panes/x:Pane/x:ActiveRow"/>
  297.                                             </config:config-item>
  298.                                         </xsl:otherwise>
  299.                                     </xsl:choose>
  300.                                     <xsl:variable name="position-left">
  301.                                         <xsl:choose>
  302.                                             <xsl:when test="x:WorksheetOptions/x:LeftColumnVisible">
  303.                                                 <xsl:value-of select="x:WorksheetOptions/x:LeftColumnVisible"/>
  304.                                             </xsl:when>
  305.                                             <xsl:otherwise>0</xsl:otherwise>
  306.                                         </xsl:choose>
  307.                                     </xsl:variable>
  308.                                     <config:config-item config:name="PositionLeft" config:type="int">
  309.                                         <xsl:value-of select="$position-left"/>
  310.                                     </config:config-item>
  311.                                     <xsl:variable name="position-top">
  312.                                         <xsl:choose>
  313.                                             <xsl:when test="x:WorksheetOptions/x:TopRowVisible">
  314.                                                 <xsl:value-of select="x:WorksheetOptions/x:TopRowVisible"/>
  315.                                             </xsl:when>
  316.                                             <xsl:otherwise>0</xsl:otherwise>
  317.                                         </xsl:choose>
  318.                                     </xsl:variable>
  319.                                     <xsl:choose>
  320.                                         <xsl:when test="x:WorksheetOptions/x:SplitVertical and not(x:WorksheetOptions/x:SplitHorizontal)">
  321.                                             <config:config-item config:name="PositionBottom" config:type="int">
  322.                                                 <xsl:value-of select="$position-top"/>
  323.                                             </config:config-item>
  324.                                         </xsl:when>
  325.                                         <xsl:otherwise>
  326.                                             <config:config-item config:name="PositionTop" config:type="int">
  327.                                                 <xsl:value-of select="$position-top"/>
  328.                                             </config:config-item>
  329.                                         </xsl:otherwise>
  330.                                     </xsl:choose>
  331.                                     <xsl:choose>
  332.                                         <xsl:when test="x:WorksheetOptions/x:SplitVertical">
  333.                                             <config:config-item config:name="HorizontalSplitMode" config:type="short">
  334.                                                 <xsl:choose>
  335.                                                     <xsl:when test="x:WorksheetOptions/x:FreezePanes">2</xsl:when>
  336.                                                     <xsl:otherwise>1</xsl:otherwise>
  337.                                                 </xsl:choose>
  338.                                             </config:config-item>
  339.                                             <config:config-item config:name="HorizontalSplitPosition" config:type="int">
  340.                                                 <xsl:choose>
  341.                                                     <xsl:when test="x:WorksheetOptions/x:FreezePanes">
  342.                                                         <xsl:value-of select="x:WorksheetOptions/x:SplitVertical + $position-left"/>
  343.                                                     </xsl:when>
  344.                                                     <xsl:otherwise>
  345.                                                         <xsl:value-of select="floor( x:WorksheetOptions/x:SplitVertical div $ratio )"/>
  346.                                                     </xsl:otherwise>
  347.                                                 </xsl:choose>
  348.                                             </config:config-item>
  349.                                             <config:config-item config:name="PositionRight" config:type="int">
  350.                                                 <xsl:value-of select="x:WorksheetOptions/x:LeftColumnRightPane"/>
  351.                                             </config:config-item>
  352.                                         </xsl:when>
  353.                                         <xsl:otherwise>
  354.                                             <config:config-item config:name="HorizontalSplitMode" config:type="short">0</config:config-item>
  355.                                         </xsl:otherwise>
  356.                                     </xsl:choose>
  357.                                     <xsl:choose>
  358.                                         <xsl:when test="x:WorksheetOptions/x:SplitHorizontal">
  359.                                             <config:config-item config:name="VerticalSplitMode" config:type="short">
  360.                                                 <xsl:choose>
  361.                                                     <xsl:when test="x:WorksheetOptions/x:FreezePanes">2</xsl:when>
  362.                                                     <xsl:otherwise>1</xsl:otherwise>
  363.                                                 </xsl:choose>
  364.                                             </config:config-item>
  365.                                             <config:config-item config:name="VerticalSplitPosition" config:type="int">
  366.                                                 <xsl:choose>
  367.                                                     <xsl:when test="x:WorksheetOptions/x:FreezePanes">
  368.                                                         <xsl:value-of select="x:WorksheetOptions/x:SplitHorizontal + $position-top"/>
  369.                                                     </xsl:when>
  370.                                                     <xsl:otherwise>
  371.                                                         <xsl:value-of select="floor( x:WorksheetOptions/x:SplitHorizontal div $ratio )"/>
  372.                                                     </xsl:otherwise>
  373.                                                 </xsl:choose>
  374.                                             </config:config-item>
  375.                                             <config:config-item config:name="PositionBottom" config:type="int">
  376.                                                 <xsl:value-of select="x:WorksheetOptions/x:TopRowBottomPane"/>
  377.                                             </config:config-item>
  378.                                         </xsl:when>
  379.                                         <xsl:otherwise>
  380.                                             <config:config-item config:name="VerticalSplitMode" config:type="short">0</config:config-item>
  381.                                         </xsl:otherwise>
  382.                                     </xsl:choose>
  383.                                     <xsl:copy-of select="$sharedConfiguration"/>
  384.                                     <xsl:if test="x:WorksheetOptions/x:TabColorIndex">
  385.                                         <config:config-item config:name="TabColor" config:type="int">
  386.                                             <xsl:variable name="temp-value">
  387.                                                 <xsl:call-template name="colorindex2decimal">
  388.                                                     <xsl:with-param name="colorindex" select="x:WorksheetOptions/x:TabColorIndex"/>
  389.                                                 </xsl:call-template>
  390.                                             </xsl:variable>
  391.                                             <xsl:value-of select="$temp-value"/>
  392.                                         </config:config-item>
  393.                                     </xsl:if>
  394.                                 </config:config-item-map-entry>
  395.                             </xsl:for-each>
  396.                         </config:config-item-map-named>
  397.                         <xsl:if test="x:ActiveSheet">
  398.                             <config:config-item config:name="ActiveTable" config:type="string">
  399.                                 <xsl:value-of select="../ss:Worksheet[/ss:Workbook/x:ExcelWorkbook/x:ActiveSheet+1]/@ss:Name"/>
  400.                             </config:config-item>
  401.                         </xsl:if>
  402.                         <config:config-item config:name="HorizontalScrollbarWidth" config:type="int">555</config:config-item>
  403.                         <!-- following are some table setting from Excel, but transformed to global setting, due to limit of Calc -->
  404.                         <xsl:if test="../ss:Worksheet/x:WorksheetOptions/x:ShowPageBreakZoom">
  405.                             <config:config-item config:name="ShowPageBreakPreview" config:type="boolean">true</config:config-item>
  406.                         </xsl:if>
  407.                         <xsl:if test="../ss:Worksheet/x:WorksheetOptions/x:PageBreakZoom">
  408.                             <config:config-item config:name="PageViewZoomValue" config:type="int">
  409.                                 <xsl:value-of select="../ss:Worksheet/x:WorksheetOptions/x:PageBreakZoom"/>
  410.                             </config:config-item>
  411.                         </xsl:if>
  412.                         <xsl:if test="../ss:Worksheet/x:WorksheetOptions/x:Zoom">
  413.                             <config:config-item config:name="ZoomValue" config:type="int">
  414.                                 <xsl:value-of select="../ss:Worksheet/x:WorksheetOptions/x:Zoom"/>
  415.                             </config:config-item>
  416.                         </xsl:if>
  417.                         <!-- several properties are not saved in Calc XML but setting, whereas vice versa. :( So just to be expanded, glu -->
  418.                     </config:config-item-map-entry>
  419.                 </config:config-item-map-indexed>
  420.             </config:config-item-set>
  421.             <config:config-item-set config:name="ooo:configuration-settings">
  422.                 <xsl:copy-of select="$sharedConfiguration"/>
  423.             </config:config-item-set>
  424.             <!-- printer setting, not finished yet. glu
  425.             <config:config-item-set config:name="configuration-settings" />
  426.             -->
  427.         </office:settings>
  428.     </xsl:template>
  429.     <!-- Key all attributes with the same name and same value -->
  430.     <xsl:key name="same-named-font" match="/ss:Workbook/ss:Styles/ss:Style/ss:Font" use="concat(@ss:FontName, @x:Family)"/>
  431.     <xsl:key name="same-named-face" match="/ss:Workbook/ss:Worksheet/ss:Table/ss:Row/ss:Cell//html:Font[@html:Face]" use="concat(@html:Face, @x:Family)"/>
  432.     <xsl:template name="font-declaration">
  433.         <office:font-face-decls>
  434.             <xsl:if test="/ss:Workbook/ss:Styles/ss:Style/ss:Font">
  435.                 <xsl:for-each select="/ss:Workbook/ss:Styles/ss:Style/ss:Font[ generate-id(.) = generate-id(key('same-named-font', concat(@ss:FontName, @x:Family))[1])]">
  436.                     <xsl:sort select="name()"/>
  437.                     <xsl:element name="style:font-face">
  438.                         <xsl:if test="@ss:FontName">
  439.                             <xsl:attribute name="style:name">
  440.                                 <xsl:value-of select="@ss:FontName"/>
  441.                             </xsl:attribute>
  442.                             <xsl:attribute name="svg:font-family">
  443.                                 <xsl:value-of select="@ss:FontName"/>
  444.                             </xsl:attribute>
  445.                         </xsl:if>
  446.                         <xsl:if test="@x:Family">
  447.                             <xsl:attribute name="style:font-family-generic">
  448.                                 <xsl:call-template name="translate-font-family-generic">
  449.                                     <xsl:with-param name="family" select="@x:Family"/>
  450.                                 </xsl:call-template>
  451.                             </xsl:attribute>
  452.                         </xsl:if>
  453.                     </xsl:element>
  454.                 </xsl:for-each>
  455.             </xsl:if>
  456.             <xsl:for-each select="/ss:Workbook/ss:Worksheet/ss:Table/ss:Row/ss:Cell/descendant::html:Font[@html:Face][ generate-id(.) = generate-id(key('same-named-face', concat(@html:Face, @x:Family))[1])]">
  457.                 <xsl:sort select="name()"/>
  458.                 <xsl:element name="style:font-face">
  459.                     <xsl:attribute name="style:name">
  460.                         <xsl:value-of select="@html:Face"/>
  461.                     </xsl:attribute>
  462.                     <xsl:attribute name="svg:font-family">
  463.                         <xsl:value-of select="@html:Face"/>
  464.                     </xsl:attribute>
  465.                     <xsl:attribute name="style:font-family-generic">
  466.                         <xsl:call-template name="translate-font-family-generic">
  467.                             <xsl:with-param name="family" select="@x:Family"/>
  468.                         </xsl:call-template>
  469.                     </xsl:attribute>
  470.                 </xsl:element>
  471.             </xsl:for-each>
  472.         </office:font-face-decls>
  473.     </xsl:template>
  474.     <xsl:template name="translate-font-family-generic">
  475.         <xsl:param name="family"/>
  476.         <xsl:choose>
  477.             <xsl:when test="$family='Swiss'">swiss</xsl:when>
  478.             <xsl:when test="$family='Modern'">modern</xsl:when>
  479.             <xsl:when test="$family='Roman'">roman</xsl:when>
  480.             <xsl:when test="$family='Script'">script</xsl:when>
  481.             <xsl:when test="$family='Decorative'">decorative</xsl:when>
  482.             <!-- change 'System' to 'Automatic' for Excel -->
  483.             <xsl:when test="$family='Automatic'">system</xsl:when>
  484.             <xsl:otherwise>system</xsl:otherwise>
  485.         </xsl:choose>
  486.     </xsl:template>
  487.     <xsl:template match="ss:Workbook/ss:Worksheet" mode="styles">
  488.         <office:styles>
  489.             <xsl:apply-templates select="/ss:Workbook/ss:Styles/ss:Style[@ss:Name]"/>
  490.             <xsl:apply-templates select="/ss:Workbook/ss:Styles/ss:Style/ss:NumberFormat[@ss:Format]"/>
  491.             <!-- if ConditionalFormatting exists,it should generate some styles for style:style -->
  492.             <xsl:if test="/ss:Workbook/ss:Worksheet/x:ConditionalFormatting">
  493.                 <xsl:call-template name="CondFormat_office_style"/>
  494.             </xsl:if>
  495.         </office:styles>
  496.         <office:automatic-styles>
  497.             <xsl:apply-templates select="/ss:Workbook/ss:Worksheet/ss:Table"/>
  498.             <xsl:apply-templates select="/ss:Workbook/ss:Styles/ss:Style[not(@ss:Name)]"/>
  499.             <xsl:apply-templates select="/ss:Workbook/ss:Styles/ss:Style/ss:Font[@ss:VerticalAlign]"/>
  500.             <!-- applying to ss:Data (but *, as also ss:Data nested in ss:Comments -->
  501.             <xsl:apply-templates select="/ss:Workbook/ss:Worksheet/ss:Table/ss:Row/ss:Cell/*[descendant-or-self::*[namespace-uri()='http://www.w3.org/TR/REC-html40']]"/>
  502.             <xsl:apply-templates select="/ss:Workbook/ss:Worksheet/x:WorksheetOptions/x:PageSetup//@x:Data"/>
  503.             <!-- if ConditionalFormatting exists,transforing the styles -->
  504.             <xsl:if test="/ss:Workbook/ss:Worksheet/x:ConditionalFormatting">
  505.                 <xsl:call-template name="CondFormat_automatic_style"/>
  506.             </xsl:if>
  507.             <xsl:call-template name="create-page-master">
  508.                 <xsl:with-param name="worksheetoptions" select="/ss:Workbook/ss:Worksheet/x:WorksheetOptions"/>
  509.             </xsl:call-template>
  510.         </office:automatic-styles>
  511.         <office:master-styles>
  512.             <xsl:call-template name="create-master-styles">
  513.                 <xsl:with-param name="worksheetoptions" select="/ss:Workbook/ss:Worksheet/x:WorksheetOptions"/>
  514.             </xsl:call-template>
  515.         </office:master-styles>
  516.     </xsl:template>
  517.     <xsl:template name="CondFormat_office_style">
  518.         <!-- translate the ConditionalFormatting style,including font,size,color,etc -->
  519.         <xsl:for-each select="/ss:Workbook/ss:Worksheet/x:ConditionalFormatting">
  520.             <xsl:variable name="table-pos" select="count(../preceding-sibling::ss:Worksheet)+1"/>
  521.             <xsl:variable name="conditions" select="count(preceding-sibling::x:ConditionalFormatting)+1"/>
  522.             <!-- Matching multiple styles, but automatic styles are not allowed to inherit from another automatic style
  523.             <xsl:for-each select="key('tableStyleIDs', key('tableWithConditional', .))
  524.                 [generate-id(.) =
  525.                  generate-id(key('styleId', .)[1])] ">
  526.                  <xsl:sort select="." />
  527.  
  528.                  <xsl:apply-templates select="/ss:Workbook/ss:Styles/ss:Style[@ss:ID = current()/.]"/>
  529.             </xsl:for-each>
  530.             -->
  531.             <xsl:for-each select="x:Condition">
  532.                 <xsl:variable name="condition-number" select="count(preceding-sibling::x:Condition)+1"/>
  533.                 <xsl:element name="style:style">
  534.                     <xsl:attribute name="style:name">
  535.                         <xsl:call-template name="encode-as-nc-name">
  536.                             <xsl:with-param name="string" select="concat('Excel_CondFormat_',$table-pos,'_',$conditions,'_',$condition-number)"/>
  537.                         </xsl:call-template>
  538.                     </xsl:attribute>
  539.                     <xsl:attribute name="style:family">table-cell</xsl:attribute>
  540.                     <xsl:apply-templates select="@ss:Name" />
  541.                     <xsl:element name="style:table-cell-properties">
  542.                         <xsl:choose>
  543.                             <xsl:when test="x:Format/@Style">
  544.                                 <xsl:variable name="stylevalue" select="./x:Format/@Style"/>
  545.                                 <xsl:call-template name="recursion-condformat-style-table-cell">
  546.                                     <xsl:with-param name="style-value-t">
  547.                                         <xsl:choose>
  548.                                             <xsl:when test="substring($stylevalue,string-length($stylevalue),1) != ';'">
  549.                                                 <xsl:value-of select="concat($stylevalue,';')"/>
  550.                                             </xsl:when>
  551.                                             <xsl:otherwise>
  552.                                                 <xsl:value-of select="$stylevalue"/>
  553.                                             </xsl:otherwise>
  554.                                         </xsl:choose>
  555.                                     </xsl:with-param>
  556.                                 </xsl:call-template>
  557.                             </xsl:when>
  558.                         </xsl:choose>
  559.                     </xsl:element>
  560.                     <xsl:element name="style:text-properties">
  561.                         <xsl:choose>
  562.                             <xsl:when test="x:Format/@Style">
  563.                                 <xsl:variable name="stylevalue" select="./x:Format/@Style"/>
  564.                                 <xsl:call-template name="recursion-condformat-style-text">
  565.                                     <xsl:with-param name="style-value-t">
  566.                                         <xsl:choose>
  567.                                             <xsl:when test="substring($stylevalue,string-length($stylevalue),1) != ';'">
  568.                                                 <xsl:value-of select="concat($stylevalue,';')"/>
  569.                                             </xsl:when>
  570.                                             <xsl:otherwise>
  571.                                                 <xsl:value-of select="$stylevalue"/>
  572.                                             </xsl:otherwise>
  573.                                         </xsl:choose>
  574.                                     </xsl:with-param>
  575.                                 </xsl:call-template>
  576.                             </xsl:when>
  577.                             <xsl:otherwise>
  578.                                 <xsl:attribute name="fo:font-style">
  579.                                     <xsl:value-of select="'italic'"/>
  580.                                 </xsl:attribute>
  581.                                 <xsl:attribute name="style:text-underline-type">
  582.                                     <xsl:value-of select="'single'"/>
  583.                                 </xsl:attribute>
  584.                                 <xsl:attribute name="style:text-underline-color">
  585.                                     <xsl:value-of select="'font-color'"/>
  586.                                 </xsl:attribute>
  587.                                 <xsl:attribute name="fo:font-weight">
  588.                                     <xsl:value-of select="'bold'"/>
  589.                                 </xsl:attribute>
  590.                             </xsl:otherwise>
  591.                         </xsl:choose>
  592.                     </xsl:element>
  593.                 </xsl:element>
  594.             </xsl:for-each>
  595.         </xsl:for-each>
  596.     </xsl:template>
  597.     <xsl:template match="@ss:Name">
  598.         <xsl:attribute name="style:display-name">
  599.             <xsl:value-of select="."/>
  600.         </xsl:attribute>
  601.     </xsl:template>
  602.     <xsl:template name="recursion-condformat-style-table-cell">
  603.         <!-- generates style:style for ConditionalFormatting -->
  604.         <xsl:param name="style-value-t"/>
  605.         <xsl:variable name="style-value" select="normalize-space($style-value-t)"/>
  606.         <xsl:choose>
  607.             <xsl:when test="starts-with($style-value,'background')">
  608.                 <xsl:choose>
  609.                     <xsl:when test="contains($style-value,'mso-pattern')">
  610.                         <xsl:variable name="color-value">
  611.                             <xsl:call-template name="translate-color-style">
  612.                                 <xsl:with-param name="source-str" select="normalize-space(substring-before(substring-after($style-value,':'),';'))"/>
  613.                             </xsl:call-template>
  614.                         </xsl:variable>
  615.                         <xsl:variable name="mso-value">
  616.                             <xsl:call-template name="translate-color-style">
  617.                                 <xsl:with-param name="source-str" select="normalize-space(substring-after($style-value,'mso-pattern'))"/>
  618.                             </xsl:call-template>
  619.                         </xsl:variable>
  620.                         <xsl:variable name="mso-color" select="substring-after($mso-value,'#')"/>
  621.                         <xsl:variable name="pattern-color-value" select="substring($mso-color,1,6)"/>
  622.                         <xsl:variable name="pattern" select="concat('0.',normalize-space(substring-before(substring-after($mso-color,'gray-'),';')))"/>
  623.                         <xsl:variable name="pattern-color">
  624.                             <xsl:call-template name="cell-pattern-color">
  625.                                 <xsl:with-param name="pattern" select="$pattern"/>
  626.                                 <xsl:with-param name="color-value" select="$color-value"/>
  627.                                 <xsl:with-param name="pattern-color-value" select="concat('#',$pattern-color-value)"/>
  628.                             </xsl:call-template>
  629.                         </xsl:variable>
  630.                         <xsl:attribute name="fo:background-color">
  631.                             <xsl:value-of select="normalize-space($pattern-color)"/>
  632.                         </xsl:attribute>
  633.                     </xsl:when>
  634.                     <xsl:otherwise>
  635.                         <xsl:attribute name="fo:background-color">
  636.                             <xsl:call-template name="translate-color-style">
  637.                                 <xsl:with-param name="source-str" select="normalize-space(substring-before(substring-after($style-value,':'),';'))"/>
  638.                             </xsl:call-template>
  639.                         </xsl:attribute>
  640.                     </xsl:otherwise>
  641.                 </xsl:choose>
  642.             </xsl:when>
  643.             <xsl:when test="starts-with($style-value,'border')">
  644.                 <xsl:attribute name="fo:border">
  645.                     <xsl:value-of select="'0.002cm solid #000000'"/>
  646.                 </xsl:attribute>
  647.             </xsl:when>
  648.         </xsl:choose>
  649.         <xsl:if test="contains($style-value,':')">
  650.             <xsl:call-template name="recursion-condformat-style-table-cell">
  651.                 <xsl:with-param name="style-value-t" select="substring-after($style-value,';')"/>
  652.             </xsl:call-template>
  653.         </xsl:if>
  654.     </xsl:template>
  655.     <xsl:template name="recursion-condformat-style-text">
  656.         <!-- generates style:style for ConditionalFormatting -->
  657.         <xsl:param name="style-value-t"/>
  658.         <xsl:variable name="style-value" select="normalize-space($style-value-t)"/>
  659.         <xsl:choose>
  660.             <xsl:when test="starts-with($style-value,'color')">
  661.                 <xsl:attribute name="fo:color">
  662.                     <xsl:call-template name="translate-color-style">
  663.                         <xsl:with-param name="source-str" select="normalize-space(substring-before(substring-after($style-value,':'),';'))"/>
  664.                     </xsl:call-template>
  665.                 </xsl:attribute>
  666.             </xsl:when>
  667.             <xsl:when test="starts-with($style-value,'font-style')">
  668.                 <xsl:attribute name="fo:font-style">
  669.                     <xsl:value-of select="normalize-space(substring-before(substring-after($style-value,':'),';'))"/>
  670.                 </xsl:attribute>
  671.             </xsl:when>
  672.             <xsl:when test="starts-with($style-value,'font-weight')">
  673.                 <xsl:variable name="font-weight" select="normalize-space(substring-before(substring-after($style-value,':'),';'))"/>
  674.                 <xsl:attribute name="fo:font-weight">
  675.                     <xsl:choose>
  676.                         <xsl:when test="($font-weight > 300) and ($font-weight < 500)">
  677.                             <xsl:value-of select="'normal'"/>
  678.                         </xsl:when>
  679.                         <xsl:when test="($font-weight > 500) or ($font-weight = 500)">
  680.                             <xsl:value-of select="'bold'"/>
  681.                         </xsl:when>
  682.                         <xsl:otherwise>
  683.                             <xsl:value-of select="'0'"/>
  684.                         </xsl:otherwise>
  685.                     </xsl:choose>
  686.                 </xsl:attribute>
  687.             </xsl:when>
  688.             <xsl:when test="starts-with($style-value,'text-underline-style')">
  689.                 <xsl:attribute name="style:text-underline-type">
  690.                     <xsl:value-of select="normalize-space(substring-before(substring-after($style-value,':'),';'))"/>
  691.                 </xsl:attribute>
  692.                 <xsl:attribute name="style:text-underline-color">
  693.                     <xsl:value-of select="'#000000'"/>
  694.                 </xsl:attribute>
  695.             </xsl:when>
  696.         </xsl:choose>
  697.         <xsl:if test="contains($style-value,':')">
  698.             <xsl:call-template name="recursion-condformat-style-text">
  699.                 <xsl:with-param name="style-value-t" select="substring-after($style-value,';')"/>
  700.             </xsl:call-template>
  701.         </xsl:if>
  702.     </xsl:template>
  703.     <xsl:template name="translate-color-style">
  704.         <!-- translate the word of color to hex code of color -->
  705.         <xsl:param name="source-str"/>
  706.         <xsl:choose>
  707.             <xsl:when test="starts-with($source-str,'#')">
  708.                 <xsl:value-of select="$source-str"/>
  709.             </xsl:when>
  710.             <xsl:otherwise>
  711.                 <xsl:choose>
  712.                     <xsl:when test="starts-with($source-str,'black')">
  713.                         <xsl:value-of select="'#000000'"/>
  714.                     </xsl:when>
  715.                     <xsl:when test="starts-with($source-str,'maroon')">
  716.                         <xsl:value-of select="'#800000'"/>
  717.                     </xsl:when>
  718.                     <xsl:when test="starts-with($source-str,'red')">
  719.                         <xsl:value-of select="'#FF0000'"/>
  720.                     </xsl:when>
  721.                     <xsl:when test="starts-with($source-str,'fuchsia')">
  722.                         <xsl:value-of select="'#FF00FF'"/>
  723.                     </xsl:when>
  724.                     <xsl:when test="starts-with($source-str,'olive')">
  725.                         <xsl:value-of select="'#808000'"/>
  726.                     </xsl:when>
  727.                     <xsl:when test="starts-with($source-str,'yellow')">
  728.                         <xsl:value-of select="'#FFFF00'"/>
  729.                     </xsl:when>
  730.                     <xsl:when test="starts-with($source-str,'green')">
  731.                         <xsl:value-of select="'#008000'"/>
  732.                     </xsl:when>
  733.                     <xsl:when test="starts-with($source-str,'lime')">
  734.                         <xsl:value-of select="'#00FF00'"/>
  735.                     </xsl:when>
  736.                     <xsl:when test="starts-with($source-str,'teal')">
  737.                         <xsl:value-of select="'#008080'"/>
  738.                     </xsl:when>
  739.                     <xsl:when test="starts-with($source-str,'aqua')">
  740.                         <xsl:value-of select="'#00FFFF'"/>
  741.                     </xsl:when>
  742.                     <xsl:when test="starts-with($source-str,'navy')">
  743.                         <xsl:value-of select="'#000080'"/>
  744.                     </xsl:when>
  745.                     <xsl:when test="starts-with($source-str,'blue')">
  746.                         <xsl:value-of select="'#0000FF'"/>
  747.                     </xsl:when>
  748.                     <xsl:when test="starts-with($source-str,'purple')">
  749.                         <xsl:value-of select="'#800080'"/>
  750.                     </xsl:when>
  751.                     <xsl:when test="starts-with($source-str,'gray')">
  752.                         <xsl:value-of select="'#808080'"/>
  753.                     </xsl:when>
  754.                     <xsl:when test="starts-with($source-str,'silver')">
  755.                         <xsl:value-of select="'#C0C0C0'"/>
  756.                     </xsl:when>
  757.                     <xsl:when test="starts-with($source-str,'white')">
  758.                         <xsl:value-of select="'#FFFFFF'"/>
  759.                     </xsl:when>
  760.                     <xsl:otherwise>
  761.                         <xsl:value-of select="'#FFFFFF'"/>
  762.                     </xsl:otherwise>
  763.                 </xsl:choose>
  764.             </xsl:otherwise>
  765.         </xsl:choose>
  766.     </xsl:template>
  767.     <xsl:key match="/ss:Workbook/ss:Worksheet/ss:Table" name="tableWithConditional" use="following-sibling::x:ConditionalFormatting"/>
  768.     <xsl:key match="ss:Table/ss:Row/ss:Cell/@ss:StyleID" name="tableStyleIDs" use="ancestor::ss:Table"/>
  769.     <xsl:key name="styleId" match="@ss:StyleID" use="."/>
  770.     <xsl:template name="CondFormat_automatic_style">
  771.         <!-- For each conditionalFormatting We inject a new style, which is a child of the current found style -->
  772.         <xsl:for-each select="/ss:Workbook/ss:Worksheet/x:ConditionalFormatting">
  773.             <xsl:variable name="table-pos" select="count(../preceding-sibling::ss:Worksheet)+1"/>
  774.             <xsl:variable name="conditions" select="count(preceding-sibling::x:ConditionalFormatting)+1"/>
  775.             <xsl:variable name="conditionalFormatting" select="."/>
  776.             <!-- for all 'ssStyle/@ss:ID's, which are in tables connected within this conditional formatting  -->
  777.             <xsl:for-each select="key('tableStyleIDs', key('tableWithConditional', .)) [generate-id(.) = generate-id(key('styleId', .)[1])] ">
  778.                 <!-- sort the style ID by their naming -->
  779.                 <xsl:sort select="."/>
  780.                 <xsl:element name="style:style">
  781.                     <xsl:attribute name="style:name">
  782.                         <xsl:call-template name="encode-as-nc-name">
  783.                             <xsl:with-param name="string" select="concat(.,'-ce',$table-pos,'-',$conditions)"/>
  784.                         </xsl:call-template>
  785.                     </xsl:attribute>
  786.                     <xsl:attribute name="style:family">table-cell</xsl:attribute>
  787.                     <xsl:variable name="style" select="key('Style', .)" />
  788.                     <xsl:choose>
  789.                         <xsl:when test="$style/@ss:Name">
  790.                             <xsl:attribute name="style:parent-style-name">
  791.                                 <xsl:call-template name="encode-as-nc-name">
  792.                                     <xsl:with-param name="string" select="."/>
  793.                                 </xsl:call-template>
  794.                             </xsl:attribute>
  795.                         </xsl:when>
  796.                         <!-- as we create an automatic style, the parent is not allowed to be an automatic style as well
  797.                              if the parent would be a automatic (unnamed) style, the style information have to be embedded to this style -->
  798.                         <xsl:otherwise>
  799.                             <xsl:attribute name="style:parent-style-name">
  800.                                 <xsl:call-template name="encode-as-nc-name">
  801.                                     <xsl:with-param name="string" select="$style/@ss:Parent"/>
  802.                                 </xsl:call-template>
  803.                             </xsl:attribute>
  804.                             <xsl:if test="$style/ss:NumberFormat/@ss:Format">
  805.                                 <xsl:attribute name="style:data-style-name">
  806.                                     <xsl:value-of select="concat($style/@ss:ID, 'F')"/>
  807.                                 </xsl:attribute>
  808.                             </xsl:if>
  809.                             <xsl:apply-templates select="$style" mode="style-style-content"/>
  810.                         </xsl:otherwise>
  811.                     </xsl:choose>
  812.                     <xsl:for-each select="$conditionalFormatting/x:Condition">
  813.                         <xsl:variable name="condition-number" select="count(preceding-sibling::x:Condition)+1"/>
  814.                         <xsl:variable name="base-address">
  815.                             <xsl:choose>
  816.                                 <xsl:when test="contains(../x:Range,',')">
  817.                                     <xsl:choose>
  818.                                         <xsl:when test="contains(substring-before(../x:Range,','),':')">
  819.                                             <xsl:value-of select="substring-before(substring-after(../x:Range,':'),',')"/>
  820.                                         </xsl:when>
  821.                                         <xsl:otherwise>
  822.                                             <xsl:value-of select="substring-before(../x:Range,',')"/>
  823.                                         </xsl:otherwise>
  824.                                     </xsl:choose>
  825.                                 </xsl:when>
  826.                                 <xsl:otherwise>
  827.                                     <xsl:value-of select="../x:Range"/>
  828.                                 </xsl:otherwise>
  829.                             </xsl:choose>
  830.                         </xsl:variable>
  831.                         <xsl:variable name="columnNumber">
  832.                             <xsl:choose>
  833.                                 <xsl:when test="contains($base-address, ':')">
  834.                                     <xsl:value-of select="substring-after(substring-after($base-address, ':'),'C')"/>
  835.                                 </xsl:when>
  836.                                 <xsl:otherwise>
  837.                                     <xsl:value-of select="substring-after($base-address,'C')"/>
  838.                                 </xsl:otherwise>
  839.                             </xsl:choose>
  840.                         </xsl:variable>
  841.                         <xsl:variable name="rowNumber">
  842.                             <xsl:choose>
  843.                                 <xsl:when test="contains($base-address, ':')">
  844.                                     <xsl:value-of select="substring-before(substring-after(substring-after($base-address, ':'),'R'),'C')"/>
  845.                                 </xsl:when>
  846.                                 <xsl:otherwise>
  847.                                     <xsl:value-of select="substring-before(substring-after($base-address,'R'),'C')"/>
  848.                                 </xsl:otherwise>
  849.                             </xsl:choose>
  850.                         </xsl:variable>
  851.                         <xsl:variable name="base-cell-address">
  852.                             <xsl:call-template name="translate-unit">
  853.                                 <xsl:with-param name="column-number" select="$columnNumber"/>
  854.                                 <xsl:with-param name="row-number" select="$rowNumber"/>
  855.                                 <xsl:with-param name="column-pos-style" select="'relative'"/>
  856.                                 <xsl:with-param name="row-pos-style" select="'relative'"/>
  857.                             </xsl:call-template>
  858.                         </xsl:variable>
  859.                         <xsl:variable name="condition-value">
  860.                             <xsl:call-template name="translate-condition">
  861.                                 <xsl:with-param name="cell-column-pos" select="$columnNumber"/>
  862.                                 <xsl:with-param name="cell-row-pos" select="$rowNumber"/>
  863.                             </xsl:call-template>
  864.                         </xsl:variable>
  865.                         <xsl:element name="style:map">
  866.                             <xsl:attribute name="style:condition">
  867.                                 <xsl:value-of select="$condition-value"/>
  868.                             </xsl:attribute>
  869.                             <xsl:attribute name="style:apply-style-name">
  870.                                 <xsl:value-of select="concat('Excel_CondFormat_',$table-pos,'_',$conditions,'_',$condition-number)"/>
  871.                             </xsl:attribute>
  872.                             <xsl:attribute name="style:base-cell-address">
  873.                                 <xsl:value-of select="concat(../../@ss:Name,'.',$base-cell-address)"/>
  874.                             </xsl:attribute>
  875.                         </xsl:element>
  876.                     </xsl:for-each>
  877.                 </xsl:element>
  878.             </xsl:for-each>
  879.         </xsl:for-each>
  880.     </xsl:template>
  881.     <xsl:template name="translate-condition">
  882.         <xsl:param name="cell-row-pos"/>
  883.         <xsl:param name="cell-column-pos"/>
  884.         <!-- translates the condition to generate formula -->
  885.         <xsl:variable name="address-value">
  886.             <xsl:call-template name="translate-expression">
  887.                 <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  888.                 <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  889.                 <xsl:with-param name="expression" select="x:Value1"/>
  890.                 <xsl:with-param name="return-value" select="''"/>
  891.             </xsl:call-template>
  892.         </xsl:variable>
  893.         <xsl:choose>
  894.             <xsl:when test="x:Qualifier">
  895.                 <xsl:variable name="qualifier" select="x:Qualifier"/>
  896.                 <xsl:variable name="first-value" select="x:Value1"/>
  897.                 <xsl:choose>
  898.                     <xsl:when test="$qualifier = 'Equal'">
  899.                         <xsl:choose>
  900.                             <xsl:when test="starts-with($first-value,'"')">
  901.                                 <xsl:value-of select="concat('cell-content()=',$address-value)"/>
  902.                             </xsl:when>
  903.                             <xsl:otherwise>
  904.                                 <xsl:value-of select="concat('cell-content()=[',$address-value,']')"/>
  905.                             </xsl:otherwise>
  906.                         </xsl:choose>
  907.                     </xsl:when>
  908.                     <xsl:when test="$qualifier = 'Less'">
  909.                         <xsl:value-of select="concat('cell-content()<[',$address-value,']')"/>
  910.                     </xsl:when>
  911.                     <xsl:when test="$qualifier = 'Greater'">
  912.                         <xsl:value-of select="concat('cell-content()>[',$address-value,']')"/>
  913.                     </xsl:when>
  914.                     <xsl:when test="$qualifier = 'LessOrEqual'">
  915.                         <xsl:value-of select="concat('cell-content()<=[',$address-value,']')"/>
  916.                     </xsl:when>
  917.                     <xsl:when test="$qualifier = 'GreaterOrEqual'">
  918.                         <xsl:value-of select="concat('cell-content()>=[',$address-value,']')"/>
  919.                     </xsl:when>
  920.                     <xsl:when test="$qualifier = 'NotEqual'">
  921.                         <xsl:value-of select="concat('cell-content()!=[',$address-value,']')"/>
  922.                     </xsl:when>
  923.                     <xsl:when test="$qualifier = 'Between'">
  924.                         <xsl:variable name="second-value">
  925.                             <xsl:call-template name="translate-expression">
  926.                                 <xsl:with-param name="cell-row-pos" select="0"/>
  927.                                 <xsl:with-param name="cell-column-pos" select="0"/>
  928.                                 <xsl:with-param name="expression" select="x:Value2"/>
  929.                                 <xsl:with-param name="return-value" select="''"/>
  930.                             </xsl:call-template>
  931.                         </xsl:variable>
  932.                         <xsl:value-of select="concat('cell-content-is-between([',$address-value,'],[',$second-value,'])')"/>
  933.                     </xsl:when>
  934.                     <xsl:when test="$qualifier = 'NotBetween'">
  935.                         <xsl:variable name="second-value">
  936.                             <xsl:call-template name="translate-expression">
  937.                                 <xsl:with-param name="cell-row-pos" select="0"/>
  938.                                 <xsl:with-param name="cell-column-pos" select="0"/>
  939.                                 <xsl:with-param name="expression" select="x:Value2"/>
  940.                                 <xsl:with-param name="return-value" select="''"/>
  941.                             </xsl:call-template>
  942.                         </xsl:variable>
  943.                         <xsl:value-of select="concat('cell-content-is-not-between([',$address-value,'],[',$second-value,'])')"/>
  944.                     </xsl:when>
  945.                 </xsl:choose>
  946.             </xsl:when>
  947.             <xsl:otherwise>
  948.                 <xsl:value-of select="concat('is-true-formula(',$address-value,')')"/>
  949.             </xsl:otherwise>
  950.         </xsl:choose>
  951.     </xsl:template>
  952.     <!-- Used in case of 'style:map', conditional formatting, where a style references to another -->
  953.     <xsl:key match="/ss:Workbook/ss:Worksheet/ss:Table/ss:Row/ss:Cell" name="cells" use="@ss:StyleID"/>
  954.     <xsl:template match="ss:NumberFormat">
  955.         <xsl:variable name="unit-count" select="string-length(@ss:Format) - string-length(translate(@ss:Format,';','')) + 1"/>
  956.         <xsl:variable name="proto-style-id" select="../@ss:ID"/>
  957.         <xsl:call-template name="process-number-format-unit">
  958.             <xsl:with-param name="number-format-unit" select="@ss:Format"/>
  959.             <xsl:with-param name="style-id" select="concat($proto-style-id,'F')"/>
  960.             <xsl:with-param name="format-type" select="key('cells', $proto-style-id)/ss:Data/@ss:Type"/>
  961.             <xsl:with-param name="total-unit" select="$unit-count"/>
  962.             <xsl:with-param name="current-unit" select="0"/>
  963.         </xsl:call-template>
  964.     </xsl:template>
  965.     <!-- Note: conditions appearing only once at the beginning are mixed with others -->
  966.     <xsl:template name="process-number-format-unit">
  967.         <xsl:param name="number-format-unit"/>
  968.         <xsl:param name="style-id"/>
  969.         <xsl:param name="format-type"/>
  970.         <xsl:param name="total-unit"/>
  971.         <xsl:param name="current-unit"/>
  972.         <xsl:choose>
  973.             <!-- if total-unit > 1 and the last unit is just @, delete it -->
  974.             <xsl:when test="$current-unit = 0 and $total-unit > 1 and substring( $number-format-unit, string-length($number-format-unit) - 1) = ';@'">
  975.                 <xsl:call-template name="process-number-format-unit">
  976.                     <xsl:with-param name="number-format-unit" select="substring( $number-format-unit, 1, string-length($number-format-unit) - 2)"/>
  977.                     <xsl:with-param name="style-id" select="$style-id"/>
  978.                     <xsl:with-param name="format-type" select="$format-type"/>
  979.                     <xsl:with-param name="total-unit" select="$total-unit - 1"/>
  980.                     <xsl:with-param name="current-unit" select="0"/>
  981.                 </xsl:call-template>
  982.             </xsl:when>
  983.             <!-- $number-format-unit enum values: General, General Number, General Date, Long Date, Medium Date, Short Date, Long Time,
  984.              Medium Time, Short Time, Currency, Euro Currency, Fixed, Standard, Percent, Scientific, Yes/No, True/False, On/Off -->
  985.             <xsl:when test="$number-format-unit = 'Currency'">
  986.                 <number:currency-style style:name="{concat( $style-id, 'P1')}" style:volatile="true">
  987.                     <number:text>$</number:text>
  988.                     <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
  989.                 </number:currency-style>
  990.                 <number:currency-style style:name="{$style-id}">
  991.                     <style:text-properties fo:color="#ff0000"/>
  992.                     <number:text>$-</number:text>
  993.                     <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
  994.                     <style:map style:condition="value()>=0" style:apply-style-name="{concat( $style-id, 'P1')}"/>
  995.                 </number:currency-style>
  996.             </xsl:when>
  997.             <xsl:when test="$number-format-unit = 'Euro Currency'">
  998.                 <number:currency-style style:name="{concat( $style-id, 'P1')}" style:volatile="true">
  999.                     <number:text>Γé¼ </number:text>
  1000.                     <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
  1001.                 </number:currency-style>
  1002.                 <number:currency-style style:name="{$style-id}">
  1003.                     <style:text-properties fo:color="#ff0000"/>
  1004.                     <number:text>(Γé¼ </number:text>
  1005.                     <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
  1006.                     <number:text>)</number:text>
  1007.                     <style:map style:condition="value()>=0" style:apply-style-name="{concat( $style-id, 'P1')}"/>
  1008.                 </number:currency-style>
  1009.             </xsl:when>
  1010.             <xsl:when test="$number-format-unit = 'Yes/No' or $number-format-unit = 'True/False' or $number-format-unit = 'On/Off'">
  1011.                 <xsl:variable name="left-code" select="substring-before( $number-format-unit, '/')"/>
  1012.                 <xsl:variable name="right-code" select="substring-after( $number-format-unit, '/')"/>
  1013.                 <number:number-style style:name="{concat( $style-id, 'P1')}" style:volatile="true">
  1014.                     <number:text>
  1015.                         <xsl:value-of select="$left-code"/>
  1016.                     </number:text>
  1017.                 </number:number-style>
  1018.                 <number:number-style style:name="{concat( $style-id, 'P2')}" style:volatile="true">
  1019.                     <number:text>
  1020.                         <xsl:value-of select="$left-code"/>
  1021.                     </number:text>
  1022.                 </number:number-style>
  1023.                 <number:number-style style:name="{$style-id}">
  1024.                     <number:text>
  1025.                         <xsl:value-of select="$right-code"/>
  1026.                     </number:text>
  1027.                     <style:map style:condition="value()>0" style:apply-style-name="{concat( $style-id, 'P1')}"/>
  1028.                     <style:map style:condition="value()<0" style:apply-style-name="{concat( $style-id, 'P2')}"/>
  1029.                 </number:number-style>
  1030.             </xsl:when>
  1031.             <xsl:otherwise>
  1032.                 <xsl:if test="$total-unit > 1 and $current-unit = 0">
  1033.                     <!-- still complete number format string of multiple sub-formats, split them out -->
  1034.                     <xsl:call-template name="process-number-format-unit">
  1035.                         <xsl:with-param name="number-format-unit" select="substring-before($number-format-unit,';')"/>
  1036.                         <xsl:with-param name="style-id" select="concat($style-id,'P1')"/>
  1037.                         <xsl:with-param name="format-type" select="$format-type"/>
  1038.                         <xsl:with-param name="total-unit" select="$total-unit"/>
  1039.                         <xsl:with-param name="current-unit" select="1"/>
  1040.                     </xsl:call-template>
  1041.                     <xsl:if test="$total-unit > 2">
  1042.                         <xsl:call-template name="process-number-format-unit">
  1043.                             <xsl:with-param name="number-format-unit" select="substring-before(substring-after($number-format-unit,';'),';')"/>
  1044.                             <xsl:with-param name="style-id" select="concat($style-id,'P2')"/>
  1045.                             <xsl:with-param name="format-type" select="$format-type"/>
  1046.                             <xsl:with-param name="total-unit" select="$total-unit"/>
  1047.                             <xsl:with-param name="current-unit" select="2"/>
  1048.                         </xsl:call-template>
  1049.                     </xsl:if>
  1050.                     <xsl:if test="$total-unit > 3">
  1051.                         <!-- four sub number format -->
  1052.                         <xsl:call-template name="process-number-format-unit">
  1053.                             <xsl:with-param name="number-format-unit" select="substring-before(substring-after(substring-after($number-format-unit,';'),';'),';')"/>
  1054.                             <xsl:with-param name="style-id" select="concat($style-id,'P3')"/>
  1055.                             <xsl:with-param name="format-type" select="$format-type"/>
  1056.                             <xsl:with-param name="total-unit" select="$total-unit"/>
  1057.                             <xsl:with-param name="current-unit" select="3"/>
  1058.                         </xsl:call-template>
  1059.                     </xsl:if>
  1060.                 </xsl:if>
  1061.                 <!-- symbol number format converted, below deal with ordinary number formatting -->
  1062.                 <xsl:variable name="current-number-format-unit">
  1063.                     <xsl:choose>
  1064.                         <xsl:when test="$total-unit = 1 and $current-unit = 0">
  1065.                             <xsl:value-of select="$number-format-unit"/>
  1066.                         </xsl:when>
  1067.                         <xsl:when test="$total-unit = 2 and $current-unit = 0">
  1068.                             <xsl:value-of select="substring-after($number-format-unit,';')"/>
  1069.                         </xsl:when>
  1070.                         <xsl:when test="$total-unit = 3 and $current-unit = 0">
  1071.                             <xsl:value-of select="substring-after(substring-after($number-format-unit,';'),';')"/>
  1072.                         </xsl:when>
  1073.                         <xsl:when test="$current-unit = 0">
  1074.                             <!-- the forth sub number format -->
  1075.                             <xsl:value-of select="substring-after(substring-after(substring-after($number-format-unit,';'),';'),';')"/>
  1076.                         </xsl:when>
  1077.                         <xsl:otherwise>
  1078.                             <!-- not the default sub number format, glu -->
  1079.                             <xsl:value-of select="$number-format-unit"/>
  1080.                         </xsl:otherwise>
  1081.                     </xsl:choose>
  1082.                 </xsl:variable>
  1083.                 <xsl:variable name="style-type-name">
  1084.                     <xsl:choose>
  1085.                         <xsl:when test="($format-type = 'Number' and contains($current-number-format-unit,'[$') and not(contains($current-number-format-unit,'[$-') ) ) or contains($current-number-format-unit,'Currency') ">number:currency-style</xsl:when>
  1086.                         <xsl:when test="($format-type = 'Number' and (contains($current-number-format-unit,'%') or contains($current-number-format-unit, 'Percent') ) ) or contains($current-number-format-unit,'Percent') ">number:percentage-style</xsl:when>
  1087.                         <xsl:when test="($format-type = 'DateTime' or $format-type = 'String') and (contains($current-number-format-unit,'y') or contains($current-number-format-unit,'g') or contains($current-number-format-unit,'d') or contains($current-number-format-unit, 'Date') )">number:date-style</xsl:when>
  1088.                         <xsl:when test="($format-type = 'DateTime' or $format-type = 'String') and ( contains($current-number-format-unit,'h') or contains($current-number-format-unit,'m') or contains($current-number-format-unit,'s') or contains($current-number-format-unit, 'Time') )">number:time-style</xsl:when>
  1089.                         <xsl:when test="contains($current-number-format-unit, 'Number') or contains($current-number-format-unit, 'General') or contains($current-number-format-unit, 'Fixed') or contains($current-number-format-unit, 'Standard') or contains($current-number-format-unit, 'Scientific') or ( contains($current-number-format-unit,'#') or contains($current-number-format-unit,'0') or contains($current-number-format-unit,'?') )">number:number-style</xsl:when>
  1090.                         <xsl:when test="$format-type = 'Boolean'">number:boolean-style</xsl:when>
  1091.                         <xsl:otherwise>number:text-style</xsl:otherwise>
  1092.                     </xsl:choose>
  1093.                 </xsl:variable>
  1094.                 <xsl:element name="{$style-type-name}">
  1095.                     <xsl:attribute name="style:name">
  1096.                         <xsl:value-of select="$style-id"/>
  1097.                     </xsl:attribute>
  1098.                     <xsl:apply-templates select="@ss:Name" />
  1099.                     <!-- removed in OASIS XML
  1100.                     <xsl:attribute name="style:family">data-style</xsl:attribute>-->
  1101.                     <xsl:if test="$current-unit > 0">
  1102.                         <xsl:attribute name="style:volatile">true</xsl:attribute>
  1103.                     </xsl:if>
  1104.                     <xsl:if test="contains ( $current-number-format-unit, '[h]') or contains ( $current-number-format-unit, '[m]') or contains ( $current-number-format-unit, '[s]')">
  1105.                         <xsl:attribute name="number:truncate-on-overflow">false</xsl:attribute>
  1106.                     </xsl:if>
  1107.                     <xsl:if test="contains($current-number-format-unit,'[$') or contains($current-number-format-unit, '[DBNum')">
  1108.                         <xsl:call-template name="create-language-country-attribute">
  1109.                             <xsl:with-param name="attribute-code" select="substring-before(substring-after(substring-after($current-number-format-unit,'[$'),'-'),']')"/>
  1110.                             <xsl:with-param name="number-code-style" select="substring-before( substring-after($current-number-format-unit,'[DBNum'),']')"/>
  1111.                         </xsl:call-template>
  1112.                     </xsl:if>
  1113.                     <xsl:if test="contains( $current-number-format-unit, '[')">
  1114.                         <xsl:element name="style:text-properties">
  1115.                             <xsl:choose>
  1116.                                 <xsl:when test="contains( $current-number-format-unit, '[Red')">
  1117.                                     <xsl:attribute name="fo:color">#ff0000</xsl:attribute>
  1118.                                 </xsl:when>
  1119.                                 <xsl:when test="contains( $current-number-format-unit, '[Black')">
  1120.                                     <xsl:attribute name="fo:color">#000000</xsl:attribute>
  1121.                                 </xsl:when>
  1122.                                 <xsl:when test="contains( $current-number-format-unit, '[Blue')">
  1123.                                     <xsl:attribute name="fo:color">#0000ff</xsl:attribute>
  1124.                                 </xsl:when>
  1125.                                 <xsl:when test="contains( $current-number-format-unit, '[Cyan')">
  1126.                                     <xsl:attribute name="fo:color">#00ffff</xsl:attribute>
  1127.                                 </xsl:when>
  1128.                                 <xsl:when test="contains( $current-number-format-unit, '[Green')">
  1129.                                     <xsl:attribute name="fo:color">#00ff00</xsl:attribute>
  1130.                                 </xsl:when>
  1131.                                 <xsl:when test="contains( $current-number-format-unit, '[Magenta')">
  1132.                                     <xsl:attribute name="fo:color">#ff00ff</xsl:attribute>
  1133.                                 </xsl:when>
  1134.                                 <xsl:when test="contains( $current-number-format-unit, '[White')">
  1135.                                     <xsl:attribute name="fo:color">#ffffff</xsl:attribute>
  1136.                                 </xsl:when>
  1137.                                 <xsl:when test="contains( $current-number-format-unit, '[Yellow')">
  1138.                                     <xsl:attribute name="fo:color">#ffff00</xsl:attribute>
  1139.                                 </xsl:when>
  1140.                             </xsl:choose>
  1141.                         </xsl:element>
  1142.                     </xsl:if>
  1143.                     <!-- the type of condition-pos:1,the former third part of General; 2, the last General. the methods handling diffirent -->
  1144.                     <xsl:call-template name="create-number-format-content">
  1145.                         <xsl:with-param name="style-type-name" select="$style-type-name"/>
  1146.                         <xsl:with-param name="number-format-unit" select="$current-number-format-unit"/>
  1147.                         <xsl:with-param name="unit-pos" select="1"/>
  1148.                         <xsl:with-param name="condition-pos">
  1149.                             <xsl:choose>
  1150.                                 <xsl:when test="$current-unit = 1 or $current-unit = 2 or $current-unit = 3">
  1151.                                     <xsl:value-of select="1"/>
  1152.                                 </xsl:when>
  1153.                                 <xsl:when test="$current-unit = 0 and not(contains($number-format-unit, ';'))">
  1154.                                     <xsl:value-of select="1"/>
  1155.                                 </xsl:when>
  1156.                                 <xsl:otherwise>
  1157.                                     <xsl:value-of select="2"/>
  1158.                                 </xsl:otherwise>
  1159.                             </xsl:choose>
  1160.                         </xsl:with-param>
  1161.                     </xsl:call-template>
  1162.                     <!-- creat style:map for other sub number formats -->
  1163.                     <xsl:if test="$current-unit = 0 and $total-unit > 1">
  1164.                         <xsl:variable name="style-condition1">
  1165.                             <xsl:call-template name="get-number-format-condition">
  1166.                                 <xsl:with-param name="number-format-unit" select="substring-before($number-format-unit,';')"/>
  1167.                             </xsl:call-template>
  1168.                         </xsl:variable>
  1169.                         <xsl:choose>
  1170.                             <xsl:when test="string-length($style-condition1) > 0">
  1171.                                 <style:map style:condition="{concat('value()',$style-condition1)}" style:apply-style-name="{concat($style-id,'P1')}"/>
  1172.                             </xsl:when>
  1173.                             <xsl:otherwise>
  1174.                                 <xsl:choose>
  1175.                                     <xsl:when test="$total-unit = 2">
  1176.                                         <style:map style:condition="value()>=0" style:apply-style-name="{concat($style-id,'P1')}"/>
  1177.                                     </xsl:when>
  1178.                                     <xsl:otherwise>
  1179.                                         <style:map style:condition="value()>0" style:apply-style-name="{concat($style-id,'P1')}"/>
  1180.                                     </xsl:otherwise>
  1181.                                 </xsl:choose>
  1182.                             </xsl:otherwise>
  1183.                         </xsl:choose>
  1184.                         <xsl:if test="$total-unit > 2">
  1185.                             <xsl:variable name="style-condition2">
  1186.                                 <xsl:call-template name="get-number-format-condition">
  1187.                                     <xsl:with-param name="number-format-unit" select="substring-before(substring-after($number-format-unit,';'),';')"/>
  1188.                                 </xsl:call-template>
  1189.                             </xsl:variable>
  1190.                             <xsl:choose>
  1191.                                 <xsl:when test="string-length($style-condition2) > 0">
  1192.                                     <style:map style:condition="{concat('value()',$style-condition2)}" style:apply-style-name="{concat($style-id,'P2')}"/>
  1193.                                 </xsl:when>
  1194.                                 <xsl:otherwise>
  1195.                                     <style:map style:condition="value()<0" style:apply-style-name="{concat($style-id,'P2')}"/>
  1196.                                 </xsl:otherwise>
  1197.                             </xsl:choose>
  1198.                         </xsl:if>
  1199.                         <xsl:if test="$total-unit > 3">
  1200.                             <!-- four sub number formats, glu -->
  1201.                             <xsl:variable name="style-condition3">
  1202.                                 <xsl:call-template name="get-number-format-condition">
  1203.                                     <xsl:with-param name="number-format-unit" select="substring-before(substring-after(substring-after($number-format-unit,';'),';'),';')"/>
  1204.                                 </xsl:call-template>
  1205.                             </xsl:variable>
  1206.                             <xsl:choose>
  1207.                                 <xsl:when test="string-length($style-condition3) > 0">
  1208.                                     <style:map style:condition="{concat('value()',$style-condition3)}" style:apply-style-name="{concat($style-id,'P3')}"/>
  1209.                                 </xsl:when>
  1210.                                 <xsl:otherwise>
  1211.                                     <style:map style:condition="value()=0" style:apply-style-name="{concat($style-id,'P3')}"/>
  1212.                                 </xsl:otherwise>
  1213.                             </xsl:choose>
  1214.                         </xsl:if>
  1215.                     </xsl:if>
  1216.                 </xsl:element>
  1217.             </xsl:otherwise>
  1218.         </xsl:choose>
  1219.     </xsl:template>
  1220.     <xsl:template name="create-language-country-attribute">
  1221.         <xsl:param name="attribute-code"/>
  1222.         <xsl:param name="number-code-style"/>
  1223.         <!-- convert Microsoft List of Locale ID (LCID) to language and country codes according to ISO-639 and ISO-3166.
  1224.             Reference:
  1225.             http://www.loc.gov/standards/iso639-2/langcodes.html
  1226.             http://etext.lib.virginia.edu/tei/iso639.html
  1227.             http://nl.ijs.si/gnusl/cee/std/ISO_3166.html
  1228.             http://xml.coverpages.org/ripe3166.txt
  1229.             http://www.worldlanguage.com/
  1230.             http://www.ethnologue.com/
  1231.         glu -->
  1232.         <!-- the variables of language-country-code and number-shape-code transformed to decimal format -->
  1233.         <xsl:variable name="language-country-code">
  1234.             <xsl:variable name="temp-code">
  1235.                 <xsl:choose>
  1236.                     <xsl:when test="string-length($attribute-code) <= 4">
  1237.                         <xsl:value-of select="$attribute-code"/>
  1238.                     </xsl:when>
  1239.                     <xsl:otherwise>
  1240.                         <xsl:value-of select="substring($attribute-code,string-length($attribute-code) - 3)"/>
  1241.                     </xsl:otherwise>
  1242.                 </xsl:choose>
  1243.             </xsl:variable>
  1244.             <xsl:call-template name="hex2decimal">
  1245.                 <xsl:with-param name="hex-number" select="$temp-code"/>
  1246.                 <xsl:with-param name="index" select="1"/>
  1247.                 <xsl:with-param name="str-length" select="string-length($temp-code)"/>
  1248.                 <xsl:with-param name="last-value" select="0"/>
  1249.             </xsl:call-template>
  1250.         </xsl:variable>
  1251.         <xsl:if test="string-length($attribute-code) > 4 or string-length($number-code-style) > 0">
  1252.             <xsl:variable name="number-shape-code">
  1253.                 <xsl:variable name="temp-code">
  1254.                     <xsl:choose>
  1255.                         <xsl:when test="string-length($attribute-code) > 4">
  1256.                             <xsl:value-of select="substring($attribute-code, 1, string-length($attribute-code) - 6)"/>
  1257.                         </xsl:when>
  1258.                         <xsl:otherwise>0</xsl:otherwise>
  1259.                     </xsl:choose>
  1260.                 </xsl:variable>
  1261.                 <xsl:call-template name="hex2decimal">
  1262.                     <xsl:with-param name="hex-number" select="$temp-code"/>
  1263.                     <xsl:with-param name="index" select="1"/>
  1264.                     <xsl:with-param name="str-length" select="string-length($temp-code)"/>
  1265.                     <xsl:with-param name="last-value" select="0"/>
  1266.                 </xsl:call-template>
  1267.             </xsl:variable>
  1268.             <xsl:attribute name="number:transliteration-style">long</xsl:attribute>
  1269.             <xsl:choose>
  1270.                 <!-- Western, #01 -->
  1271.                 <xsl:when test="$number-shape-code = 1"/>
  1272.                 <!-- Arabic Indic, #02 -->
  1273.                 <xsl:when test="$number-shape-code = 2"/>
  1274.                 <!-- Extended Arabic Indic, #03 -->
  1275.                 <xsl:when test="$number-shape-code = 3"/>
  1276.                 <!-- Devanagari (Sanskrit - India), #04-->
  1277.                 <xsl:when test="$number-shape-code = 4">
  1278.                     <xsl:attribute name="number:transliteration-language">sa</xsl:attribute>
  1279.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1280.                 </xsl:when>
  1281.                 <!-- Bengali (India), #05 -->
  1282.                 <xsl:when test="$number-shape-code = 5">
  1283.                     <xsl:attribute name="number:transliteration-language">bn</xsl:attribute>
  1284.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1285.                 </xsl:when>
  1286.                 <!-- Gurmukhi (Punjabi - India), #06 -->
  1287.                 <xsl:when test="$number-shape-code = 6">
  1288.                     <xsl:attribute name="number:transliteration-language">pa</xsl:attribute>
  1289.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1290.                 </xsl:when>
  1291.                 <!-- Gujarati (India), #07 -->
  1292.                 <xsl:when test="$number-shape-code = 7">
  1293.                     <xsl:attribute name="number:transliteration-language">gu</xsl:attribute>
  1294.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1295.                 </xsl:when>
  1296.                 <!-- Oriya (India), #08 -->
  1297.                 <xsl:when test="$number-shape-code = 8">
  1298.                     <xsl:attribute name="number:transliteration-language">or</xsl:attribute>
  1299.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1300.                 </xsl:when>
  1301.                 <!-- Tamil (India), #09 -->
  1302.                 <xsl:when test="$number-shape-code = 9">
  1303.                     <xsl:attribute name="number:transliteration-language">ta</xsl:attribute>
  1304.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1305.                 </xsl:when>
  1306.                 <!-- Telugu (India), #0a -->
  1307.                 <xsl:when test="$number-shape-code = 10">
  1308.                     <xsl:attribute name="number:transliteration-language">te</xsl:attribute>
  1309.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1310.                 </xsl:when>
  1311.                 <!-- Kannada (India), #0b -->
  1312.                 <xsl:when test="$number-shape-code = 11">
  1313.                     <xsl:attribute name="number:transliteration-language">kn</xsl:attribute>
  1314.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1315.                 </xsl:when>
  1316.                 <!-- Malayalam (India), #0c -->
  1317.                 <xsl:when test="$number-shape-code = 12">
  1318.                     <xsl:attribute name="number:transliteration-language">ml</xsl:attribute>
  1319.                     <xsl:attribute name="number:transliteration-country">IN</xsl:attribute>
  1320.                 </xsl:when>
  1321.                 <!-- Thai, #0d -->
  1322.                 <xsl:when test="$number-shape-code = 13">
  1323.                     <xsl:attribute name="number:transliteration-language">th</xsl:attribute>
  1324.                     <xsl:attribute name="number:transliteration-country">TH</xsl:attribute>
  1325.                 </xsl:when>
  1326.                 <!-- Lao, #0e -->
  1327.                 <xsl:when test="$number-shape-code = 14">
  1328.                     <xsl:attribute name="number:transliteration-language">lo</xsl:attribute>
  1329.                     <xsl:attribute name="number:transliteration-country">LA</xsl:attribute>
  1330.                 </xsl:when>
  1331.                 <!-- Tibetan (China), #0f -->
  1332.                 <xsl:when test="$number-shape-code = 15">
  1333.                     <xsl:attribute name="number:transliteration-language">bo</xsl:attribute>
  1334.                     <xsl:attribute name="number:transliteration-country">CN</xsl:attribute>
  1335.                 </xsl:when>
  1336.                 <!-- Myanmar (Burma), #10 -->
  1337.                 <xsl:when test="$number-shape-code = 16">
  1338.                     <xsl:attribute name="number:transliteration-language">my</xsl:attribute>
  1339.                     <xsl:attribute name="number:transliteration-country">MM</xsl:attribute>
  1340.                 </xsl:when>
  1341.                 <!-- Ethiopic (Geez), #11 -->
  1342.                 <xsl:when test="$number-shape-code = 17">
  1343.                     <xsl:attribute name="number:transliteration-language">gez</xsl:attribute>
  1344.                     <xsl:attribute name="number:transliteration-country">ET</xsl:attribute>
  1345.                 </xsl:when>
  1346.                 <!-- Khmer (Cambodian), #12-->
  1347.                 <xsl:when test="$number-shape-code = 18">
  1348.                     <xsl:attribute name="number:transliteration-language">km</xsl:attribute>
  1349.                     <xsl:attribute name="number:transliteration-country">KH</xsl:attribute>
  1350.                 </xsl:when>
  1351.                 <!-- Mongolian, #13 -->
  1352.                 <xsl:when test="$number-shape-code = 19">
  1353.                     <xsl:attribute name="number:transliteration-language">mn</xsl:attribute>
  1354.                     <xsl:attribute name="number:transliteration-country">CN</xsl:attribute>
  1355.                 </xsl:when>
  1356.                 <!-- Japanese 1 ([DBNum1]) , #1b, #0411 -->
  1357.                 <xsl:when test="$number-shape-code = 27 or ($number-code-style = '1' and $language-country-code = 1041)">
  1358.                     <xsl:attribute name="number:transliteration-format">Σ╕Ç</xsl:attribute>
  1359.                     <xsl:attribute name="number:transliteration-language">ja</xsl:attribute>
  1360.                     <xsl:attribute name="number:transliteration-country">JP</xsl:attribute>
  1361.                 </xsl:when>
  1362.                 <!-- Japanese 2 ([DBNum2]) ,#1c, #0411 -->
  1363.                 <xsl:when test="$number-shape-code = 28 or ($number-code-style = '2' and $language-country-code = 1041 )">
  1364.                     <xsl:attribute name="number:transliteration-format">σú╣</xsl:attribute>
  1365.                     <xsl:attribute name="number:transliteration-language">ja</xsl:attribute>
  1366.                     <xsl:attribute name="number:transliteration-country">JP</xsl:attribute>
  1367.                 </xsl:when>
  1368.                 <!-- Japanese 3 ([DBNum3]), #1d, #0411 -->
  1369.                 <xsl:when test="$number-shape-code = 29 or ($number-code-style = '3' and $language-country-code = 1041 )">
  1370.                     <xsl:attribute name="number:transliteration-format">∩╝æ</xsl:attribute>
  1371.                     <xsl:attribute name="number:transliteration-language">ja</xsl:attribute>
  1372.                     <xsl:attribute name="number:transliteration-country">JP</xsl:attribute>
  1373.                 </xsl:when>
  1374.                 <!-- Simplified Chinese 1 ([DBNum1]), #1e, #0804 -->
  1375.                 <xsl:when test="$number-shape-code = 30 or ($number-code-style = '1' and $language-country-code = 2052 )">
  1376.                     <xsl:attribute name="number:transliteration-format">Σ╕Ç</xsl:attribute>
  1377.                     <xsl:attribute name="number:transliteration-language">zh</xsl:attribute>
  1378.                     <xsl:attribute name="number:transliteration-country">CN</xsl:attribute>
  1379.                 </xsl:when>
  1380.                 <!-- Simplified Chinese 2 ([DBNum2]),#1f,#0804 -->
  1381.                 <xsl:when test="$number-shape-code = 31 or ($number-code-style = '2' and $language-country-code = 2052 )">
  1382.                     <xsl:attribute name="number:transliteration-format">σú╣</xsl:attribute>
  1383.                     <xsl:attribute name="number:transliteration-language">zh</xsl:attribute>
  1384.                     <xsl:attribute name="number:transliteration-country">CN</xsl:attribute>
  1385.                 </xsl:when>
  1386.                 <!-- Simplified Chinese 3 ([DBNum3]), #20,#0804 -->
  1387.                 <xsl:when test="$number-shape-code = 32 or ($number-code-style = '3' and $language-country-code = 2052 )">
  1388.                     <xsl:attribute name="number:transliteration-format">∩╝æ</xsl:attribute>
  1389.                     <xsl:attribute name="number:transliteration-language">zh</xsl:attribute>
  1390.                     <xsl:attribute name="number:transliteration-country">CN</xsl:attribute>
  1391.                 </xsl:when>
  1392.                 <!-- Traditional Chinese 1 ([DBNum1]), #21, #0404 -->
  1393.                 <xsl:when test="$number-shape-code = 33 or ($number-code-style = '1' and $language-country-code = 1028 )">
  1394.                     <xsl:attribute name="number:transliteration-format">Σ╕Ç</xsl:attribute>
  1395.                     <xsl:attribute name="number:transliteration-language">zh</xsl:attribute>
  1396.                     <xsl:attribute name="number:transliteration-country">TW</xsl:attribute>
  1397.                 </xsl:when>
  1398.                 <!-- Traditional Chinese 2 ([DBNum2]), #22, #0404 -->
  1399.                 <xsl:when test="$number-shape-code = 34 or ($number-code-style = '2' and $language-country-code = 1028 )">
  1400.                     <xsl:attribute name="number:transliteration-format">σú╣</xsl:attribute>
  1401.                     <xsl:attribute name="number:transliteration-language">zh</xsl:attribute>
  1402.                     <xsl:attribute name="number:transliteration-country">TW</xsl:attribute>
  1403.                 </xsl:when>
  1404.                 <!-- Traditional Chinese 3 ([DBNum3]),#23, #0404  -->
  1405.                 <xsl:when test="$number-shape-code = 35 or ($number-code-style = '3' and $language-country-code = 1028 )">
  1406.                     <xsl:attribute name="number:transliteration-format">∩╝æ</xsl:attribute>
  1407.                     <xsl:attribute name="number:transliteration-language">zh</xsl:attribute>
  1408.                     <xsl:attribute name="number:transliteration-country">TW</xsl:attribute>
  1409.                 </xsl:when>
  1410.                 <!-- Korean 1 ([DBNum1]), #24, #0412 -->
  1411.                 <xsl:when test="$number-shape-code = 36 or ($number-code-style = '1' and $language-country-code = 1042 )">
  1412.                     <xsl:attribute name="number:transliteration-format">Σ╕Ç</xsl:attribute>
  1413.                     <xsl:attribute name="number:transliteration-language">ko</xsl:attribute>
  1414.                     <xsl:attribute name="number:transliteration-country">KR</xsl:attribute>
  1415.                 </xsl:when>
  1416.                 <!-- Korean 2 ([DBNum2]), #25, #0412 -->
  1417.                 <xsl:when test="$number-shape-code = 37 or ($number-code-style = '2' and $language-country-code = 1042 )">
  1418.                     <xsl:attribute name="number:transliteration-format">σú╣</xsl:attribute>
  1419.                     <xsl:attribute name="number:transliteration-language">ko</xsl:attribute>
  1420.                     <xsl:attribute name="number:transliteration-country">KR</xsl:attribute>
  1421.                 </xsl:when>
  1422.                 <!-- Korean 3 ([DBNum3]), #26, #0412 -->
  1423.                 <xsl:when test="$number-shape-code = 38 or ($number-code-style = '3' and $language-country-code = 1042 )">
  1424.                     <xsl:attribute name="number:transliteration-format">∩╝æ</xsl:attribute>
  1425.                     <xsl:attribute name="number:transliteration-language">ko</xsl:attribute>
  1426.                     <xsl:attribute name="number:transliteration-country">KR</xsl:attribute>
  1427.                 </xsl:when>
  1428.                 <!-- Korean 4 ([DBNum4]), #27, #0412 -->
  1429.                 <xsl:when test="$number-shape-code = 39 or ($number-code-style = '4' and $language-country-code = 1042 )">
  1430.                     <xsl:attribute name="number:transliteration-format">1</xsl:attribute>
  1431.                     <xsl:attribute name="number:transliteration-language">ko</xsl:attribute>
  1432.                     <xsl:attribute name="number:transliteration-country">KR</xsl:attribute>
  1433.                 </xsl:when>
  1434.             </xsl:choose>
  1435.         </xsl:if>
  1436.         <!-- components of a format code: two digits  for number shape codes, two for calendar types, four for LCID -->
  1437.         <xsl:choose>
  1438.             <!-- totally 223 language-country LCID codes, manually created, among which MS Office 2003 supports 134, OOo supports 91 -->
  1439.             <xsl:when test="$language-country-code = 1078">
  1440.                 <!-- Afrikaans - South Africa, #0436 -->
  1441.                 <xsl:attribute name="number:language">af</xsl:attribute>
  1442.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  1443.             </xsl:when>
  1444.             <xsl:when test="$language-country-code = 1052">
  1445.                 <!-- Albanian - Albania, #041c -->
  1446.                 <xsl:attribute name="number:language">sq</xsl:attribute>
  1447.                 <xsl:attribute name="number:country">AL</xsl:attribute>
  1448.             </xsl:when>
  1449.             <xsl:when test="$language-country-code = 1118">
  1450.                 <!-- Amharic - Ethiopia, #045e -->
  1451.                 <xsl:attribute name="number:language">am</xsl:attribute>
  1452.                 <xsl:attribute name="number:country">ET</xsl:attribute>
  1453.             </xsl:when>
  1454.             <xsl:when test="$language-country-code = 1025">
  1455.                 <!-- Arabic - Saudi Arabia, #0401 -->
  1456.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1457.                 <xsl:attribute name="number:country">SA</xsl:attribute>
  1458.             </xsl:when>
  1459.             <xsl:when test="$language-country-code = 5121">
  1460.                 <!-- Arabic - Algeria, #1401 -->
  1461.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1462.                 <xsl:attribute name="number:country">DZ</xsl:attribute>
  1463.             </xsl:when>
  1464.             <xsl:when test="$language-country-code = 15361">
  1465.                 <!-- Arabic - Bahrain, #3c01 -->
  1466.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1467.                 <xsl:attribute name="number:country">BH</xsl:attribute>
  1468.             </xsl:when>
  1469.             <xsl:when test="$language-country-code = 3073">
  1470.                 <!-- Arabic - Egypt, #0c01 -->
  1471.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1472.                 <xsl:attribute name="number:country">EG</xsl:attribute>
  1473.             </xsl:when>
  1474.             <xsl:when test="$language-country-code = 2049">
  1475.                 <!-- Arabic - Iraq, #0801 -->
  1476.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1477.                 <xsl:attribute name="number:country">IQ</xsl:attribute>
  1478.             </xsl:when>
  1479.             <xsl:when test="$language-country-code = 11265">
  1480.                 <!-- Arabic - Jordan, #2c01 -->
  1481.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1482.                 <xsl:attribute name="number:country">JO</xsl:attribute>
  1483.             </xsl:when>
  1484.             <xsl:when test="$language-country-code = 13313">
  1485.                 <!-- Arabic - Kuwait, #3401 -->
  1486.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1487.                 <xsl:attribute name="number:country">KW</xsl:attribute>
  1488.             </xsl:when>
  1489.             <xsl:when test="$language-country-code = 12289">
  1490.                 <!-- Arabic - Lebanon, #3001 -->
  1491.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1492.                 <xsl:attribute name="number:country">LB</xsl:attribute>
  1493.             </xsl:when>
  1494.             <xsl:when test="$language-country-code = 4097">
  1495.                 <!-- Arabic - Libya, #1001 -->
  1496.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1497.                 <xsl:attribute name="number:country">LY</xsl:attribute>
  1498.             </xsl:when>
  1499.             <xsl:when test="$language-country-code = 6145">
  1500.                 <!-- Arabic - Morocco, #1801 -->
  1501.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1502.                 <xsl:attribute name="number:country">MA</xsl:attribute>
  1503.             </xsl:when>
  1504.             <xsl:when test="$language-country-code = 8193">
  1505.                 <!-- Arabic - Oman, #2001 -->
  1506.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1507.                 <xsl:attribute name="number:country">OM</xsl:attribute>
  1508.             </xsl:when>
  1509.             <xsl:when test="$language-country-code = 16385">
  1510.                 <!-- Arabic - Qatar, #4001 -->
  1511.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1512.                 <xsl:attribute name="number:country">QA</xsl:attribute>
  1513.             </xsl:when>
  1514.             <xsl:when test="$language-country-code = 10241">
  1515.                 <!-- Arabic - Syria, #2801 -->
  1516.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1517.                 <xsl:attribute name="number:country">SY</xsl:attribute>
  1518.             </xsl:when>
  1519.             <xsl:when test="$language-country-code = 7169">
  1520.                 <!-- Arabic - Tunisia, #1c01 -->
  1521.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1522.                 <xsl:attribute name="number:country">TN</xsl:attribute>
  1523.             </xsl:when>
  1524.             <xsl:when test="$language-country-code = 14337">
  1525.                 <!-- Arabic - U.A.E., #3801 -->
  1526.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1527.                 <xsl:attribute name="number:country">AE</xsl:attribute>
  1528.             </xsl:when>
  1529.             <xsl:when test="$language-country-code = 9217">
  1530.                 <!-- Arabic - Yemen, #2401 -->
  1531.                 <xsl:attribute name="number:language">ar</xsl:attribute>
  1532.                 <xsl:attribute name="number:country">YE</xsl:attribute>
  1533.             </xsl:when>
  1534.             <xsl:when test="$language-country-code = 1067">
  1535.                 <!-- Armenian - Armenia, #042b -->
  1536.                 <xsl:attribute name="number:language">hy</xsl:attribute>
  1537.                 <xsl:attribute name="number:country">AM</xsl:attribute>
  1538.             </xsl:when>
  1539.             <xsl:when test="$language-country-code = 1101">
  1540.                 <!-- Assamese, #044d -->
  1541.                 <xsl:attribute name="number:language">as</xsl:attribute>
  1542.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  1543.             </xsl:when>
  1544.             <xsl:when test="$language-country-code = 2092">
  1545.                 <!-- Azeri - Cyrillic, #082c -->
  1546.                 <xsl:attribute name="number:language">az</xsl:attribute>
  1547.                 <xsl:attribute name="number:country">AZ</xsl:attribute>
  1548.             </xsl:when>
  1549.             <xsl:when test="$language-country-code = 1068">
  1550.                 <!-- Azeri - Latin, #042c -->
  1551.                 <xsl:attribute name="number:language">az</xsl:attribute>
  1552.                 <xsl:attribute name="number:country">AZ</xsl:attribute>
  1553.             </xsl:when>
  1554.             <xsl:when test="$language-country-code = 1069">
  1555.                 <!-- Basque - France/Spain, #042d -->
  1556.                 <xsl:attribute name="number:language">eu</xsl:attribute>
  1557.                 <xsl:attribute name="number:country">ES</xsl:attribute>
  1558.             </xsl:when>
  1559.             <xsl:when test="$language-country-code = 1059">
  1560.                 <!-- Belarusian - Belarus, #0423 -->
  1561.                 <xsl:attribute name="number:language">be</xsl:attribute>
  1562.                 <xsl:attribute name="number:country">BY</xsl:attribute>
  1563.             </xsl:when>
  1564.             <xsl:when test="$language-country-code = 1093">
  1565.                 <!-- Bengali (India), #0445 -->
  1566.                 <xsl:attribute name="number:language">bn</xsl:attribute>
  1567.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  1568.             </xsl:when>
  1569.             <xsl:when test="$language-country-code = 2117">
  1570.                 <!-- Bengali (Bangladesh), #0845 -->
  1571.                 <xsl:attribute name="number:language">bn</xsl:attribute>
  1572.                 <xsl:attribute name="number:country">BD</xsl:attribute>
  1573.             </xsl:when>
  1574.             <xsl:when test="$language-country-code = 5146">
  1575.                 <!-- Bosnian (Bosnia/Herzegovina), #141a -->
  1576.                 <xsl:attribute name="number:language">bs</xsl:attribute>
  1577.                 <xsl:attribute name="number:country">BA</xsl:attribute>
  1578.             </xsl:when>
  1579.             <xsl:when test="$language-country-code = 1026">
  1580.                 <!-- Bulgarian, #0402 -->
  1581.                 <xsl:attribute name="number:language">bg</xsl:attribute>
  1582.                 <xsl:attribute name="number:country">BG</xsl:attribute>
  1583.             </xsl:when>
  1584.             <xsl:when test="$language-country-code = 1109">
  1585.                 <!-- Burmese (Burma/Myanmar), #0455 -->
  1586.                 <xsl:attribute name="number:language">my</xsl:attribute>
  1587.                 <xsl:attribute name="number:country">MM</xsl:attribute>
  1588.             </xsl:when>
  1589.             <xsl:when test="$language-country-code = 1027">
  1590.                 <!-- Catalan - Spain, #0403 -->
  1591.                 <xsl:attribute name="number:language">ca</xsl:attribute>
  1592.                 <xsl:attribute name="number:country">ES</xsl:attribute>
  1593.             </xsl:when>
  1594.             <xsl:when test="$language-country-code = 1116">
  1595.                 <!-- Cherokee - United States, #045c -->
  1596.                 <xsl:attribute name="number:language">chr</xsl:attribute>
  1597.                 <xsl:attribute name="number:country">US</xsl:attribute>
  1598.             </xsl:when>
  1599.             <xsl:when test="$language-country-code = 2052">
  1600.                 <!-- Chinese - People's Republic of China, #0804 -->
  1601.                 <xsl:attribute name="number:language">zh</xsl:attribute>
  1602.                 <xsl:attribute name="number:country">CN</xsl:attribute>
  1603.             </xsl:when>
  1604.             <xsl:when test="$language-country-code = 4100">
  1605.                 <!-- Chinese - Singapore, #1004 -->
  1606.                 <xsl:attribute name="number:language">zh</xsl:attribute>
  1607.                 <xsl:attribute name="number:country">SG</xsl:attribute>
  1608.             </xsl:when>
  1609.             <xsl:when test="$language-country-code = 1028">
  1610.                 <!-- Chinese - Taiwan, #0404 -->
  1611.                 <xsl:attribute name="number:language">zh</xsl:attribute>
  1612.                 <xsl:attribute name="number:country">TW</xsl:attribute>
  1613.             </xsl:when>
  1614.             <xsl:when test="$language-country-code = 3076">
  1615.                 <!-- Chinese - Hong Kong SAR, #0c04 -->
  1616.                 <xsl:attribute name="number:language">zh</xsl:attribute>
  1617.                 <xsl:attribute name="number:country">HK</xsl:attribute>
  1618.             </xsl:when>
  1619.             <xsl:when test="$language-country-code = 5124">
  1620.                 <!-- Chinese - Macao SAR, #1404 -->
  1621.                 <xsl:attribute name="number:language">zh</xsl:attribute>
  1622.                 <xsl:attribute name="number:country">MO</xsl:attribute>
  1623.             </xsl:when>
  1624.             <xsl:when test="$language-country-code = 1050">
  1625.                 <!-- Croatian (Croatia), #041a -->
  1626.                 <xsl:attribute name="number:language">hr</xsl:attribute>
  1627.                 <xsl:attribute name="number:country">HR</xsl:attribute>
  1628.             </xsl:when>
  1629.             <xsl:when test="$language-country-code = 4122">
  1630.                 <!-- Croatian (Bosnia/Herzegovina), #101a -->
  1631.                 <xsl:attribute name="number:language">hr</xsl:attribute>
  1632.                 <xsl:attribute name="number:country">BA</xsl:attribute>
  1633.             </xsl:when>
  1634.             <xsl:when test="$language-country-code = 1029">
  1635.                 <!-- Czech, #0405 -->
  1636.                 <xsl:attribute name="number:language">cs</xsl:attribute>
  1637.                 <xsl:attribute name="number:country">CZ</xsl:attribute>
  1638.             </xsl:when>
  1639.             <xsl:when test="$language-country-code = 1030">
  1640.                 <!-- Danish, #0406 -->
  1641.                 <xsl:attribute name="number:language">da</xsl:attribute>
  1642.                 <xsl:attribute name="number:country">DK</xsl:attribute>
  1643.             </xsl:when>
  1644.             <xsl:when test="$language-country-code = 1125">
  1645.                 <!-- Divehi, #0465 -->
  1646.                 <xsl:attribute name="number:language">dv</xsl:attribute>
  1647.                 <xsl:attribute name="number:country">MV</xsl:attribute>
  1648.             </xsl:when>
  1649.             <xsl:when test="$language-country-code = 1043">
  1650.                 <!-- Dutch - Netherlands, #0413 -->
  1651.                 <xsl:attribute name="number:language">nl</xsl:attribute>
  1652.                 <xsl:attribute name="number:country">NL</xsl:attribute>
  1653.             </xsl:when>
  1654.             <xsl:when test="$language-country-code = 2067">
  1655.                 <!-- Dutch - Belgium, #0813 -->
  1656.                 <xsl:attribute name="number:language">nl</xsl:attribute>
  1657.                 <xsl:attribute name="number:country">BE</xsl:attribute>
  1658.             </xsl:when>
  1659.             <xsl:when test="$language-country-code = 1126">
  1660.                 <!-- Edo (Bini - Nigeria), #0466 -->
  1661.                 <xsl:attribute name="number:language">bin</xsl:attribute>
  1662.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  1663.             </xsl:when>
  1664.             <xsl:when test="$language-country-code = 1033">
  1665.                 <!-- English - United States, #0409 -->
  1666.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1667.                 <xsl:attribute name="number:country">US</xsl:attribute>
  1668.             </xsl:when>
  1669.             <xsl:when test="$language-country-code = 2057">
  1670.                 <!-- English - United Kingdom, #0809 -->
  1671.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1672.                 <xsl:attribute name="number:country">GB</xsl:attribute>
  1673.             </xsl:when>
  1674.             <xsl:when test="$language-country-code = 3081">
  1675.                 <!-- English - Australia, #0c09 -->
  1676.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1677.                 <xsl:attribute name="number:country">AU</xsl:attribute>
  1678.             </xsl:when>
  1679.             <xsl:when test="$language-country-code = 10249">
  1680.                 <!-- English - Belize, #2809 -->
  1681.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1682.                 <xsl:attribute name="number:country">BZ</xsl:attribute>
  1683.             </xsl:when>
  1684.             <xsl:when test="$language-country-code = 4105">
  1685.                 <!-- English - Canada, #1009 -->
  1686.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1687.                 <xsl:attribute name="number:country">CA</xsl:attribute>
  1688.             </xsl:when>
  1689.             <xsl:when test="$language-country-code = 9225">
  1690.                 <!-- English - Caribbean (Cuba), #2409 -->
  1691.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1692.                 <xsl:attribute name="number:country">CU</xsl:attribute>
  1693.             </xsl:when>
  1694.             <xsl:when test="$language-country-code = 15369">
  1695.                 <!-- English - Hong Kong SAR, #3c09 -->
  1696.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1697.                 <xsl:attribute name="number:country">HK</xsl:attribute>
  1698.             </xsl:when>
  1699.             <xsl:when test="$language-country-code = 16393">
  1700.                 <!-- English - India, #4009 -->
  1701.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1702.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  1703.             </xsl:when>
  1704.             <xsl:when test="$language-country-code = 14345">
  1705.                 <!-- English - Indonesia, #3809 -->
  1706.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1707.                 <xsl:attribute name="number:country">ID</xsl:attribute>
  1708.             </xsl:when>
  1709.             <xsl:when test="$language-country-code = 6153">
  1710.                 <!-- English - Ireland, #1809 -->
  1711.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1712.                 <xsl:attribute name="number:country">IE</xsl:attribute>
  1713.             </xsl:when>
  1714.             <xsl:when test="$language-country-code = 8201">
  1715.                 <!-- English - Jamaica, #2009 -->
  1716.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1717.                 <xsl:attribute name="number:country">JM</xsl:attribute>
  1718.             </xsl:when>
  1719.             <xsl:when test="$language-country-code = 17417">
  1720.                 <!-- English - Malaysia, #4409 -->
  1721.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1722.                 <xsl:attribute name="number:country">MY</xsl:attribute>
  1723.             </xsl:when>
  1724.             <xsl:when test="$language-country-code = 5129">
  1725.                 <!-- English - New Zealand, #1409 -->
  1726.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1727.                 <xsl:attribute name="number:country">NZ</xsl:attribute>
  1728.             </xsl:when>
  1729.             <xsl:when test="$language-country-code = 13321">
  1730.                 <!-- English - Philippines, #3409 -->
  1731.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1732.                 <xsl:attribute name="number:country">PH</xsl:attribute>
  1733.             </xsl:when>
  1734.             <xsl:when test="$language-country-code = 18441">
  1735.                 <!-- English - Singapore, #4809 -->
  1736.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1737.                 <xsl:attribute name="number:country">SG</xsl:attribute>
  1738.             </xsl:when>
  1739.             <xsl:when test="$language-country-code = 7177">
  1740.                 <!-- English - South Africa, #1c09 -->
  1741.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1742.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  1743.             </xsl:when>
  1744.             <xsl:when test="$language-country-code = 11273">
  1745.                 <!-- English - Trinidad, #2c09 -->
  1746.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1747.                 <xsl:attribute name="number:country">TT</xsl:attribute>
  1748.             </xsl:when>
  1749.             <xsl:when test="$language-country-code = 12297">
  1750.                 <!-- English - Zimbabwe, #3009 -->
  1751.                 <xsl:attribute name="number:language">en</xsl:attribute>
  1752.                 <xsl:attribute name="number:country">ZW</xsl:attribute>
  1753.             </xsl:when>
  1754.             <xsl:when test="$language-country-code = 1061">
  1755.                 <!-- Estonian (Estonia), #0425 -->
  1756.                 <xsl:attribute name="number:language">et</xsl:attribute>
  1757.                 <xsl:attribute name="number:country">EE</xsl:attribute>
  1758.             </xsl:when>
  1759.             <xsl:when test="$language-country-code = 1080">
  1760.                 <!-- Faroese (Faroe Islands), #0438 -->
  1761.                 <xsl:attribute name="number:language">fo</xsl:attribute>
  1762.                 <xsl:attribute name="number:country">FO</xsl:attribute>
  1763.             </xsl:when>
  1764.             <xsl:when test="$language-country-code = 1065">
  1765.                 <!-- Farsi (Persian/Iran), #0429 -->
  1766.                 <xsl:attribute name="number:language">fa</xsl:attribute>
  1767.                 <xsl:attribute name="number:country">IR</xsl:attribute>
  1768.             </xsl:when>
  1769.             <xsl:when test="$language-country-code = 1124">
  1770.                 <!-- Filipino (Philippine), #0464 -->
  1771.                 <xsl:attribute name="number:language">phi</xsl:attribute>
  1772.                 <xsl:attribute name="number:country">PH</xsl:attribute>
  1773.             </xsl:when>
  1774.             <xsl:when test="$language-country-code = 1035">
  1775.                 <!-- Finnish, #040b -->
  1776.                 <xsl:attribute name="number:language">fi</xsl:attribute>
  1777.                 <xsl:attribute name="number:country">FI</xsl:attribute>
  1778.             </xsl:when>
  1779.             <xsl:when test="$language-country-code = 1036">
  1780.                 <!-- French - France, #040c -->
  1781.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1782.                 <xsl:attribute name="number:country">FR</xsl:attribute>
  1783.             </xsl:when>
  1784.             <xsl:when test="$language-country-code = 2060">
  1785.                 <!-- French - Belgium, #080c -->
  1786.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1787.                 <xsl:attribute name="number:country">BE</xsl:attribute>
  1788.             </xsl:when>
  1789.             <xsl:when test="$language-country-code = 11276">
  1790.                 <!-- French - Cameroon, #2c0c -->
  1791.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1792.                 <xsl:attribute name="number:country">CM</xsl:attribute>
  1793.             </xsl:when>
  1794.             <xsl:when test="$language-country-code = 3084">
  1795.                 <!-- French - Canada, #0c0c -->
  1796.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1797.                 <xsl:attribute name="number:country">CA</xsl:attribute>
  1798.             </xsl:when>
  1799.             <xsl:when test="$language-country-code = 9228">
  1800.                 <!-- French - Congo, #240c -->
  1801.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1802.                 <xsl:attribute name="number:country">CG</xsl:attribute>
  1803.             </xsl:when>
  1804.             <xsl:when test="$language-country-code = 12300">
  1805.                 <!-- French - Cote d'Ivoire, #300c -->
  1806.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1807.                 <xsl:attribute name="number:country">CI</xsl:attribute>
  1808.             </xsl:when>
  1809.             <xsl:when test="$language-country-code = 15372">
  1810.                 <!-- French - Haiti, #3c0c -->
  1811.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1812.                 <xsl:attribute name="number:country">HT</xsl:attribute>
  1813.             </xsl:when>
  1814.             <xsl:when test="$language-country-code = 5132">
  1815.                 <!-- French - Luxembourg, #140c -->
  1816.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1817.                 <xsl:attribute name="number:country">LU</xsl:attribute>
  1818.             </xsl:when>
  1819.             <xsl:when test="$language-country-code = 13324">
  1820.                 <!-- French - Mali, #340c -->
  1821.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1822.                 <xsl:attribute name="number:country">ML</xsl:attribute>
  1823.             </xsl:when>
  1824.             <xsl:when test="$language-country-code = 6156">
  1825.                 <!-- French - Monaco, #180c -->
  1826.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1827.                 <xsl:attribute name="number:country">MC</xsl:attribute>
  1828.             </xsl:when>
  1829.             <xsl:when test="$language-country-code = 14348">
  1830.                 <!-- French - Morocco, #380c -->
  1831.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1832.                 <xsl:attribute name="number:country">MA</xsl:attribute>
  1833.             </xsl:when>
  1834.             <xsl:when test="$language-country-code = 58380">
  1835.                 <!-- French - North Africa (Algeria), #e40c -->
  1836.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1837.                 <xsl:attribute name="number:country">DZ</xsl:attribute>
  1838.             </xsl:when>
  1839.             <xsl:when test="$language-country-code = 8204">
  1840.                 <!-- French - Reunion, #200c -->
  1841.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1842.                 <xsl:attribute name="number:country">RE</xsl:attribute>
  1843.             </xsl:when>
  1844.             <xsl:when test="$language-country-code = 10252">
  1845.                 <!-- French - Senegal, #280c -->
  1846.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1847.                 <xsl:attribute name="number:country">SN</xsl:attribute>
  1848.             </xsl:when>
  1849.             <xsl:when test="$language-country-code = 4108">
  1850.                 <!-- French - Switzerland, #100c -->
  1851.                 <xsl:attribute name="number:language">fr</xsl:attribute>
  1852.                 <xsl:attribute name="number:country">CH</xsl:attribute>
  1853.             </xsl:when>
  1854.             <xsl:when test="$language-country-code = 1122">
  1855.                 <!-- Frisian - Netherlands, #0462 -->
  1856.                 <xsl:attribute name="number:language">fy</xsl:attribute>
  1857.                 <xsl:attribute name="number:country">NL</xsl:attribute>
  1858.             </xsl:when>
  1859.             <xsl:when test="$language-country-code = 1127">
  1860.                 <!-- Fulfude (Fulah) - Nigeria, #0467 -->
  1861.                 <xsl:attribute name="number:language">ff</xsl:attribute>
  1862.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  1863.             </xsl:when>
  1864.             <xsl:when test="$language-country-code = 1071">
  1865.                 <!-- FYRO Macedonian, #042f -->
  1866.                 <xsl:attribute name="number:language">mk</xsl:attribute>
  1867.                 <xsl:attribute name="number:country">MK</xsl:attribute>
  1868.             </xsl:when>
  1869.             <xsl:when test="$language-country-code = 2108">
  1870.                 <!-- Gaelic (Ireland), #083c -->
  1871.                 <xsl:attribute name="number:language">gd</xsl:attribute>
  1872.                 <xsl:attribute name="number:country">IE</xsl:attribute>
  1873.             </xsl:when>
  1874.             <xsl:when test="$language-country-code = 1084">
  1875.                 <!-- Gaelic (Scotland), #043c -->
  1876.                 <xsl:attribute name="number:language">gd</xsl:attribute>
  1877.                 <xsl:attribute name="number:country">GB</xsl:attribute>
  1878.             </xsl:when>
  1879.             <xsl:when test="$language-country-code = 1110">
  1880.                 <!-- Galician (Gallegan) - Spain, #0456 -->
  1881.                 <xsl:attribute name="number:language">gl</xsl:attribute>
  1882.                 <xsl:attribute name="number:country">ES</xsl:attribute>
  1883.             </xsl:when>
  1884.             <xsl:when test="$language-country-code = 1079">
  1885.                 <!-- Georgian - Georgia, #0437 -->
  1886.                 <xsl:attribute name="number:language">ka</xsl:attribute>
  1887.                 <xsl:attribute name="number:country">GE</xsl:attribute>
  1888.             </xsl:when>
  1889.             <xsl:when test="$language-country-code = 1031">
  1890.                 <!-- German - Germany, #0407 -->
  1891.                 <xsl:attribute name="number:language">de</xsl:attribute>
  1892.                 <xsl:attribute name="number:country">DE</xsl:attribute>
  1893.             </xsl:when>
  1894.             <xsl:when test="$language-country-code = 3079">
  1895.                 <!-- German - Austria, #0c07 -->
  1896.                 <xsl:attribute name="number:language">de</xsl:attribute>
  1897.                 <xsl:attribute name="number:country">AT</xsl:attribute>
  1898.             </xsl:when>
  1899.             <xsl:when test="$language-country-code = 5127">
  1900.                 <!-- German - Liechtenstein, #1407 -->
  1901.                 <xsl:attribute name="number:language">de</xsl:attribute>
  1902.                 <xsl:attribute name="number:country">LI</xsl:attribute>
  1903.             </xsl:when>
  1904.             <xsl:when test="$language-country-code = 4103">
  1905.                 <!-- German - Luxembourg, #1007 -->
  1906.                 <xsl:attribute name="number:language">de</xsl:attribute>
  1907.                 <xsl:attribute name="number:country">LU</xsl:attribute>
  1908.             </xsl:when>
  1909.             <xsl:when test="$language-country-code = 2055">
  1910.                 <!-- German - Switzerland, #0807 -->
  1911.                 <xsl:attribute name="number:language">de</xsl:attribute>
  1912.                 <xsl:attribute name="number:country">CH</xsl:attribute>
  1913.             </xsl:when>
  1914.             <xsl:when test="$language-country-code = 1032">
  1915.                 <!-- Greek, #0408 -->
  1916.                 <xsl:attribute name="number:language">el</xsl:attribute>
  1917.                 <xsl:attribute name="number:country">GR</xsl:attribute>
  1918.             </xsl:when>
  1919.             <xsl:when test="$language-country-code = 1140">
  1920.                 <!-- Guarani - Paraguay, #0474 -->
  1921.                 <xsl:attribute name="number:language">gn</xsl:attribute>
  1922.                 <xsl:attribute name="number:country">PY</xsl:attribute>
  1923.             </xsl:when>
  1924.             <xsl:when test="$language-country-code = 1095">
  1925.                 <!-- Gujarati - India, #0447 -->
  1926.                 <xsl:attribute name="number:language">gu</xsl:attribute>
  1927.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  1928.             </xsl:when>
  1929.             <xsl:when test="$language-country-code = 1128">
  1930.                 <!-- Hausa - Nigeria, #0468 -->
  1931.                 <xsl:attribute name="number:language">ha</xsl:attribute>
  1932.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  1933.             </xsl:when>
  1934.             <xsl:when test="$language-country-code = 1141">
  1935.                 <!-- Hawaiian - US, #0475 -->
  1936.                 <xsl:attribute name="number:language">haw</xsl:attribute>
  1937.                 <xsl:attribute name="number:country">US</xsl:attribute>
  1938.             </xsl:when>
  1939.             <xsl:when test="$language-country-code = 1037">
  1940.                 <!-- Hebrew, #040d -->
  1941.                 <xsl:attribute name="number:language">he</xsl:attribute>
  1942.                 <xsl:attribute name="number:country">IL</xsl:attribute>
  1943.             </xsl:when>
  1944.             <xsl:when test="$language-country-code = 1081">
  1945.                 <!-- Hindi (India), #0439 -->
  1946.                 <xsl:attribute name="number:language">hi</xsl:attribute>
  1947.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  1948.             </xsl:when>
  1949.             <xsl:when test="$language-country-code = 1038">
  1950.                 <!-- Hungarian - Hungary, #040e -->
  1951.                 <xsl:attribute name="number:language">hu</xsl:attribute>
  1952.                 <xsl:attribute name="number:country">HU</xsl:attribute>
  1953.             </xsl:when>
  1954.             <xsl:when test="$language-country-code = 1129">
  1955.                 <!-- Ibibio (Niger-Kordofanian) - Nigeria, #0469 -->
  1956.                 <xsl:attribute name="number:language">nic</xsl:attribute>
  1957.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  1958.             </xsl:when>
  1959.             <xsl:when test="$language-country-code = 1039">
  1960.                 <!-- Icelandic, #040f -->
  1961.                 <xsl:attribute name="number:language">is</xsl:attribute>
  1962.                 <xsl:attribute name="number:country">IS</xsl:attribute>
  1963.             </xsl:when>
  1964.             <xsl:when test="$language-country-code = 1136">
  1965.                 <!-- Igbo - Nigeria, #0470 -->
  1966.                 <xsl:attribute name="number:language">ig</xsl:attribute>
  1967.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  1968.             </xsl:when>
  1969.             <xsl:when test="$language-country-code = 1057">
  1970.                 <!-- Indonesian, #0421 -->
  1971.                 <xsl:attribute name="number:language">id</xsl:attribute>
  1972.                 <xsl:attribute name="number:country">ID</xsl:attribute>
  1973.             </xsl:when>
  1974.             <xsl:when test="$language-country-code = 1117">
  1975.                 <!-- Inuktitut - US, #045d -->
  1976.                 <xsl:attribute name="number:language">iu</xsl:attribute>
  1977.                 <xsl:attribute name="number:country">US</xsl:attribute>
  1978.             </xsl:when>
  1979.             <xsl:when test="$language-country-code = 1040">
  1980.                 <!-- Italian - Italy, #0410 -->
  1981.                 <xsl:attribute name="number:language">it</xsl:attribute>
  1982.                 <xsl:attribute name="number:country">IT</xsl:attribute>
  1983.             </xsl:when>
  1984.             <xsl:when test="$language-country-code = 2064">
  1985.                 <!-- Italian - Switzerland, #0810 -->
  1986.                 <xsl:attribute name="number:language">it</xsl:attribute>
  1987.                 <xsl:attribute name="number:country">CH</xsl:attribute>
  1988.             </xsl:when>
  1989.             <xsl:when test="$language-country-code = 1041">
  1990.                 <!-- Japanese, #0411 -->
  1991.                 <xsl:attribute name="number:language">ja</xsl:attribute>
  1992.                 <xsl:attribute name="number:country">JP</xsl:attribute>
  1993.             </xsl:when>
  1994.             <xsl:when test="$language-country-code = 1099">
  1995.                 <!-- Kannada (India), #044b -->
  1996.                 <xsl:attribute name="number:language">kn</xsl:attribute>
  1997.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  1998.             </xsl:when>
  1999.             <xsl:when test="$language-country-code = 1137">
  2000.                 <!-- Kanuri - Nigeria, #0471 -->
  2001.                 <xsl:attribute name="number:language">kr</xsl:attribute>
  2002.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  2003.             </xsl:when>
  2004.             <xsl:when test="$language-country-code = 2144">
  2005.                 <!-- Kashmiri (India), #0860 -->
  2006.                 <xsl:attribute name="number:language">ks</xsl:attribute>
  2007.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2008.             </xsl:when>
  2009.             <xsl:when test="$language-country-code = 1120">
  2010.                 <!-- Kashmiri (Arabic), #0460 -->
  2011.                 <xsl:attribute name="number:language">ks</xsl:attribute>
  2012.                 <xsl:attribute name="number:country">PK</xsl:attribute>
  2013.             </xsl:when>
  2014.             <xsl:when test="$language-country-code = 1087">
  2015.                 <!-- Kazakh, #043f -->
  2016.                 <xsl:attribute name="number:language">kk</xsl:attribute>
  2017.                 <xsl:attribute name="number:country">KZ</xsl:attribute>
  2018.             </xsl:when>
  2019.             <xsl:when test="$language-country-code = 1107">
  2020.                 <!-- Khmer (Cambodian), #0453 -->
  2021.                 <xsl:attribute name="number:language">km</xsl:attribute>
  2022.                 <xsl:attribute name="number:country">KH</xsl:attribute>
  2023.             </xsl:when>
  2024.             <xsl:when test="$language-country-code = 1111">
  2025.                 <!-- Konkani (India), #0457 -->
  2026.                 <xsl:attribute name="number:language">kok</xsl:attribute>
  2027.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2028.             </xsl:when>
  2029.             <xsl:when test="$language-country-code = 1042">
  2030.                 <!-- Korean, #0412 -->
  2031.                 <xsl:attribute name="number:language">ko</xsl:attribute>
  2032.                 <xsl:attribute name="number:country">KR</xsl:attribute>
  2033.             </xsl:when>
  2034.             <xsl:when test="$language-country-code = 1088">
  2035.                 <!-- Kyrgyz ( Kirgiz / Cyrillic), #0440 -->
  2036.                 <xsl:attribute name="number:language">ky</xsl:attribute>
  2037.                 <xsl:attribute name="number:country">KG</xsl:attribute>
  2038.             </xsl:when>
  2039.             <xsl:when test="$language-country-code = 1108">
  2040.                 <!-- Lao, #0454 -->
  2041.                 <xsl:attribute name="number:language">lo</xsl:attribute>
  2042.                 <xsl:attribute name="number:country">LA</xsl:attribute>
  2043.             </xsl:when>
  2044.             <xsl:when test="$language-country-code = 1142">
  2045.                 <!-- Latin, #0476 -->
  2046.                 <xsl:attribute name="number:language">la</xsl:attribute>
  2047.                 <xsl:attribute name="number:country">IT</xsl:attribute>
  2048.             </xsl:when>
  2049.             <xsl:when test="$language-country-code = 1062">
  2050.                 <!-- Latvian, #0426 -->
  2051.                 <xsl:attribute name="number:language">lv</xsl:attribute>
  2052.                 <xsl:attribute name="number:country">LV</xsl:attribute>
  2053.             </xsl:when>
  2054.             <xsl:when test="$language-country-code = 1063">
  2055.                 <!-- Lithuanian, #0427 -->
  2056.                 <xsl:attribute name="number:language">lt</xsl:attribute>
  2057.                 <xsl:attribute name="number:country">LT</xsl:attribute>
  2058.             </xsl:when>
  2059.             <xsl:when test="$language-country-code = 1086">
  2060.                 <!-- Malay - Malaysia, #043e -->
  2061.                 <xsl:attribute name="number:language">ms</xsl:attribute>
  2062.                 <xsl:attribute name="number:country">MY</xsl:attribute>
  2063.             </xsl:when>
  2064.             <xsl:when test="$language-country-code = 2110">
  2065.                 <!-- Malay - Brunei Darussalam, #083e -->
  2066.                 <xsl:attribute name="number:language">ms</xsl:attribute>
  2067.                 <xsl:attribute name="number:country">BN</xsl:attribute>
  2068.             </xsl:when>
  2069.             <xsl:when test="$language-country-code = 1071">
  2070.                 <!-- Macedonian (FYROM), #042f -->
  2071.                 <xsl:attribute name="number:language">mk</xsl:attribute>
  2072.                 <xsl:attribute name="number:country">MK</xsl:attribute>
  2073.             </xsl:when>
  2074.             <xsl:when test="$language-country-code = 1100">
  2075.                 <!-- Malayalam (India), #044c -->
  2076.                 <xsl:attribute name="number:language">ml</xsl:attribute>
  2077.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2078.             </xsl:when>
  2079.             <xsl:when test="$language-country-code = 1082">
  2080.                 <!-- Maltese, #043a -->
  2081.                 <xsl:attribute name="number:language">mt</xsl:attribute>
  2082.                 <xsl:attribute name="number:country">MT</xsl:attribute>
  2083.             </xsl:when>
  2084.             <xsl:when test="$language-country-code = 1112">
  2085.                 <!-- Manipuri (India), #0458 -->
  2086.                 <xsl:attribute name="number:language">mni</xsl:attribute>
  2087.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2088.             </xsl:when>
  2089.             <xsl:when test="$language-country-code = 1153">
  2090.                 <!-- Maori - New Zealand, #0481 -->
  2091.                 <xsl:attribute name="number:language">mi</xsl:attribute>
  2092.                 <xsl:attribute name="number:country">NZ</xsl:attribute>
  2093.             </xsl:when>
  2094.             <xsl:when test="$language-country-code = 1102">
  2095.                 <!-- Marathi (India), #044e -->
  2096.                 <xsl:attribute name="number:language">mr</xsl:attribute>
  2097.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2098.             </xsl:when>
  2099.             <xsl:when test="$language-country-code = 1104">
  2100.                 <!-- Mongolian (Cyrillic), #0450 -->
  2101.                 <xsl:attribute name="number:language">mn</xsl:attribute>
  2102.                 <xsl:attribute name="number:country">MN</xsl:attribute>
  2103.             </xsl:when>
  2104.             <xsl:when test="$language-country-code = 2128">
  2105.                 <!-- Mongolian (Mongolian), #0850 -->
  2106.                 <xsl:attribute name="number:language">mn</xsl:attribute>
  2107.                 <xsl:attribute name="number:country">CN</xsl:attribute>
  2108.             </xsl:when>
  2109.             <xsl:when test="$language-country-code = 1121">
  2110.                 <!-- Nepali, #0461 -->
  2111.                 <xsl:attribute name="number:language">ne</xsl:attribute>
  2112.                 <xsl:attribute name="number:country">NP</xsl:attribute>
  2113.             </xsl:when>
  2114.             <xsl:when test="$language-country-code = 2145">
  2115.                 <!-- Nepali (India), #0861 -->
  2116.                 <xsl:attribute name="number:language">ne</xsl:attribute>
  2117.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2118.             </xsl:when>
  2119.             <xsl:when test="$language-country-code = 1044">
  2120.                 <!-- Norwegian (Bokmal), #0414 -->
  2121.                 <xsl:attribute name="number:language">nb</xsl:attribute>
  2122.                 <xsl:attribute name="number:country">NO</xsl:attribute>
  2123.             </xsl:when>
  2124.             <xsl:when test="$language-country-code = 2068">
  2125.                 <!-- Norwegian (Nynorsk), #0814 -->
  2126.                 <xsl:attribute name="number:language">nn</xsl:attribute>
  2127.                 <xsl:attribute name="number:country">NO</xsl:attribute>
  2128.             </xsl:when>
  2129.             <xsl:when test="$language-country-code = 1096">
  2130.                 <!-- Oriya (India), #0448 -->
  2131.                 <xsl:attribute name="number:language">or</xsl:attribute>
  2132.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2133.             </xsl:when>
  2134.             <xsl:when test="$language-country-code = 1138">
  2135.                 <!-- Oromo (Ethiopia), #0472 -->
  2136.                 <xsl:attribute name="number:language">om</xsl:attribute>
  2137.                 <xsl:attribute name="number:country">ET</xsl:attribute>
  2138.             </xsl:when>
  2139.             <xsl:when test="$language-country-code = 1145">
  2140.                 <!-- Papiamentu (Netherlands Antilles), #0479 -->
  2141.                 <xsl:attribute name="number:language">pap</xsl:attribute>
  2142.                 <xsl:attribute name="number:country">AN</xsl:attribute>
  2143.             </xsl:when>
  2144.             <xsl:when test="$language-country-code = 1123">
  2145.                 <!-- Pashto (Afghanistan), #0463 -->
  2146.                 <xsl:attribute name="number:language">ps</xsl:attribute>
  2147.                 <xsl:attribute name="number:country">AF</xsl:attribute>
  2148.             </xsl:when>
  2149.             <xsl:when test="$language-country-code = 1045">
  2150.                 <!-- Polish, #0415 -->
  2151.                 <xsl:attribute name="number:language">pl</xsl:attribute>
  2152.                 <xsl:attribute name="number:country">PL</xsl:attribute>
  2153.             </xsl:when>
  2154.             <xsl:when test="$language-country-code = 1046">
  2155.                 <!-- Portuguese - Brazil, #0416 -->
  2156.                 <xsl:attribute name="number:language">pt</xsl:attribute>
  2157.                 <xsl:attribute name="number:country">BR</xsl:attribute>
  2158.             </xsl:when>
  2159.             <xsl:when test="$language-country-code = 2070">
  2160.                 <!-- Portuguese - Portugal, #0816 -->
  2161.                 <xsl:attribute name="number:language">pt</xsl:attribute>
  2162.                 <xsl:attribute name="number:country">PT</xsl:attribute>
  2163.             </xsl:when>
  2164.             <xsl:when test="$language-country-code = 1094">
  2165.                 <!-- Punjabi, #0446 -->
  2166.                 <xsl:attribute name="number:language">pa</xsl:attribute>
  2167.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2168.             </xsl:when>
  2169.             <xsl:when test="$language-country-code = 2118">
  2170.                 <!-- Punjabi (Pakistan), #0846 -->
  2171.                 <xsl:attribute name="number:language">pa</xsl:attribute>
  2172.                 <xsl:attribute name="number:country">PK</xsl:attribute>
  2173.             </xsl:when>
  2174.             <xsl:when test="$language-country-code = 1131">
  2175.                 <!-- Quecha - Blivia, #046b -->
  2176.                 <xsl:attribute name="number:language">qu</xsl:attribute>
  2177.                 <xsl:attribute name="number:country">BO</xsl:attribute>
  2178.             </xsl:when>
  2179.             <xsl:when test="$language-country-code = 2155">
  2180.                 <!-- Quecha - Ecuador, #086b -->
  2181.                 <xsl:attribute name="number:language">qu</xsl:attribute>
  2182.                 <xsl:attribute name="number:country">EC</xsl:attribute>
  2183.             </xsl:when>
  2184.             <xsl:when test="$language-country-code = 3179">
  2185.                 <!-- Quecha - peru, #0c6b -->
  2186.                 <xsl:attribute name="number:language">qu</xsl:attribute>
  2187.                 <xsl:attribute name="number:country">PE</xsl:attribute>
  2188.             </xsl:when>
  2189.             <xsl:when test="$language-country-code = 1047">
  2190.                 <!-- Rhaeto-Romanic (Italy), #0417 -->
  2191.                 <xsl:attribute name="number:language">rm</xsl:attribute>
  2192.                 <xsl:attribute name="number:country">IT</xsl:attribute>
  2193.             </xsl:when>
  2194.             <xsl:when test="$language-country-code = 1048">
  2195.                 <!-- Romanian, #0418 -->
  2196.                 <xsl:attribute name="number:language">ro</xsl:attribute>
  2197.                 <xsl:attribute name="number:country">RO</xsl:attribute>
  2198.             </xsl:when>
  2199.             <xsl:when test="$language-country-code = 2072">
  2200.                 <!-- Romanian - Moldova, #0818 -->
  2201.                 <xsl:attribute name="number:language">ro</xsl:attribute>
  2202.                 <xsl:attribute name="number:country">MD</xsl:attribute>
  2203.             </xsl:when>
  2204.             <xsl:when test="$language-country-code = 1049">
  2205.                 <!-- Russian, #0419 -->
  2206.                 <xsl:attribute name="number:language">ru</xsl:attribute>
  2207.                 <xsl:attribute name="number:country">RU</xsl:attribute>
  2208.             </xsl:when>
  2209.             <xsl:when test="$language-country-code = 2073">
  2210.                 <!-- Russian - Moldova, #0819 -->
  2211.                 <xsl:attribute name="number:language">ru</xsl:attribute>
  2212.                 <xsl:attribute name="number:country">MD</xsl:attribute>
  2213.             </xsl:when>
  2214.             <xsl:when test="$language-country-code = 1083">
  2215.                 <!-- Sami (Lappish), # (Northern Sami - Sweden), #043b -->
  2216.                 <xsl:attribute name="number:language">se</xsl:attribute>
  2217.                 <xsl:attribute name="number:country">SE</xsl:attribute>
  2218.             </xsl:when>
  2219.             <xsl:when test="$language-country-code = 1103">
  2220.                 <!-- Sanskrit (India), #044f -->
  2221.                 <xsl:attribute name="number:language">sa</xsl:attribute>
  2222.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2223.             </xsl:when>
  2224.             <xsl:when test="$language-country-code = 1132">
  2225.                 <!-- Sepedi (Northern Sotho - South Africa), #046c -->
  2226.                 <xsl:attribute name="number:language">nso</xsl:attribute>
  2227.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  2228.             </xsl:when>
  2229.             <xsl:when test="$language-country-code = 3098">
  2230.                 <!-- Serbian (Cyrillic - Serbia Yugoslavia), #0c1a -->
  2231.                 <xsl:attribute name="number:language">sr</xsl:attribute>
  2232.                 <xsl:attribute name="number:country">YU</xsl:attribute>
  2233.             </xsl:when>
  2234.             <xsl:when test="$language-country-code = 2074">
  2235.                 <!-- Serbian (Latin - Croatia), #081a -->
  2236.                 <xsl:attribute name="number:language">sr</xsl:attribute>
  2237.                 <xsl:attribute name="number:country">HR</xsl:attribute>
  2238.             </xsl:when>
  2239.             <xsl:when test="$language-country-code = 1113">
  2240.                 <!-- Sindhi - India,#0459 -->
  2241.                 <xsl:attribute name="number:language">sd</xsl:attribute>
  2242.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2243.             </xsl:when>
  2244.             <xsl:when test="$language-country-code = 2137">
  2245.                 <!-- Sindhi - Pakistan, #0859 -->
  2246.                 <xsl:attribute name="number:language">sd</xsl:attribute>
  2247.                 <xsl:attribute name="number:country">PK</xsl:attribute>
  2248.             </xsl:when>
  2249.             <xsl:when test="$language-country-code = 1115">
  2250.                 <!-- Sinhalese - Sri Lanka, #045b -->
  2251.                 <xsl:attribute name="number:language">si</xsl:attribute>
  2252.                 <xsl:attribute name="number:country">LK</xsl:attribute>
  2253.             </xsl:when>
  2254.             <xsl:when test="$language-country-code = 1051">
  2255.                 <!-- Slovak, #041b -->
  2256.                 <xsl:attribute name="number:language">sk</xsl:attribute>
  2257.                 <xsl:attribute name="number:country">SK</xsl:attribute>
  2258.             </xsl:when>
  2259.             <xsl:when test="$language-country-code = 1060">
  2260.                 <!-- Slovenian, #0424 -->
  2261.                 <xsl:attribute name="number:language">sl</xsl:attribute>
  2262.                 <xsl:attribute name="number:country">SI</xsl:attribute>
  2263.             </xsl:when>
  2264.             <xsl:when test="$language-country-code = 1143">
  2265.                 <!-- Somali, #0477 -->
  2266.                 <xsl:attribute name="number:language">so</xsl:attribute>
  2267.                 <xsl:attribute name="number:country">SO</xsl:attribute>
  2268.             </xsl:when>
  2269.             <xsl:when test="$language-country-code = 1070">
  2270.                 <!-- Sorbian, #042e -->
  2271.                 <xsl:attribute name="number:language">wen</xsl:attribute>
  2272.                 <xsl:attribute name="number:country">DE</xsl:attribute>
  2273.             </xsl:when>
  2274.             <xsl:when test="$language-country-code = 3082">
  2275.                 <!-- Spanish - Spain (Modern/International Sort), #0c0a -->
  2276.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2277.                 <xsl:attribute name="number:country">ES</xsl:attribute>
  2278.             </xsl:when>
  2279.             <xsl:when test="$language-country-code = 1034">
  2280.                 <!-- Spanish - Spain (Traditional Sort), #040a -->
  2281.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2282.                 <xsl:attribute name="number:country">ES</xsl:attribute>
  2283.             </xsl:when>
  2284.             <xsl:when test="$language-country-code = 11274">
  2285.                 <!-- Spanish - Argentina, #2c0a -->
  2286.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2287.                 <xsl:attribute name="number:country">AR</xsl:attribute>
  2288.             </xsl:when>
  2289.             <xsl:when test="$language-country-code = 16394">
  2290.                 <!-- Spanish - Bolivia, #400a -->
  2291.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2292.                 <xsl:attribute name="number:country">BO</xsl:attribute>
  2293.             </xsl:when>
  2294.             <xsl:when test="$language-country-code = 13322">
  2295.                 <!-- Spanish - Chile, #340a -->
  2296.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2297.                 <xsl:attribute name="number:country">CL</xsl:attribute>
  2298.             </xsl:when>
  2299.             <xsl:when test="$language-country-code = 9226">
  2300.                 <!-- Spanish - Colombia, #240a -->
  2301.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2302.                 <xsl:attribute name="number:country">CO</xsl:attribute>
  2303.             </xsl:when>
  2304.             <xsl:when test="$language-country-code = 5130">
  2305.                 <!-- Spanish - Costa Rica, #140a -->
  2306.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2307.                 <xsl:attribute name="number:country">CR</xsl:attribute>
  2308.             </xsl:when>
  2309.             <xsl:when test="$language-country-code = 7178">
  2310.                 <!-- Spanish - Dominican Republic, #1c0a -->
  2311.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2312.                 <xsl:attribute name="number:country">DO</xsl:attribute>
  2313.             </xsl:when>
  2314.             <xsl:when test="$language-country-code = 12298">
  2315.                 <!-- Spanish - Ecuador, #300a -->
  2316.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2317.                 <xsl:attribute name="number:country">EC</xsl:attribute>
  2318.             </xsl:when>
  2319.             <xsl:when test="$language-country-code = 17418">
  2320.                 <!-- Spanish - EL Salvador, #440a -->
  2321.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2322.                 <xsl:attribute name="number:country">SV</xsl:attribute>
  2323.             </xsl:when>
  2324.             <xsl:when test="$language-country-code = 4106">
  2325.                 <!-- Spanish - Guatemala, #100a -->
  2326.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2327.                 <xsl:attribute name="number:country">GT</xsl:attribute>
  2328.             </xsl:when>
  2329.             <xsl:when test="$language-country-code = 18442">
  2330.                 <!-- Spanish - Honduras, #480a -->
  2331.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2332.                 <xsl:attribute name="number:country">HN</xsl:attribute>
  2333.             </xsl:when>
  2334.             <xsl:when test="$language-country-code = 58378">
  2335.                 <!-- Spanish - Latin America (Argentina), #e40a -->
  2336.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2337.                 <xsl:attribute name="number:country">AR</xsl:attribute>
  2338.             </xsl:when>
  2339.             <xsl:when test="$language-country-code = 2058">
  2340.                 <!-- Spanish - Mexico, #080a -->
  2341.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2342.                 <xsl:attribute name="number:country">MX</xsl:attribute>
  2343.             </xsl:when>
  2344.             <xsl:when test="$language-country-code = 19466">
  2345.                 <!-- Spanish - Nicaragua, #4c0a -->
  2346.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2347.                 <xsl:attribute name="number:country">NI</xsl:attribute>
  2348.             </xsl:when>
  2349.             <xsl:when test="$language-country-code = 6154">
  2350.                 <!-- Spanish - Panama, #180a -->
  2351.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2352.                 <xsl:attribute name="number:country">PA</xsl:attribute>
  2353.             </xsl:when>
  2354.             <xsl:when test="$language-country-code = 15370">
  2355.                 <!-- Spanish - Paraguay, #3c0a -->
  2356.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2357.                 <xsl:attribute name="number:country">PY</xsl:attribute>
  2358.             </xsl:when>
  2359.             <xsl:when test="$language-country-code = 10250">
  2360.                 <!-- Spanish - Peru, #280a -->
  2361.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2362.                 <xsl:attribute name="number:country">PE</xsl:attribute>
  2363.             </xsl:when>
  2364.             <xsl:when test="$language-country-code = 20490">
  2365.                 <!-- Spanish - Puerto Rico, #500a -->
  2366.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2367.                 <xsl:attribute name="number:country">PR</xsl:attribute>
  2368.             </xsl:when>
  2369.             <xsl:when test="$language-country-code = 21514">
  2370.                 <!-- Spanish - US, #540a -->
  2371.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2372.                 <xsl:attribute name="number:country">US</xsl:attribute>
  2373.             </xsl:when>
  2374.             <xsl:when test="$language-country-code = 14346">
  2375.                 <!-- Spanish - Uruguay, #380a -->
  2376.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2377.                 <xsl:attribute name="number:country">UY</xsl:attribute>
  2378.             </xsl:when>
  2379.             <xsl:when test="$language-country-code = 8202">
  2380.                 <!-- Spanish - Venezuela, #200a -->
  2381.                 <xsl:attribute name="number:language">es</xsl:attribute>
  2382.                 <xsl:attribute name="number:country">VE</xsl:attribute>
  2383.             </xsl:when>
  2384.             <xsl:when test="$language-country-code = 1072">
  2385.                 <!-- Sutu (Ngoni - Tanzania), #0430 -->
  2386.                 <xsl:attribute name="number:language">bnt</xsl:attribute>
  2387.                 <xsl:attribute name="number:country">TZ</xsl:attribute>
  2388.             </xsl:when>
  2389.             <xsl:when test="$language-country-code = 1089">
  2390.                 <!-- Swahili (Tanzania), #0441 -->
  2391.                 <xsl:attribute name="number:language">sw</xsl:attribute>
  2392.                 <xsl:attribute name="number:country">TZ</xsl:attribute>
  2393.             </xsl:when>
  2394.             <xsl:when test="$language-country-code = 1053">
  2395.                 <!-- Swedish (Sweden), #041d -->
  2396.                 <xsl:attribute name="number:language">sv</xsl:attribute>
  2397.                 <xsl:attribute name="number:country">SE</xsl:attribute>
  2398.             </xsl:when>
  2399.             <xsl:when test="$language-country-code = 2077">
  2400.                 <!-- Swedish - Finland, #081d -->
  2401.                 <xsl:attribute name="number:language">sv</xsl:attribute>
  2402.                 <xsl:attribute name="number:country">FI</xsl:attribute>
  2403.             </xsl:when>
  2404.             <xsl:when test="$language-country-code = 1114">
  2405.                 <!-- Syriac (Syria), #045a -->
  2406.                 <xsl:attribute name="number:language">syr</xsl:attribute>
  2407.                 <xsl:attribute name="number:country">SY</xsl:attribute>
  2408.             </xsl:when>
  2409.             <xsl:when test="$language-country-code = 1064">
  2410.                 <!-- Tajik, #0428 -->
  2411.                 <xsl:attribute name="number:language">tg</xsl:attribute>
  2412.                 <xsl:attribute name="number:country">TJ</xsl:attribute>
  2413.             </xsl:when>
  2414.             <xsl:when test="$language-country-code = 1119">
  2415.                 <!-- Tamazight (Arabic), #045f -->
  2416.                 <xsl:attribute name="number:language">ber</xsl:attribute>
  2417.                 <xsl:attribute name="number:country">ML</xsl:attribute>
  2418.             </xsl:when>
  2419.             <xsl:when test="$language-country-code = 2143">
  2420.                 <!-- Tamazight (Latin), #085f -->
  2421.                 <xsl:attribute name="number:language">ber</xsl:attribute>
  2422.                 <xsl:attribute name="number:country">MA</xsl:attribute>
  2423.             </xsl:when>
  2424.             <xsl:when test="$language-country-code = 1097">
  2425.                 <!-- Tamil (India), #0449 -->
  2426.                 <xsl:attribute name="number:language">ta</xsl:attribute>
  2427.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2428.             </xsl:when>
  2429.             <xsl:when test="$language-country-code = 1092">
  2430.                 <!-- Tatar (Russia), #0444 -->
  2431.                 <xsl:attribute name="number:language">tt</xsl:attribute>
  2432.                 <xsl:attribute name="number:country">RU</xsl:attribute>
  2433.             </xsl:when>
  2434.             <xsl:when test="$language-country-code = 1098">
  2435.                 <!-- Telugu (India), #044a -->
  2436.                 <xsl:attribute name="number:language">te</xsl:attribute>
  2437.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2438.             </xsl:when>
  2439.             <xsl:when test="$language-country-code = 1054">
  2440.                 <!-- Thai, #041e -->
  2441.                 <xsl:attribute name="number:language">th</xsl:attribute>
  2442.                 <xsl:attribute name="number:country">TH</xsl:attribute>
  2443.             </xsl:when>
  2444.             <xsl:when test="$language-country-code = 2129">
  2445.                 <!-- Tibetan - Bhutan, #0851 -->
  2446.                 <xsl:attribute name="number:language">bo</xsl:attribute>
  2447.                 <xsl:attribute name="number:country">BT</xsl:attribute>
  2448.             </xsl:when>
  2449.             <xsl:when test="$language-country-code = 1105">
  2450.                 <!-- Tibetan - Peoples' Republic of China, #0451 -->
  2451.                 <xsl:attribute name="number:language">bo</xsl:attribute>
  2452.                 <xsl:attribute name="number:country">CN</xsl:attribute>
  2453.             </xsl:when>
  2454.             <xsl:when test="$language-country-code = 2163">
  2455.                 <!-- Tigrigna (Tigrinya) - Eritrea, #0873 -->
  2456.                 <xsl:attribute name="number:language">ti</xsl:attribute>
  2457.                 <xsl:attribute name="number:country">ER</xsl:attribute>
  2458.             </xsl:when>
  2459.             <xsl:when test="$language-country-code = 1139">
  2460.                 <!-- Tigrigna (Tigrinya) - Ethiopia, #0473 -->
  2461.                 <xsl:attribute name="number:language">ti</xsl:attribute>
  2462.                 <xsl:attribute name="number:country">ET</xsl:attribute>
  2463.             </xsl:when>
  2464.             <xsl:when test="$language-country-code = 1073">
  2465.                 <!-- Tsonga (South Africa), #0431 -->
  2466.                 <xsl:attribute name="number:language">ts</xsl:attribute>
  2467.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  2468.             </xsl:when>
  2469.             <xsl:when test="$language-country-code = 1074">
  2470.                 <!-- Tswana (South Africa), #0432 -->
  2471.                 <xsl:attribute name="number:language">tn</xsl:attribute>
  2472.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  2473.             </xsl:when>
  2474.             <xsl:when test="$language-country-code = 1055">
  2475.                 <!-- Turkish, #041f -->
  2476.                 <xsl:attribute name="number:language">tr</xsl:attribute>
  2477.                 <xsl:attribute name="number:country">TR</xsl:attribute>
  2478.             </xsl:when>
  2479.             <xsl:when test="$language-country-code = 1090">
  2480.                 <!-- Turkmen, #0442 -->
  2481.                 <xsl:attribute name="number:language">tk</xsl:attribute>
  2482.                 <xsl:attribute name="number:country">TM</xsl:attribute>
  2483.             </xsl:when>
  2484.             <xsl:when test="$language-country-code = 1152">
  2485.                 <!-- Uighur - China, #0480 -->
  2486.                 <xsl:attribute name="number:language">ug</xsl:attribute>
  2487.                 <xsl:attribute name="number:country">CN</xsl:attribute>
  2488.             </xsl:when>
  2489.             <xsl:when test="$language-country-code = 1058">
  2490.                 <!-- Ukrainian, #0422 -->
  2491.                 <xsl:attribute name="number:language">uk</xsl:attribute>
  2492.                 <xsl:attribute name="number:country">UA</xsl:attribute>
  2493.             </xsl:when>
  2494.             <xsl:when test="$language-country-code = 1056">
  2495.                 <!-- Urdu (Pakistan), #0420 -->
  2496.                 <xsl:attribute name="number:language">ur</xsl:attribute>
  2497.                 <xsl:attribute name="number:country">PK</xsl:attribute>
  2498.             </xsl:when>
  2499.             <xsl:when test="$language-country-code = 2080">
  2500.                 <!-- Urdu - India, #0820 -->
  2501.                 <xsl:attribute name="number:language">ur</xsl:attribute>
  2502.                 <xsl:attribute name="number:country">IN</xsl:attribute>
  2503.             </xsl:when>
  2504.             <xsl:when test="$language-country-code = 2115">
  2505.                 <!-- Uzbek (Cyrillic), #0843 -->
  2506.                 <xsl:attribute name="number:language">uz</xsl:attribute>
  2507.                 <xsl:attribute name="number:country">UZ</xsl:attribute>
  2508.             </xsl:when>
  2509.             <xsl:when test="$language-country-code = 1091">
  2510.                 <!-- Uzbek (Latin), #0443 -->
  2511.                 <xsl:attribute name="number:language">uz</xsl:attribute>
  2512.                 <xsl:attribute name="number:country">UZ</xsl:attribute>
  2513.             </xsl:when>
  2514.             <xsl:when test="$language-country-code = 1075">
  2515.                 <!-- Venda (South Africa), #0433 -->
  2516.                 <xsl:attribute name="number:language">ve</xsl:attribute>
  2517.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  2518.             </xsl:when>
  2519.             <xsl:when test="$language-country-code = 1066">
  2520.                 <!-- Vietnamese, #042a -->
  2521.                 <xsl:attribute name="number:language">vi</xsl:attribute>
  2522.                 <xsl:attribute name="number:country">VN</xsl:attribute>
  2523.             </xsl:when>
  2524.             <xsl:when test="$language-country-code = 1106">
  2525.                 <!-- Welsh (UK), #0452 -->
  2526.                 <xsl:attribute name="number:language">cy</xsl:attribute>
  2527.                 <xsl:attribute name="number:country">UK</xsl:attribute>
  2528.             </xsl:when>
  2529.             <xsl:when test="$language-country-code = 1076">
  2530.                 <!-- Xhosa (South Africa), #0434 -->
  2531.                 <xsl:attribute name="number:language">xh</xsl:attribute>
  2532.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  2533.             </xsl:when>
  2534.             <xsl:when test="$language-country-code = 1144">
  2535.                 <!-- Yi (Sino-Tibetan - China), #0478 -->
  2536.                 <xsl:attribute name="number:language">sit</xsl:attribute>
  2537.                 <xsl:attribute name="number:country">CN</xsl:attribute>
  2538.             </xsl:when>
  2539.             <xsl:when test="$language-country-code = 1085">
  2540.                 <!-- Yiddish (Jews - Israel), #043d -->
  2541.                 <xsl:attribute name="number:language">yi</xsl:attribute>
  2542.                 <xsl:attribute name="number:country">IL</xsl:attribute>
  2543.             </xsl:when>
  2544.             <xsl:when test="$language-country-code = 1130">
  2545.                 <!-- Yoruba (Nigeria), #046a -->
  2546.                 <xsl:attribute name="number:language">yo</xsl:attribute>
  2547.                 <xsl:attribute name="number:country">NG</xsl:attribute>
  2548.             </xsl:when>
  2549.             <xsl:when test="$language-country-code = 1077">
  2550.                 <!-- Zulu (South Africa), #0435 -->
  2551.                 <xsl:attribute name="number:language">zu</xsl:attribute>
  2552.                 <xsl:attribute name="number:country">ZA</xsl:attribute>
  2553.             </xsl:when>
  2554.         </xsl:choose>
  2555.     </xsl:template>
  2556.     <xsl:template name="get-number-format-condition">
  2557.         <xsl:param name="number-format-unit"/>
  2558.         <xsl:choose>
  2559.             <xsl:when test="contains($number-format-unit, '[>')">
  2560.                 <xsl:value-of select="concat('>', substring-before( substring-after($number-format-unit,'[>'), ']'))"/>
  2561.             </xsl:when>
  2562.             <xsl:when test="contains($number-format-unit, '[<')">
  2563.                 <xsl:value-of select="concat('<', substring-before( substring-after($number-format-unit,'[<'), ']'))"/>
  2564.             </xsl:when>
  2565.             <xsl:when test="contains($number-format-unit, '[=')">
  2566.                 <xsl:value-of select="concat('=', substring-before( substring-after($number-format-unit,'[='), ']'))"/>
  2567.             </xsl:when>
  2568.             <xsl:otherwise/>
  2569.         </xsl:choose>
  2570.     </xsl:template>
  2571.     <xsl:template name="add-number-text-value">
  2572.         <xsl:param name="style-type-name"/>
  2573.         <xsl:param name="number-format-unit"/>
  2574.         <xsl:param name="unit-pos"/>
  2575.         <xsl:param name="condition-pos"/>
  2576.         <xsl:param name="isNumberTextElementOpened" select="false()"/>
  2577.         <xsl:param name="numberTextValue"/>
  2578.         <xsl:param name="posed-number-format-unit"/>
  2579.         <xsl:param name="finished" select="false()"/>
  2580.         <xsl:choose>
  2581.             <xsl:when test="not($finished)">
  2582.                 <xsl:choose>
  2583. <!-- <xsl:when test="$style-type-name='number:text-style' or $style-type-name='number:date-style'"> -->
  2584.                     <xsl:when test="$style-type-name='number:text-style'">
  2585.                         <xsl:choose>
  2586.                             <xsl:when test="$isNumberTextElementOpened">
  2587.                                 <number:text-content/>
  2588.                                 <number:text>
  2589.                                     <xsl:copy-of select="$numberTextValue"/>
  2590.                                 </number:text>
  2591.                                 <xsl:call-template name="get-number-text-content">
  2592.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2593.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2594.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2595.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2596.                                     <xsl:with-param name="isNumberTextElementOpened" select="true()"/>
  2597.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2598.                                 </xsl:call-template>
  2599.                             </xsl:when>
  2600.                             <xsl:otherwise>
  2601.                                 <number:text>
  2602.                                     <xsl:copy-of select="$numberTextValue"/>
  2603.                                 </number:text>
  2604.                                 <xsl:call-template name="get-number-text-content">
  2605.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2606.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2607.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2608.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2609.                                     <xsl:with-param name="isNumberTextElementOpened" select="true()"/>
  2610.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2611.                                 </xsl:call-template>
  2612.                                 <xsl:call-template name="get-number-text-content">
  2613.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2614.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2615.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2616.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2617.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2618.                                     <xsl:with-param name="finished" select="true()"/>
  2619.                                 </xsl:call-template>
  2620.                             </xsl:otherwise>
  2621.                         </xsl:choose>
  2622.                     </xsl:when>
  2623.                     <xsl:when test="$style-type-name='number:number-style'">
  2624.                         <xsl:choose>
  2625.                             <xsl:when test="$isNumberTextElementOpened">
  2626.                                 <xsl:copy-of select="$numberTextValue"/>
  2627.                                 <xsl:call-template name="get-number-text-content">
  2628.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2629.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2630.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2631.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2632.                                     <xsl:with-param name="isNumberTextElementOpened" select="true()"/>
  2633.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2634.                                 </xsl:call-template>
  2635.                             </xsl:when>
  2636.                             <xsl:otherwise>
  2637.                                 <number:text>
  2638.                                     <xsl:copy-of select="$numberTextValue"/>
  2639.                                     <xsl:call-template name="get-number-text-content">
  2640.                                         <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2641.                                         <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2642.                                         <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2643.                                         <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2644.                                         <xsl:with-param name="isNumberTextElementOpened" select="true()"/>
  2645.                                         <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2646.                                     </xsl:call-template>
  2647.                                 </number:text>
  2648.                                 <xsl:call-template name="get-number-text-content">
  2649.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2650.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2651.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2652.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2653.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2654.                                     <xsl:with-param name="finished" select="true()"/>
  2655.                                 </xsl:call-template>
  2656.                             </xsl:otherwise>
  2657.                         </xsl:choose>
  2658.                     </xsl:when>
  2659.                     <xsl:otherwise>
  2660.                         <number:text>
  2661.                             <xsl:copy-of select="$numberTextValue"/>
  2662.                         </number:text>
  2663.                         <xsl:choose>
  2664.                             <xsl:when test="starts-with($posed-number-format-unit, '\')">
  2665.                                 <xsl:call-template name="get-number-text-content">
  2666.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2667.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2668.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2669.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2670.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2671.                                     <xsl:with-param name="finished" select="false()" />
  2672.                                 </xsl:call-template>
  2673.                             </xsl:when>
  2674.                             <xsl:otherwise>
  2675.                                 <xsl:call-template name="get-number-text-content">
  2676.                                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2677.                                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2678.                                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2679.                                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2680.                                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2681.                                     <xsl:with-param name="finished" select="true()" />
  2682.                                 </xsl:call-template>
  2683.                             </xsl:otherwise>
  2684.                         </xsl:choose>
  2685.                     </xsl:otherwise>
  2686.                 </xsl:choose>
  2687.             </xsl:when>
  2688.             <xsl:otherwise>
  2689.                 <xsl:call-template name="get-number-text-content">
  2690.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2691.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2692.                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2693.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2694.                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2695.                 </xsl:call-template>
  2696.             </xsl:otherwise>
  2697.         </xsl:choose>
  2698.     </xsl:template>
  2699.     <xsl:template name="get-number-text-content">
  2700.         <xsl:param name="style-type-name"/>
  2701.         <xsl:param name="number-format-unit"/>
  2702.         <xsl:param name="unit-pos"/>
  2703.         <xsl:param name="condition-pos"/>
  2704.         <xsl:param name="isNumberTextElementOpened" select="false()"/>
  2705.         <xsl:param name="finished" select="false()"/>
  2706.         <xsl:param name="posed-number-format-unit"/>
  2707.         <!-- process number-format-unit by character string parser -->
  2708.         <xsl:choose>
  2709.             <xsl:when test="starts-with( $posed-number-format-unit, '\') or starts-with( $posed-number-format-unit, '*')">
  2710.                 <xsl:choose>
  2711.                     <xsl:when test="not($finished)">
  2712.                         <xsl:call-template name="add-number-text-value">
  2713.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2714.                             <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2715.                             <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  2716.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2717.                             <xsl:with-param name="isNumberTextElementOpened" select="$isNumberTextElementOpened"/>
  2718.                             <xsl:with-param name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos + 2)"/>
  2719.                             <!-- place '*' temparily here, because now StarCalc doesn't support variable filling character definition -->
  2720.                             <xsl:with-param name="numberTextValue" select="substring($posed-number-format-unit,2,1)"/>
  2721.                             <xsl:with-param name="finished" select="$finished"/>
  2722.                         </xsl:call-template>
  2723.                     </xsl:when>
  2724.                     <xsl:otherwise>
  2725.                         <xsl:call-template name="get-number-text-content">
  2726.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2727.                             <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2728.                             <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  2729.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2730.                             <xsl:with-param name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos +2)"/>
  2731.                             <xsl:with-param name="finished" select="true()"/>
  2732.                         </xsl:call-template>
  2733.                     </xsl:otherwise>
  2734.                 </xsl:choose>
  2735.             </xsl:when>
  2736.             <xsl:when test="starts-with( $posed-number-format-unit, '_')">
  2737.                 <xsl:choose>
  2738.                     <xsl:when test="not($finished)">
  2739.                         <xsl:call-template name="add-number-text-value">
  2740.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2741.                             <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2742.                             <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  2743.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2744.                             <xsl:with-param name="isNumberTextElementOpened" select="$isNumberTextElementOpened"/>
  2745.                             <xsl:with-param name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos + 2)"/>
  2746.                             <!-- adding an empty string -->
  2747.                             <xsl:with-param name="numberTextValue" select="' '"/>
  2748.                             <xsl:with-param name="finished" select="$finished"/>
  2749.                         </xsl:call-template>
  2750.                     </xsl:when>
  2751.                     <xsl:otherwise>
  2752.                         <xsl:call-template name="get-number-text-content">
  2753.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2754.                             <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2755.                             <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  2756.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2757.                             <xsl:with-param name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos + 2)"/>
  2758.                             <xsl:with-param name="finished" select="true()"/>
  2759.                         </xsl:call-template>
  2760.                     </xsl:otherwise>
  2761.                 </xsl:choose>
  2762.             </xsl:when>
  2763.             <xsl:when test="starts-with( $posed-number-format-unit, '"')">
  2764.                 <xsl:choose>
  2765.                     <xsl:when test="not($finished)">
  2766.                         <!-- creating a pre-character string  -->
  2767.                         <xsl:variable name="pre-character-string" select="substring-before(substring($posed-number-format-unit,2), '"')"/>
  2768.                         <xsl:call-template name="add-number-text-value">
  2769.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2770.                             <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2771.                             <xsl:with-param name="unit-pos" select="$unit-pos + string-length($pre-character-string) + 2"/>
  2772.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2773.                             <xsl:with-param name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos + string-length($pre-character-string) + 2)"/>
  2774.                             <xsl:with-param name="isNumberTextElementOpened" select="$isNumberTextElementOpened"/>
  2775.                             <xsl:with-param name="numberTextValue" select="$pre-character-string"/>
  2776.                             <xsl:with-param name="finished" select="$finished"/>
  2777.                         </xsl:call-template>
  2778.                     </xsl:when>
  2779.                     <xsl:otherwise>
  2780.                         <!-- creating a pre-character string  -->
  2781.                         <xsl:variable name="pre-character-string" select="substring-before(substring($posed-number-format-unit,2), '"')"/>
  2782.                         <xsl:call-template name="get-number-text-content">
  2783.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2784.                             <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2785.                             <xsl:with-param name="unit-pos" select="$unit-pos + string-length($pre-character-string) + 2"/>
  2786.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2787.                             <xsl:with-param name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos + string-length($pre-character-string) + 2)"/>
  2788.                             <xsl:with-param name="finished" select="true()"/>
  2789.                         </xsl:call-template>
  2790.                     </xsl:otherwise>
  2791.                 </xsl:choose>
  2792.             </xsl:when>
  2793.             <xsl:otherwise>
  2794.                 <xsl:if test="$finished">
  2795.                     <xsl:call-template name="create-number-format-content">
  2796.                         <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2797.                         <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2798.                         <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2799.                         <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2800.                     </xsl:call-template>
  2801.                 </xsl:if>
  2802.             </xsl:otherwise>
  2803.         </xsl:choose>
  2804.     </xsl:template>
  2805.     <xsl:template name="create-number-format-content">
  2806.         <xsl:param name="style-type-name"/>
  2807.         <xsl:param name="number-format-unit"/>
  2808.         <xsl:param name="unit-pos"/>
  2809.         <xsl:param name="condition-pos"/>
  2810.         <xsl:param name="isNumberTextElementOpened" select="false()"/>
  2811.         <xsl:variable name="posed-number-format-unit" select="substring($number-format-unit,$unit-pos)"/>
  2812.         <xsl:variable name="calendar-type-name">
  2813.             <xsl:if test="contains( $number-format-unit, '[$')">
  2814.                 <xsl:variable name="format-code" select="substring-before( substring-after( substring-after( $number-format-unit, '[$'), '-'), ']')"/>
  2815.                 <xsl:if test="string-length( $format-code) > 4">
  2816.                     <xsl:call-template name="get-calendar-type-name">
  2817.                         <xsl:with-param name="calendar-type" select="substring( $format-code, string-length($format-code) -5, 2)"/>
  2818.                     </xsl:call-template>
  2819.                 </xsl:if>
  2820.             </xsl:if>
  2821.         </xsl:variable>
  2822.         <!-- process number-format-unit by character string parser -->
  2823.         <xsl:choose>
  2824.             <xsl:when test="starts-with( $posed-number-format-unit, '[$') and (not(starts-with($posed-number-format-unit, '[$-') ) )">
  2825.                 <xsl:element name="number:currency-symbol">
  2826.                     <xsl:call-template name="create-language-country-attribute">
  2827.                         <xsl:with-param name="attribute-code" select="substring-before(substring-after(substring-after($posed-number-format-unit,'[$'),'-'),']')"/>
  2828.                     </xsl:call-template>
  2829.                     <xsl:value-of select="substring-before( substring-after( $posed-number-format-unit, '[$'), '-')"/>
  2830.                 </xsl:element>
  2831.                 <xsl:call-template name="create-number-format-content">
  2832.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2833.                     <xsl:with-param name="unit-pos" select="$unit-pos + string-length( substring-before( $posed-number-format-unit, ']') ) + 1"/>
  2834.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2835.                 </xsl:call-template>
  2836.             </xsl:when>
  2837.             <xsl:when test="starts-with( $posed-number-format-unit, '\') or starts-with( $posed-number-format-unit, '*') or starts-with( $posed-number-format-unit, '_') or starts-with( $posed-number-format-unit, '"')">
  2838.                 <xsl:call-template name="get-number-text-content">
  2839.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  2840.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  2841.                     <xsl:with-param name="unit-pos" select="$unit-pos"/>
  2842.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  2843.                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  2844.                 </xsl:call-template>
  2845.             </xsl:when>
  2846.             <xsl:when test="(starts-with( $posed-number-format-unit, '0') or starts-with( $posed-number-format-unit, '#') or starts-with( $posed-number-format-unit, '?') ) and (not ( contains( $posed-number-format-unit, 's.00') ) )">
  2847.                 <xsl:variable name="valid-number-format-string">
  2848.                     <xsl:call-template name="get-valid-number-format-string">
  2849.                         <xsl:with-param name="number-format-unit" select="$posed-number-format-unit"/>
  2850.                     </xsl:call-template>
  2851.                 </xsl:variable>
  2852.                 <xsl:choose>
  2853.                     <xsl:when test="contains( $valid-number-format-string, '/')">
  2854.                         <xsl:element name="number:fraction">
  2855.                             <xsl:attribute name="number:min-integer-digits">
  2856.                                 <xsl:value-of select="string-length( substring-before($valid-number-format-string, '/') ) - string-length(translate( substring-before($valid-number-format-string, '/'), '0', '') )"/>
  2857.                             </xsl:attribute>
  2858.                             <xsl:if test="contains( $valid-number-format-string, ',')">
  2859.                                 <xsl:attribute name="number:grouping">true</xsl:attribute>
  2860.                             </xsl:if>
  2861.                             <xsl:attribute name="number:min-numerator-digits">
  2862.                                 <xsl:value-of select="string-length( substring-before($valid-number-format-string, '/') ) - string-length(translate( substring-before($valid-number-format-string,'/'), '?', '') )"/>
  2863.                             </xsl:attribute>
  2864.                             <xsl:attribute name="number:min-denominator-digits">
  2865.                                 <xsl:value-of select="string-length(substring-after($valid-number-format-string, '/') )"/>
  2866.                             </xsl:attribute>
  2867.                             <!-- deal with number:embedded-text (removed, as SCHEMA demands element to be empty)
  2868.                             <xsl:call-template name="create-number-format-embedded-text">
  2869.                                 <xsl:with-param name="adapted-number-format-unit" select="$posed-number-format-unit"/>
  2870.                                 <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  2871.                             </xsl:call-template>
  2872.                              -->
  2873.                         </xsl:element>
  2874.                     </xsl:when>
  2875.                     <xsl:when test="contains( $valid-number-format-string, '%')">
  2876.                         <xsl:element name="number:number">
  2877.                             <xsl:choose>
  2878.                                 <xsl:when test="contains( $valid-number-format-string, '.')">
  2879.                                     <xsl:attribute name="number:decimal-places">
  2880.                                         <xsl:value-of select="string-length( substring-before( substring-after( $valid-number-format-string, '.'), '%') ) - string-length( translate( substring-before( substring-after( $valid-number-format-string, '.'), '%'), '0', '') )"/>
  2881.                                     </xsl:attribute>
  2882.                                     <xsl:attribute name="number:min-integer-digits">
  2883.                                         <xsl:value-of select="string-length( substring-before($valid-number-format-string, '.') ) - string-length(translate( substring-before($valid-number-format-string, '.'), '0', '') )"/>
  2884.                                     </xsl:attribute>
  2885.                                 </xsl:when>
  2886.                                 <xsl:otherwise>
  2887.                                     <xsl:attribute name="number:decimal-places">0</xsl:attribute>
  2888.                                     <xsl:attribute name="number:min-integer-digits">
  2889.                                         <xsl:value-of select="string-length( substring-before($valid-number-format-string, '%') ) - string-length(translate( substring-before($valid-number-format-string, '%'), '0', '') )"/>
  2890.                                     </xsl:attribute>
  2891.                                 </xsl:otherwise>
  2892.                             </xsl:choose>
  2893.                             <xsl:choose>
  2894.                                 <xsl:when test="contains( $valid-number-format-string, ',') and (substring( $valid-number-format-string,string-length($valid-number-format-string)) = ',')">
  2895.                                     <xsl:variable name="display-factor">
  2896.                                         <xsl:call-template name="get-display-factor">
  2897.                                             <xsl:with-param name="start-number" select="1"/>
  2898.                                             <xsl:with-param name="thousand-count" select="string-length($valid-number-format-string) - string-length( translate($valid-number-format-string, ',', '') )"/>
  2899.                                         </xsl:call-template>
  2900.                                     </xsl:variable>
  2901.                                     <xsl:attribute name="number:display-factor">
  2902.                                         <xsl:value-of select="$display-factor"/>
  2903.                                     </xsl:attribute>
  2904.                                     <xsl:attribute name="number:grouping">true</xsl:attribute>
  2905.                                 </xsl:when>
  2906.                                 <xsl:when test="contains( $valid-number-format-string, ',')">
  2907.                                     <xsl:attribute name="number:grouping">true</xsl:attribute>
  2908.                                 </xsl:when>
  2909.                             </xsl:choose>
  2910.                             <!-- deal with number:embedded-text -->
  2911.                             <xsl:call-template name="create-number-format-embedded-text">
  2912.                                 <xsl:with-param name="adapted-number-format-unit" select="$posed-number-format-unit"/>
  2913.                                 <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  2914.                             </xsl:call-template>
  2915.                         </xsl:element>
  2916.                         <number:text>%</number:text>
  2917.                     </xsl:when>
  2918.                     <xsl:when test="contains( $valid-number-format-string, 'E') or contains ($valid-number-format-string, 'e')">
  2919.                         <xsl:element name="number:scientific-number">
  2920.                             <xsl:choose>
  2921.                                 <xsl:when test="contains( $valid-number-format-string, '.')">
  2922.                                     <xsl:attribute name="number:decimal-places">
  2923.                                         <xsl:value-of select="string-length( substring-before( substring-after( $valid-number-format-string, '.'), 'E') ) - string-length( translate( substring-before( substring-after( $valid-number-format-string, '.'), 'E'), '0', '') )"/>
  2924.                                     </xsl:attribute>
  2925.                                     <xsl:attribute name="number:min-integer-digits">
  2926.                                         <xsl:value-of select="string-length( substring-before($valid-number-format-string, '.') ) - string-length(translate( substring-before($valid-number-format-string, '.'), '0', '') )"/>
  2927.                                     </xsl:attribute>
  2928.                                 </xsl:when>
  2929.                                 <xsl:otherwise>
  2930.                                     <xsl:attribute name="number:decimal-places">0</xsl:attribute>
  2931.                                     <xsl:attribute name="number:min-integer-digits">
  2932.                                         <xsl:value-of select="string-length( substring-before($valid-number-format-string, 'E') ) - string-length(translate( substring-before($valid-number-format-string, 'E'), '0', '') )"/>
  2933.                                     </xsl:attribute>
  2934.                                 </xsl:otherwise>
  2935.                             </xsl:choose>
  2936.                             <xsl:attribute name="number:min-exponent-digits">
  2937.                                 <xsl:value-of select="string-length( substring-after( $valid-number-format-string, 'E') ) - string-length( translate( substring-after( $valid-number-format-string, 'E'), '0', '') )"/>
  2938.                             </xsl:attribute>
  2939.                             <!-- deal with number:embedded-text -->
  2940.                             <xsl:call-template name="create-number-format-embedded-text">
  2941.                                 <xsl:with-param name="adapted-number-format-unit" select="$posed-number-format-unit"/>
  2942.                                 <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  2943.                             </xsl:call-template>
  2944.                         </xsl:element>
  2945.                     </xsl:when>
  2946.                     <xsl:otherwise>
  2947.                         <!-- -normal number format, currency, and accounting, e.g -->
  2948.                         <xsl:element name="number:number">
  2949.                             <xsl:choose>
  2950.                                 <xsl:when test="contains( $valid-number-format-string, '.')">
  2951.                                     <xsl:attribute name="number:decimal-places">
  2952.                                         <xsl:value-of select="string-length( substring-after( $valid-number-format-string, '.') ) - string-length( translate( substring-after( $valid-number-format-string, '.'), '0', '') )"/>
  2953.                                     </xsl:attribute>
  2954.                                     <xsl:attribute name="number:min-integer-digits">
  2955.                                         <xsl:value-of select="string-length( substring-before($valid-number-format-string, '.') ) - string-length(translate( substring-before($valid-number-format-string, '.'), '0', '') )"/>
  2956.                                     </xsl:attribute>
  2957.                                 </xsl:when>
  2958.                                 <xsl:otherwise>
  2959.                                     <xsl:attribute name="number:decimal-places">0</xsl:attribute>
  2960.                                     <xsl:attribute name="number:min-integer-digits">
  2961.                                         <xsl:value-of select="string-length( $valid-number-format-string ) - string-length(translate( $valid-number-format-string, '0', '') )"/>
  2962.                                     </xsl:attribute>
  2963.                                 </xsl:otherwise>
  2964.                             </xsl:choose>
  2965.                             <xsl:choose>
  2966.                                 <xsl:when test="contains( $valid-number-format-string, ',') and (substring( $valid-number-format-string,string-length($valid-number-format-string)) = ',')">
  2967.                                     <xsl:variable name="display-factor">
  2968.                                         <xsl:call-template name="get-display-factor">
  2969.                                             <xsl:with-param name="start-number" select="1"/>
  2970.                                             <xsl:with-param name="thousand-count">
  2971.                                                 <xsl:call-template name="thousand-count-temp">
  2972.                                                     <xsl:with-param name="format-unit" select="$valid-number-format-string"/>
  2973.                                                 </xsl:call-template>
  2974.                                             </xsl:with-param>
  2975.                                         </xsl:call-template>
  2976.                                     </xsl:variable>
  2977.                                     <xsl:attribute name="number:display-factor">
  2978.                                         <xsl:value-of select="$display-factor"/>
  2979.                                     </xsl:attribute>
  2980.                                     <xsl:attribute name="number:grouping">true</xsl:attribute>
  2981.                                 </xsl:when>
  2982.                                 <xsl:when test="contains( $valid-number-format-string, ',')">
  2983.                                     <xsl:attribute name="number:grouping">true</xsl:attribute>
  2984.                                 </xsl:when>
  2985.                             </xsl:choose>
  2986.                             <!-- deal with number:embedded-text -->
  2987.                             <xsl:call-template name="create-number-format-embedded-text">
  2988.                                 <xsl:with-param name="adapted-number-format-unit" select="$posed-number-format-unit"/>
  2989.                                 <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  2990.                             </xsl:call-template>
  2991.                         </xsl:element>
  2992.                     </xsl:otherwise>
  2993.                 </xsl:choose>
  2994.                 <!-- deal with post number:text -->
  2995.                 <xsl:variable name="post-number-format-text">
  2996.                     <xsl:call-template name="get-post-number-format-text">
  2997.                         <xsl:with-param name="adapted-number-format-unit" select="$posed-number-format-unit"/>
  2998.                         <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  2999.                     </xsl:call-template>
  3000.                 </xsl:variable>
  3001.                 <xsl:call-template name="create-number-format-content">
  3002.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3003.                     <xsl:with-param name="number-format-unit" select="$post-number-format-text"/>
  3004.                     <xsl:with-param name="unit-pos" select="1"/>
  3005.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3006.                 </xsl:call-template>
  3007.             </xsl:when>
  3008.             <xsl:when test="starts-with( $posed-number-format-unit, 'ggg')">
  3009.                 <xsl:element name="number:era">
  3010.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3011.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3012.                         <xsl:attribute name="number:calendar">
  3013.                             <xsl:value-of select="$calendar-type-name"/>
  3014.                         </xsl:attribute>
  3015.                     </xsl:if>
  3016.                 </xsl:element>
  3017.                 <xsl:call-template name="create-number-format-content">
  3018.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3019.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3020.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3021.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3022.                 </xsl:call-template>
  3023.             </xsl:when>
  3024.             <xsl:when test="starts-with( $posed-number-format-unit, 'gg')">
  3025.                 <xsl:element name="number:era">
  3026.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3027.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3028.                         <xsl:attribute name="number:calendar">
  3029.                             <xsl:value-of select="$calendar-type-name"/>
  3030.                         </xsl:attribute>
  3031.                     </xsl:if>
  3032.                 </xsl:element>
  3033.                 <xsl:call-template name="create-number-format-content">
  3034.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3035.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3036.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3037.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3038.                 </xsl:call-template>
  3039.             </xsl:when>
  3040.             <xsl:when test="starts-with( $posed-number-format-unit, 'g')">
  3041.                 <xsl:element name="number:era">
  3042.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3043.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3044.                         <xsl:attribute name="number:calendar">
  3045.                             <xsl:value-of select="$calendar-type-name"/>
  3046.                         </xsl:attribute>
  3047.                     </xsl:if>
  3048.                 </xsl:element>
  3049.                 <xsl:call-template name="create-number-format-content">
  3050.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3051.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3052.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3053.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3054.                 </xsl:call-template>
  3055.             </xsl:when>
  3056.             <xsl:when test="starts-with( $posed-number-format-unit, 'ee')">
  3057.                 <xsl:element name="number:year">
  3058.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3059.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3060.                         <xsl:attribute name="number:calendar">
  3061.                             <xsl:value-of select="$calendar-type-name"/>
  3062.                         </xsl:attribute>
  3063.                     </xsl:if>
  3064.                 </xsl:element>
  3065.                 <xsl:call-template name="create-number-format-content">
  3066.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3067.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3068.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3069.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3070.                 </xsl:call-template>
  3071.             </xsl:when>
  3072.             <xsl:when test="starts-with( $posed-number-format-unit, 'r')">
  3073.                 <xsl:element name="number:year">
  3074.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3075.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3076.                         <xsl:attribute name="number:calendar">
  3077.                             <xsl:value-of select="$calendar-type-name"/>
  3078.                         </xsl:attribute>
  3079.                     </xsl:if>
  3080.                 </xsl:element>
  3081.                 <xsl:call-template name="create-number-format-content">
  3082.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3083.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3084.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3085.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3086.                 </xsl:call-template>
  3087.             </xsl:when>
  3088.             <xsl:when test="starts-with( $posed-number-format-unit, 'yyyy')">
  3089.                 <xsl:element name="number:year">
  3090.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3091.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3092.                         <xsl:attribute name="number:calendar">
  3093.                             <xsl:value-of select="$calendar-type-name"/>
  3094.                         </xsl:attribute>
  3095.                     </xsl:if>
  3096.                 </xsl:element>
  3097.                 <xsl:call-template name="create-number-format-content">
  3098.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3099.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3100.                     <xsl:with-param name="unit-pos" select="$unit-pos + 4"/>
  3101.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3102.                 </xsl:call-template>
  3103.             </xsl:when>
  3104.             <xsl:when test="starts-with( $posed-number-format-unit, 'yy')">
  3105.                 <xsl:element name="number:year">
  3106.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3107.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3108.                         <xsl:attribute name="number:calendar">
  3109.                             <xsl:value-of select="$calendar-type-name"/>
  3110.                         </xsl:attribute>
  3111.                     </xsl:if>
  3112.                 </xsl:element>
  3113.                 <xsl:call-template name="create-number-format-content">
  3114.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3115.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3116.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3117.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3118.                 </xsl:call-template>
  3119.             </xsl:when>
  3120.             <xsl:when test="starts-with( $posed-number-format-unit, 'e') or starts-with( $posed-number-format-unit, 'y')">
  3121.                 <xsl:element name="number:year">
  3122.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3123.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3124.                         <xsl:attribute name="number:calendar">
  3125.                             <xsl:value-of select="$calendar-type-name"/>
  3126.                         </xsl:attribute>
  3127.                     </xsl:if>
  3128.                 </xsl:element>
  3129.                 <xsl:call-template name="create-number-format-content">
  3130.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3131.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3132.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3133.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3134.                 </xsl:call-template>
  3135.             </xsl:when>
  3136.             <xsl:when test="starts-with( $posed-number-format-unit, 'mmmmm')">
  3137.                 <xsl:element name="number:month">
  3138.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3139.                     <xsl:attribute name="number:textual">true</xsl:attribute>
  3140.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3141.                         <xsl:attribute name="number:calendar">
  3142.                             <xsl:value-of select="$calendar-type-name"/>
  3143.                         </xsl:attribute>
  3144.                     </xsl:if>
  3145.                 </xsl:element>
  3146.                 <xsl:call-template name="create-number-format-content">
  3147.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3148.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3149.                     <xsl:with-param name="unit-pos" select="$unit-pos + 5"/>
  3150.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3151.                 </xsl:call-template>
  3152.             </xsl:when>
  3153.             <xsl:when test="starts-with( $posed-number-format-unit, 'mmmm')">
  3154.                 <xsl:element name="number:month">
  3155.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3156.                     <xsl:attribute name="number:textual">true</xsl:attribute>
  3157.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3158.                         <xsl:attribute name="number:calendar">
  3159.                             <xsl:value-of select="$calendar-type-name"/>
  3160.                         </xsl:attribute>
  3161.                     </xsl:if>
  3162.                 </xsl:element>
  3163.                 <xsl:call-template name="create-number-format-content">
  3164.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3165.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3166.                     <xsl:with-param name="unit-pos" select="$unit-pos + 4"/>
  3167.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3168.                 </xsl:call-template>
  3169.             </xsl:when>
  3170.             <xsl:when test="starts-with( $posed-number-format-unit, 'mmm')">
  3171.                 <xsl:element name="number:month">
  3172.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3173.                     <xsl:attribute name="number:textual">true</xsl:attribute>
  3174.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3175.                         <xsl:attribute name="number:calendar">
  3176.                             <xsl:value-of select="$calendar-type-name"/>
  3177.                         </xsl:attribute>
  3178.                     </xsl:if>
  3179.                 </xsl:element>
  3180.                 <xsl:call-template name="create-number-format-content">
  3181.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3182.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3183.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3184.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3185.                 </xsl:call-template>
  3186.             </xsl:when>
  3187.             <xsl:when test="starts-with( $posed-number-format-unit, '[mm]')">
  3188.                 <xsl:element name="number:minutes">
  3189.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3190.                 </xsl:element>
  3191.                 <xsl:call-template name="create-number-format-content">
  3192.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3193.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3194.                     <xsl:with-param name="unit-pos" select="$unit-pos + 4"/>
  3195.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3196.                 </xsl:call-template>
  3197.             </xsl:when>
  3198.             <xsl:when test="starts-with( $posed-number-format-unit, '[m]')">
  3199.                 <xsl:element name="number:minutes">
  3200.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3201.                 </xsl:element>
  3202.                 <xsl:call-template name="create-number-format-content">
  3203.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3204.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3205.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3206.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3207.                 </xsl:call-template>
  3208.             </xsl:when>
  3209.             <xsl:when test="starts-with( $posed-number-format-unit, 'mm') and ( contains( $number-format-unit, 'h') or contains( $posed-number-format-unit, 's') )">
  3210.                 <xsl:element name="number:minutes">
  3211.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3212.                 </xsl:element>
  3213.                 <xsl:call-template name="create-number-format-content">
  3214.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3215.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3216.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3217.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3218.                 </xsl:call-template>
  3219.             </xsl:when>
  3220.             <xsl:when test="starts-with( $posed-number-format-unit, 'mm')">
  3221.                 <xsl:element name="number:month">
  3222.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3223.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3224.                         <xsl:attribute name="number:calendar">
  3225.                             <xsl:value-of select="$calendar-type-name"/>
  3226.                         </xsl:attribute>
  3227.                     </xsl:if>
  3228.                 </xsl:element>
  3229.                 <xsl:call-template name="create-number-format-content">
  3230.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3231.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3232.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3233.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3234.                 </xsl:call-template>
  3235.             </xsl:when>
  3236.             <xsl:when test="starts-with( $posed-number-format-unit, 'm') and ( contains( $number-format-unit, 'h') or contains( $posed-number-format-unit, 's') )">
  3237.                 <xsl:element name="number:minutes">
  3238.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3239.                 </xsl:element>
  3240.                 <xsl:call-template name="create-number-format-content">
  3241.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3242.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3243.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3244.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3245.                 </xsl:call-template>
  3246.             </xsl:when>
  3247.             <xsl:when test="starts-with( $posed-number-format-unit, 'm')">
  3248.                 <xsl:element name="number:month">
  3249.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3250.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3251.                         <xsl:attribute name="number:calendar">
  3252.                             <xsl:value-of select="$calendar-type-name"/>
  3253.                         </xsl:attribute>
  3254.                     </xsl:if>
  3255.                 </xsl:element>
  3256.                 <xsl:call-template name="create-number-format-content">
  3257.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3258.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3259.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3260.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3261.                 </xsl:call-template>
  3262.             </xsl:when>
  3263.             <xsl:when test="starts-with( $posed-number-format-unit, 'dddd') or starts-with( $posed-number-format-unit, 'aaaa')">
  3264.                 <xsl:element name="number:day-of-week">
  3265.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3266.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3267.                         <xsl:attribute name="number:calendar">
  3268.                             <xsl:value-of select="$calendar-type-name"/>
  3269.                         </xsl:attribute>
  3270.                     </xsl:if>
  3271.                 </xsl:element>
  3272.                 <xsl:call-template name="create-number-format-content">
  3273.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3274.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3275.                     <xsl:with-param name="unit-pos" select="$unit-pos + 4"/>
  3276.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3277.                 </xsl:call-template>
  3278.             </xsl:when>
  3279.             <xsl:when test="starts-with( $posed-number-format-unit, 'ddd') or starts-with( $posed-number-format-unit, 'aaa')">
  3280.                 <xsl:element name="number:day-of-week">
  3281.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3282.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3283.                         <xsl:attribute name="number:calendar">
  3284.                             <xsl:value-of select="$calendar-type-name"/>
  3285.                         </xsl:attribute>
  3286.                     </xsl:if>
  3287.                 </xsl:element>
  3288.                 <xsl:call-template name="create-number-format-content">
  3289.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3290.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3291.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3292.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3293.                 </xsl:call-template>
  3294.             </xsl:when>
  3295.             <xsl:when test="starts-with( $posed-number-format-unit, 'dd')">
  3296.                 <xsl:element name="number:day">
  3297.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3298.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3299.                         <xsl:attribute name="number:calendar">
  3300.                             <xsl:value-of select="$calendar-type-name"/>
  3301.                         </xsl:attribute>
  3302.                     </xsl:if>
  3303.                 </xsl:element>
  3304.                 <xsl:call-template name="create-number-format-content">
  3305.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3306.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3307.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3308.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3309.                 </xsl:call-template>
  3310.             </xsl:when>
  3311.             <xsl:when test="starts-with( $posed-number-format-unit, 'd')">
  3312.                 <xsl:element name="number:day">
  3313.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3314.                     <xsl:if test="string-length($calendar-type-name) > 0">
  3315.                         <xsl:attribute name="number:calendar">
  3316.                             <xsl:value-of select="$calendar-type-name"/>
  3317.                         </xsl:attribute>
  3318.                     </xsl:if>
  3319.                 </xsl:element>
  3320.                 <xsl:call-template name="create-number-format-content">
  3321.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3322.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3323.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3324.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3325.                 </xsl:call-template>
  3326.             </xsl:when>
  3327.             <xsl:when test="starts-with( $posed-number-format-unit, 'hh')">
  3328.                 <xsl:element name="number:hours">
  3329.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3330.                 </xsl:element>
  3331.                 <xsl:call-template name="create-number-format-content">
  3332.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3333.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3334.                     <xsl:with-param name="unit-pos" select="$unit-pos + 2"/>
  3335.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3336.                 </xsl:call-template>
  3337.             </xsl:when>
  3338.             <xsl:when test="starts-with( $posed-number-format-unit, '[hh]')">
  3339.                 <xsl:element name="number:hours">
  3340.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3341.                 </xsl:element>
  3342.                 <xsl:call-template name="create-number-format-content">
  3343.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3344.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3345.                     <xsl:with-param name="unit-pos" select="$unit-pos + 4"/>
  3346.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3347.                 </xsl:call-template>
  3348.             </xsl:when>
  3349.             <xsl:when test="starts-with( $posed-number-format-unit, 'h')">
  3350.                 <xsl:element name="number:hours">
  3351.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3352.                 </xsl:element>
  3353.                 <xsl:call-template name="create-number-format-content">
  3354.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3355.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3356.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3357.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3358.                 </xsl:call-template>
  3359.             </xsl:when>
  3360.             <xsl:when test="starts-with( $posed-number-format-unit, '[h]')">
  3361.                 <xsl:element name="number:hours">
  3362.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3363.                 </xsl:element>
  3364.                 <xsl:call-template name="create-number-format-content">
  3365.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3366.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3367.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3368.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3369.                 </xsl:call-template>
  3370.             </xsl:when>
  3371.             <xsl:when test="starts-with( $posed-number-format-unit, 'AM/PM') or starts-with( $posed-number-format-unit, 'am/pm')">
  3372.                 <number:am-pm/>
  3373.                 <!-- long: am-pm doesn't support long style yet -->
  3374.                 <xsl:call-template name="create-number-format-content">
  3375.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3376.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3377.                     <xsl:with-param name="unit-pos" select="$unit-pos + 5"/>
  3378.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3379.                 </xsl:call-template>
  3380.             </xsl:when>
  3381.             <xsl:when test="starts-with( $posed-number-format-unit, 'a/p'or starts-with( $posed-number-format-unit, 'A/P'))">
  3382.                 <number:am-pm/>
  3383.                 <!-- short: am-pm doesn't support short style yet -->
  3384.                 <xsl:call-template name="create-number-format-content">
  3385.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3386.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3387.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3388.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3389.                 </xsl:call-template>
  3390.             </xsl:when>
  3391.             <xsl:when test="starts-with( $posed-number-format-unit, 'ss')">
  3392.                 <xsl:variable name="decimal-places">
  3393.                     <xsl:choose>
  3394.                         <xsl:when test="starts-with( $posed-number-format-unit, 'ss.0')">
  3395.                             <xsl:value-of select="string-length( $posed-number-format-unit) - string-length( translate( $posed-number-format-unit, '0', '') )"/>
  3396.                         </xsl:when>
  3397.                         <xsl:otherwise>0</xsl:otherwise>
  3398.                     </xsl:choose>
  3399.                 </xsl:variable>
  3400.                 <xsl:element name="number:seconds">
  3401.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3402.                     <xsl:if test="$decimal-places > 0">
  3403.                         <xsl:attribute name="number:decimal-places">
  3404.                             <xsl:value-of select="$decimal-places"/>
  3405.                         </xsl:attribute>
  3406.                     </xsl:if>
  3407.                 </xsl:element>
  3408.                 <xsl:variable name="second-length">
  3409.                     <xsl:choose>
  3410.                         <xsl:when test="$decimal-places > 0">
  3411.                             <xsl:value-of select="$decimal-places + 3"/>
  3412.                         </xsl:when>
  3413.                         <xsl:otherwise>2</xsl:otherwise>
  3414.                     </xsl:choose>
  3415.                 </xsl:variable>
  3416.                 <xsl:call-template name="create-number-format-content">
  3417.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3418.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3419.                     <xsl:with-param name="unit-pos" select="$unit-pos + $second-length"/>
  3420.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3421.                 </xsl:call-template>
  3422.             </xsl:when>
  3423.             <xsl:when test="starts-with( $posed-number-format-unit, '[ss]')">
  3424.                 <xsl:element name="number:seconds">
  3425.                     <xsl:attribute name="number:style">long</xsl:attribute>
  3426.                 </xsl:element>
  3427.                 <xsl:call-template name="create-number-format-content">
  3428.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3429.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3430.                     <xsl:with-param name="unit-pos" select="$unit-pos + 4"/>
  3431.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3432.                 </xsl:call-template>
  3433.             </xsl:when>
  3434.             <xsl:when test="starts-with( $posed-number-format-unit, 's')">
  3435.                 <xsl:variable name="decimal-places">
  3436.                     <xsl:choose>
  3437.                         <xsl:when test="starts-with( $posed-number-format-unit, 's.0')">
  3438.                             <xsl:value-of select="string-length( $posed-number-format-unit) - string-length( translate( $posed-number-format-unit, '0', '') )"/>
  3439.                         </xsl:when>
  3440.                         <xsl:otherwise>0</xsl:otherwise>
  3441.                     </xsl:choose>
  3442.                 </xsl:variable>
  3443.                 <xsl:element name="number:seconds">
  3444.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3445.                     <xsl:if test="$decimal-places > 0">
  3446.                         <xsl:attribute name="number:decimal-places">
  3447.                             <xsl:value-of select="$decimal-places"/>
  3448.                         </xsl:attribute>
  3449.                     </xsl:if>
  3450.                 </xsl:element>
  3451.                 <xsl:variable name="second-length">
  3452.                     <xsl:choose>
  3453.                         <xsl:when test="$decimal-places > 0">
  3454.                             <xsl:value-of select="$decimal-places + 2"/>
  3455.                         </xsl:when>
  3456.                         <xsl:otherwise>1</xsl:otherwise>
  3457.                     </xsl:choose>
  3458.                 </xsl:variable>
  3459.                 <xsl:call-template name="create-number-format-content">
  3460.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3461.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3462.                     <xsl:with-param name="unit-pos" select="$unit-pos + $second-length"/>
  3463.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3464.                 </xsl:call-template>
  3465.             </xsl:when>
  3466.             <xsl:when test="starts-with( $posed-number-format-unit, '[s]')">
  3467.                 <xsl:element name="number:seconds">
  3468.                     <xsl:attribute name="number:style">short</xsl:attribute>
  3469.                 </xsl:element>
  3470.                 <xsl:call-template name="create-number-format-content">
  3471.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3472.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3473.                     <xsl:with-param name="unit-pos" select="$unit-pos + 3"/>
  3474.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3475.                 </xsl:call-template>
  3476.             </xsl:when>
  3477.             <xsl:when test="starts-with( $posed-number-format-unit, '@')">
  3478.                 <number:text-content/>
  3479.                 <xsl:call-template name="create-number-format-content">
  3480.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3481.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3482.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3483.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3484.                 </xsl:call-template>
  3485.             </xsl:when>
  3486.             <xsl:when test="$posed-number-format-unit = 'General Number'">
  3487.                 <number:number number:decimal-places="0" number:min-integer-digits="1"/>
  3488.             </xsl:when>
  3489.             <xsl:when test="$posed-number-format-unit = 'General Date'">
  3490.                 <number:year number:style="long"/>
  3491.                 <number:text>-</number:text>
  3492.                 <number:month number:style="short"/>
  3493.                 <number:text>-</number:text>
  3494.                 <number:day number:style="short"/>
  3495.                 <number:text>
  3496.                     <xsl:text> </xsl:text>
  3497.                 </number:text>
  3498.                 <number:hours number:style="short"/>
  3499.                 <number:text>:</number:text>
  3500.                 <number:minutes number:style="long"/>
  3501.             </xsl:when>
  3502.             <!-- special for General number:text-content output -->
  3503.             <xsl:when test="starts-with($posed-number-format-unit , 'General')">
  3504.                 <xsl:choose>
  3505.                     <xsl:when test="$posed-number-format-unit = 'General' and $condition-pos = 1">
  3506.                         <number:number number:decimal-places="0" number:min-integer-digits="1"/>
  3507.                     </xsl:when>
  3508.                     <xsl:otherwise>
  3509.                         <xsl:call-template name="create-number-format-content">
  3510.                             <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3511.                             <xsl:with-param name="number-format-unit" select="$posed-number-format-unit"/>
  3512.                             <xsl:with-param name="unit-pos" select="8"/>
  3513.                             <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3514.                         </xsl:call-template>
  3515.                     </xsl:otherwise>
  3516.                 </xsl:choose>
  3517.             </xsl:when>
  3518.             <xsl:when test="$posed-number-format-unit = 'Fixed'">
  3519.                 <number:number number:decimal-places="2" number:min-integer-digits="1"/>
  3520.                 <number:text/>
  3521.             </xsl:when>
  3522.             <xsl:when test="$posed-number-format-unit = 'Standard'">
  3523.                 <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
  3524.             </xsl:when>
  3525.             <xsl:when test="$posed-number-format-unit = 'Long Date'">
  3526.                 <number:year number:style="long"/>
  3527.                 <number:text>-</number:text>
  3528.                 <number:month number:style="long"/>
  3529.                 <number:text>-</number:text>
  3530.                 <number:day number:style="long"/>
  3531.             </xsl:when>
  3532.             <xsl:when test="$posed-number-format-unit = 'Medium Date'">
  3533.                 <number:day number:style="short"/>
  3534.                 <number:text>-</number:text>
  3535.                 <number:month number:textual="true"/>
  3536.                 <number:text>-</number:text>
  3537.                 <number:year number:style="short"/>
  3538.             </xsl:when>
  3539.             <xsl:when test="$posed-number-format-unit = 'Short Date'">
  3540.                 <number:day number:style="short"/>
  3541.                 <number:text>-</number:text>
  3542.                 <number:month number:style="short"/>
  3543.                 <number:text>-</number:text>
  3544.                 <number:year number:style="short"/>
  3545.             </xsl:when>
  3546.             <xsl:when test="$posed-number-format-unit = 'Long Time'">
  3547.                 <number:hours number:style="long"/>
  3548.                 <number:text>:</number:text>
  3549.                 <number:minutes number:style="long"/>
  3550.                 <number:text>:</number:text>
  3551.                 <number:seconds number:style="long"/>
  3552.                 <number:text>
  3553.                     <xsl:text> </xsl:text>
  3554.                 </number:text>
  3555.                 <number:am-pm/>
  3556.             </xsl:when>
  3557.             <xsl:when test="$posed-number-format-unit = 'Medium Time'">
  3558.                 <number:hours number:style="short"/>
  3559.                 <number:text>:</number:text>
  3560.                 <number:minutes number:style="long"/>
  3561.                 <number:text>
  3562.                     <xsl:text> </xsl:text>
  3563.                 </number:text>
  3564.                 <number:am-pm/>
  3565.             </xsl:when>
  3566.             <xsl:when test="$posed-number-format-unit = 'Short Time'">
  3567.                 <number:hours number:style="short"/>
  3568.                 <number:text>:</number:text>
  3569.                 <number:minutes number:style="long"/>
  3570.                 <number:text>
  3571.                     <xsl:text> </xsl:text>
  3572.                 </number:text>
  3573.             </xsl:when>
  3574.             <xsl:when test="$posed-number-format-unit = 'Percent'">
  3575.                 <number:number number:decimal-places="2" number:min-integer-digits="1"/>
  3576.                 <number:text>%</number:text>
  3577.             </xsl:when>
  3578.             <xsl:when test="$posed-number-format-unit = 'Scientific'">
  3579.                 <number:scientific-number number:decimal-places="2" number:min-integer-digits="1" number:min-exponent-digits="2"/>
  3580.             </xsl:when>
  3581.             <xsl:when test="starts-with( $posed-number-format-unit, '[')">
  3582.                 <xsl:call-template name="create-number-format-content">
  3583.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3584.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3585.                     <xsl:with-param name="unit-pos" select="$unit-pos + string-length( substring-before( $posed-number-format-unit, ']') ) + 1"/>
  3586.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3587.                     <xsl:with-param name="isNumberTextElementOpened" select="$isNumberTextElementOpened"/>
  3588.                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  3589.                 </xsl:call-template>
  3590.             </xsl:when>
  3591.             <xsl:when test="starts-with( $posed-number-format-unit, '/')">
  3592.                 <number:text>/</number:text>
  3593.                 <xsl:call-template name="create-number-format-content">
  3594.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3595.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3596.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3597.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3598.                 </xsl:call-template>
  3599.             </xsl:when>
  3600.             <xsl:when test="starts-with( $posed-number-format-unit, ':')">
  3601.                 <number:text>:</number:text>
  3602.                 <xsl:call-template name="create-number-format-content">
  3603.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3604.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3605.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3606.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3607.                 </xsl:call-template>
  3608.             </xsl:when>
  3609.             <xsl:when test="string-length( $posed-number-format-unit ) > 0">
  3610.                 <xsl:call-template name="create-number-format-content">
  3611.                     <xsl:with-param name="style-type-name" select="$style-type-name"/>
  3612.                     <xsl:with-param name="number-format-unit" select="$number-format-unit"/>
  3613.                     <xsl:with-param name="unit-pos" select="$unit-pos + 1"/>
  3614.                     <xsl:with-param name="condition-pos" select="$condition-pos"/>
  3615.                     <xsl:with-param name="isNumberTextElementOpened" select="$isNumberTextElementOpened"/>
  3616.                     <xsl:with-param name="posed-number-format-unit" select="$posed-number-format-unit"/>
  3617.                     <xsl:with-param name="numberTextValue" select="substring( $posed-number-format-unit, 1, 1)"/>
  3618.                 </xsl:call-template>
  3619.             </xsl:when>
  3620.         </xsl:choose>
  3621.     </xsl:template>
  3622.     <xsl:template name="thousand-count-temp">
  3623.         <!-- thousand count for char ',' at the latter of format-unit by recursion -->
  3624.         <xsl:param name="format-unit"/>
  3625.         <xsl:choose>
  3626.             <xsl:when test="contains($format-unit, ',#')">
  3627.                 <xsl:call-template name="thousand-count-temp">
  3628.                     <xsl:with-param name="format-unit" select="substring-after($format-unit, ',#')"/>
  3629.                 </xsl:call-template>
  3630.             </xsl:when>
  3631.             <xsl:when test="contains($format-unit, ',0')">
  3632.                 <xsl:call-template name="thousand-count-temp">
  3633.                     <xsl:with-param name="format-unit" select="substring-after($format-unit, ',0')"/>
  3634.                 </xsl:call-template>
  3635.             </xsl:when>
  3636.             <xsl:otherwise>
  3637.                 <xsl:value-of select="string-length($format-unit) - string-length( translate($format-unit, ',', ''))"/>
  3638.             </xsl:otherwise>
  3639.         </xsl:choose>
  3640.     </xsl:template>
  3641.     <xsl:template name="get-calendar-type-name">
  3642.         <xsl:param name="calendar-type"/>
  3643.         <xsl:variable name="temp-type">
  3644.             <xsl:call-template name="hex2decimal">
  3645.                 <xsl:with-param name="hex-number" select="$calendar-type"/>
  3646.                 <xsl:with-param name="index" select="1"/>
  3647.                 <xsl:with-param name="str-length" select="string-length($calendar-type)"/>
  3648.                 <xsl:with-param name="last-value" select="0"/>
  3649.             </xsl:call-template>
  3650.         </xsl:variable>
  3651.         <xsl:choose>
  3652.             <!-- Japanese (Emperor era), #03 -->
  3653.             <xsl:when test="$temp-type = 3">gengou</xsl:when>
  3654.             <!-- Taiwanese, #04 -->
  3655.             <xsl:when test="$temp-type = 4">ROC</xsl:when>
  3656.             <!-- Korean (Tangun era) hanja_yoil is ok too. #05 -->
  3657.             <xsl:when test="$temp-type = 5">hanja</xsl:when>
  3658.             <!-- Hijri (Arabic lunar), #06 -->
  3659.             <xsl:when test="$temp-type = 6">hijri</xsl:when>
  3660.             <!-- Thai, #07 -->
  3661.             <xsl:when test="$temp-type = 7">buddhist</xsl:when>
  3662.             <!-- 01: Gregorian (Localized), 02: Gregorian (United States), 09: Gregorian (Middle East French), 0A: Gregorian (Arabic), 0B: Gregorian (Transliterated English) -->
  3663.             <xsl:otherwise>gregorian</xsl:otherwise>
  3664.             <!-- not found jewish yet -->
  3665.         </xsl:choose>
  3666.     </xsl:template>
  3667.     <xsl:template name="get-valid-number-format-string">
  3668.         <xsl:param name="number-format-unit"/>
  3669.         <xsl:choose>
  3670.             <xsl:when test="contains( $number-format-unit, '\')">
  3671.                 <xsl:call-template name="get-valid-number-format-string">
  3672.                     <xsl:with-param name="number-format-unit" select="concat( substring-before( $number-format-unit, '\'), substring( substring-after( $number-format-unit, '\'), 2) )"/>
  3673.                 </xsl:call-template>
  3674.             </xsl:when>
  3675.             <xsl:when test="contains( $number-format-unit, '*')">
  3676.                 <xsl:call-template name="get-valid-number-format-string">
  3677.                     <xsl:with-param name="number-format-unit" select="concat( substring-before( $number-format-unit, '*'), substring( substring-after( $number-format-unit, '*'), 2) )"/>
  3678.                 </xsl:call-template>
  3679.             </xsl:when>
  3680.             <xsl:when test="contains( $number-format-unit, '_')">
  3681.                 <xsl:call-template name="get-valid-number-format-string">
  3682.                     <xsl:with-param name="number-format-unit" select="concat( substring-before( $number-format-unit, '_'), substring( substring-after( $number-format-unit, '_'), 2) )"/>
  3683.                 </xsl:call-template>
  3684.             </xsl:when>
  3685.             <xsl:when test="contains( $number-format-unit, '"')">
  3686.                 <xsl:call-template name="get-valid-number-format-string">
  3687.                     <xsl:with-param name="number-format-unit" select="concat( substring-before( $number-format-unit, '"'), substring-after( substring-after( $number-format-unit, '"'), '"') )"/>
  3688.                 </xsl:call-template>
  3689.             </xsl:when>
  3690.             <xsl:otherwise>
  3691.                 <xsl:value-of select="$number-format-unit"/>
  3692.             </xsl:otherwise>
  3693.         </xsl:choose>
  3694.     </xsl:template>
  3695.     <xsl:template name="get-display-factor">
  3696.         <xsl:param name="start-number"/>
  3697.         <xsl:param name="thousand-count"/>
  3698.         <xsl:choose>
  3699.             <xsl:when test="$thousand-count = 0">
  3700.                 <xsl:value-of select="$start-number"/>
  3701.             </xsl:when>
  3702.             <xsl:otherwise>
  3703.                 <xsl:call-template name="get-display-factor">
  3704.                     <xsl:with-param name="start-number" select="$start-number * 1000"/>
  3705.                     <xsl:with-param name="thousand-count" select="$thousand-count -1"/>
  3706.                 </xsl:call-template>
  3707.             </xsl:otherwise>
  3708.         </xsl:choose>
  3709.     </xsl:template>
  3710.     <xsl:template name="get-post-number-format-text">
  3711.         <xsl:param name="adapted-number-format-unit"/>
  3712.         <xsl:param name="valid-number-format-string"/>
  3713.         <xsl:variable name="first-embedded-character-pos">
  3714.             <xsl:choose>
  3715.                 <xsl:when test="contains( $adapted-number-format-unit, '\')">
  3716.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '\') ) + 1"/>
  3717.                 </xsl:when>
  3718.                 <xsl:when test="contains( $adapted-number-format-unit, '_')">
  3719.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '_') ) + 1"/>
  3720.                 </xsl:when>
  3721.                 <xsl:when test="contains( $adapted-number-format-unit, '*')">
  3722.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '*') ) + 1"/>
  3723.                 </xsl:when>
  3724.                 <xsl:otherwise>0</xsl:otherwise>
  3725.             </xsl:choose>
  3726.         </xsl:variable>
  3727.         <xsl:variable name="first-embedded-string-pos">
  3728.             <xsl:choose>
  3729.                 <xsl:when test="contains( $adapted-number-format-unit, '"')">
  3730.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '"') ) + 1"/>
  3731.                 </xsl:when>
  3732.                 <xsl:otherwise>0</xsl:otherwise>
  3733.             </xsl:choose>
  3734.         </xsl:variable>
  3735.         <xsl:variable name="first-embedded-text-pos">
  3736.             <xsl:choose>
  3737.                 <xsl:when test="$first-embedded-character-pos < $first-embedded-string-pos and $first-embedded-character-pos > 0">
  3738.                     <xsl:value-of select="$first-embedded-character-pos"/>
  3739.                 </xsl:when>
  3740.                 <xsl:when test="$first-embedded-character-pos < $first-embedded-string-pos and $first-embedded-character-pos = 0">
  3741.                     <xsl:value-of select="$first-embedded-string-pos"/>
  3742.                 </xsl:when>
  3743.                 <xsl:when test="$first-embedded-character-pos > $first-embedded-string-pos and $first-embedded-string-pos > 0">
  3744.                     <xsl:value-of select="$first-embedded-string-pos"/>
  3745.                 </xsl:when>
  3746.                 <xsl:when test="$first-embedded-character-pos > $first-embedded-string-pos and $first-embedded-string-pos = 0">
  3747.                     <xsl:value-of select="$first-embedded-character-pos"/>
  3748.                 </xsl:when>
  3749.             </xsl:choose>
  3750.         </xsl:variable>
  3751.         <xsl:choose>
  3752.             <xsl:when test="$first-embedded-text-pos > string-length( $valid-number-format-string )">
  3753.                 <xsl:value-of select="substring( $adapted-number-format-unit, $first-embedded-text-pos)"/>
  3754.             </xsl:when>
  3755.             <xsl:when test="$first-embedded-text-pos > 0 and $first-embedded-text-pos < string-length( $valid-number-format-string )">
  3756.                 <xsl:choose>
  3757.                     <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '\')">
  3758.                         <xsl:call-template name="get-post-number-format-text">
  3759.                             <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '\'), substring( $adapted-number-format-unit, $first-embedded-text-pos + 2) )"/>
  3760.                             <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3761.                         </xsl:call-template>
  3762.                     </xsl:when>
  3763.                     <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '_')">
  3764.                         <xsl:call-template name="get-post-number-format-text">
  3765.                             <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '_'), substring( $adapted-number-format-unit, $first-embedded-text-pos + 2) )"/>
  3766.                             <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3767.                         </xsl:call-template>
  3768.                     </xsl:when>
  3769.                     <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '*')">
  3770.                         <xsl:call-template name="get-post-number-format-text">
  3771.                             <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '*'), substring( $adapted-number-format-unit, $first-embedded-text-pos + 2) )"/>
  3772.                             <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3773.                         </xsl:call-template>
  3774.                     </xsl:when>
  3775.                     <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '"')">
  3776.                         <xsl:call-template name="get-post-number-format-text">
  3777.                             <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '"'), substring-after( substring-after( $adapted-number-format-unit, '"'), '"') )"/>
  3778.                             <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3779.                         </xsl:call-template>
  3780.                     </xsl:when>
  3781.                 </xsl:choose>
  3782.             </xsl:when>
  3783.             <xsl:otherwise/>
  3784.         </xsl:choose>
  3785.     </xsl:template>
  3786.     <xsl:template name="create-number-format-embedded-text">
  3787.         <xsl:param name="adapted-number-format-unit"/>
  3788.         <xsl:param name="valid-number-format-string"/>
  3789.         <xsl:variable name="first-embedded-character-pos">
  3790.             <xsl:choose>
  3791.                 <xsl:when test="contains( $adapted-number-format-unit, '\')">
  3792.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '\') ) + 1"/>
  3793.                 </xsl:when>
  3794.                 <xsl:when test="contains( $adapted-number-format-unit, '_')">
  3795.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '_') ) + 1"/>
  3796.                 </xsl:when>
  3797.                 <xsl:when test="contains( $adapted-number-format-unit, '*')">
  3798.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '*') ) + 1"/>
  3799.                 </xsl:when>
  3800.                 <xsl:otherwise>0</xsl:otherwise>
  3801.             </xsl:choose>
  3802.         </xsl:variable>
  3803.         <xsl:variable name="first-embedded-string-pos">
  3804.             <xsl:choose>
  3805.                 <xsl:when test="contains( $adapted-number-format-unit, '"')">
  3806.                     <xsl:value-of select="string-length( substring-before($adapted-number-format-unit, '"') ) + 1"/>
  3807.                 </xsl:when>
  3808.                 <xsl:otherwise>0</xsl:otherwise>
  3809.             </xsl:choose>
  3810.         </xsl:variable>
  3811.         <xsl:variable name="first-embedded-text-pos">
  3812.             <xsl:choose>
  3813.                 <xsl:when test="$first-embedded-character-pos < $first-embedded-string-pos and $first-embedded-character-pos > 0">
  3814.                     <xsl:value-of select="$first-embedded-character-pos"/>
  3815.                 </xsl:when>
  3816.                 <xsl:when test="$first-embedded-character-pos < $first-embedded-string-pos and $first-embedded-character-pos = 0">
  3817.                     <xsl:value-of select="$first-embedded-string-pos"/>
  3818.                 </xsl:when>
  3819.                 <xsl:when test="$first-embedded-character-pos > $first-embedded-string-pos and $first-embedded-string-pos > 0">
  3820.                     <xsl:value-of select="$first-embedded-string-pos"/>
  3821.                 </xsl:when>
  3822.                 <xsl:when test="$first-embedded-character-pos > $first-embedded-string-pos and $first-embedded-string-pos = 0">
  3823.                     <xsl:value-of select="$first-embedded-character-pos"/>
  3824.                 </xsl:when>
  3825.             </xsl:choose>
  3826.         </xsl:variable>
  3827.         <xsl:if test="$first-embedded-text-pos > 0 and $first-embedded-text-pos < string-length( $valid-number-format-string )">
  3828.             <xsl:variable name="text-pos">
  3829.                 <xsl:choose>
  3830.                     <xsl:when test="contains( $valid-number-format-string, '.')">
  3831.                         <xsl:variable name="right-text-pos" select="substring( substring-before( $valid-number-format-string, '.'), $first-embedded-text-pos)"/>
  3832.                         <xsl:value-of select="string-length($right-text-pos) - string-length( translate( $right-text-pos, '0#?', '') )"/>
  3833.                     </xsl:when>
  3834.                     <xsl:when test="contains( $valid-number-format-string, '/')">
  3835.                         <xsl:variable name="right-text-pos" select="substring( substring-before( $valid-number-format-string, '/'), $first-embedded-text-pos)"/>
  3836.                         <xsl:value-of select="string-length($right-text-pos) - string-length( translate( $right-text-pos, '0#?', '') )"/>
  3837.                     </xsl:when>
  3838.                     <xsl:when test="contains( $valid-number-format-string, '%')">
  3839.                         <xsl:variable name="right-text-pos" select="substring( substring-before( $valid-number-format-string, '%'), $first-embedded-text-pos)"/>
  3840.                         <xsl:value-of select="string-length($right-text-pos) - string-length( translate( $right-text-pos, '0#?', '') )"/>
  3841.                     </xsl:when>
  3842.                     <xsl:when test="contains( $valid-number-format-string, 'E')">
  3843.                         <xsl:variable name="right-text-pos" select="substring( substring-before( $valid-number-format-string, 'E'), $first-embedded-text-pos)"/>
  3844.                         <xsl:value-of select="string-length($right-text-pos) - string-length( translate( $right-text-pos, '0#?', '') )"/>
  3845.                     </xsl:when>
  3846.                     <xsl:otherwise>
  3847.                         <xsl:variable name="right-text-pos" select="substring( $valid-number-format-string, $first-embedded-text-pos)"/>
  3848.                         <xsl:value-of select="string-length($right-text-pos) - string-length( translate( $right-text-pos, '0#?', '') )"/>
  3849.                     </xsl:otherwise>
  3850.                 </xsl:choose>
  3851.             </xsl:variable>
  3852.             <xsl:choose>
  3853.                 <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '\')">
  3854.                     <number:embedded-text number:position="{$text-pos}">
  3855.                         <xsl:value-of select="substring( $adapted-number-format-unit, $first-embedded-text-pos + 1, 1)"/>
  3856.                     </number:embedded-text>
  3857.                     <xsl:call-template name="create-number-format-embedded-text">
  3858.                         <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '\'), substring( $adapted-number-format-unit, $first-embedded-text-pos + 2) )"/>
  3859.                         <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3860.                     </xsl:call-template>
  3861.                 </xsl:when>
  3862.                 <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '_')">
  3863.                     <number:embedded-text number:position="{$text-pos}">
  3864.                         <xsl:value-of select="substring( $adapted-number-format-unit, $first-embedded-text-pos + 1, 1)"/>
  3865.                     </number:embedded-text>
  3866.                     <xsl:call-template name="create-number-format-embedded-text">
  3867.                         <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '_'), substring( $adapted-number-format-unit, $first-embedded-text-pos + 2) )"/>
  3868.                         <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3869.                     </xsl:call-template>
  3870.                 </xsl:when>
  3871.                 <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '*')">
  3872.                     <number:embedded-text number:position="{$text-pos}">
  3873.                         <xsl:value-of select="substring( $adapted-number-format-unit, $first-embedded-text-pos + 1, 1)"/>
  3874.                     </number:embedded-text>
  3875.                     <xsl:call-template name="create-number-format-embedded-text">
  3876.                         <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '*'), substring( $adapted-number-format-unit, $first-embedded-text-pos + 2) )"/>
  3877.                         <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3878.                     </xsl:call-template>
  3879.                 </xsl:when>
  3880.                 <xsl:when test="starts-with( substring( $adapted-number-format-unit, $first-embedded-text-pos, 1), '"')">
  3881.                     <number:embedded-text number:position="{$text-pos}">
  3882.                         <xsl:value-of select="substring-before( substring( $adapted-number-format-unit, $first-embedded-text-pos + 1), '"')"/>
  3883.                     </number:embedded-text>
  3884.                     <xsl:call-template name="create-number-format-embedded-text">
  3885.                         <xsl:with-param name="adapted-number-format-unit" select="concat( substring-before( $adapted-number-format-unit, '"'), substring-after( substring-after( $adapted-number-format-unit, '"'), '"') )"/>
  3886.                         <xsl:with-param name="valid-number-format-string" select="$valid-number-format-string"/>
  3887.                     </xsl:call-template>
  3888.                 </xsl:when>
  3889.             </xsl:choose>
  3890.         </xsl:if>
  3891.     </xsl:template>
  3892.     <xsl:template name="create-master-styles">
  3893.         <xsl:param name="worksheetoptions"/>
  3894.         <xsl:for-each select="$worksheetoptions">
  3895.             <xsl:element name="style:master-page">
  3896.                 <xsl:attribute name="style:name">
  3897.                     <xsl:call-template name="encode-as-nc-name">
  3898.                         <xsl:with-param name="string" select="concat( 'TAB_', ../@ss:Name)"/>
  3899.                     </xsl:call-template>
  3900.                 </xsl:attribute>
  3901.                 <xsl:attribute name="style:display-name">
  3902.                     <xsl:value-of select="concat( 'PageStyle_', ../@ss:Name)"/>
  3903.                 </xsl:attribute>
  3904.                 <xsl:attribute name="style:page-layout-name">
  3905.                     <xsl:call-template name="encode-as-nc-name">
  3906.                         <xsl:with-param name="string" select="concat( 'pm_', ../@ss:Name)"/>
  3907.                     </xsl:call-template>
  3908.                 </xsl:attribute>
  3909.                 <xsl:choose>
  3910.                     <xsl:when test="x:PageSetup/x:Header/@x:Data">
  3911.                         <style:header>
  3912.                             <xsl:call-template name="translate-header-footer">
  3913.                                 <xsl:with-param name="content" select="x:PageSetup/x:Header/@x:Data"/>
  3914.                                 <xsl:with-param name="style-name-header" select="concat(../@ss:Name, substring(name(x:PageSetup/x:Header),1,1))"/>
  3915.                             </xsl:call-template>
  3916.                         </style:header>
  3917.                     </xsl:when>
  3918.                     <xsl:otherwise>
  3919.                         <style:header style:display="false"/>
  3920.                     </xsl:otherwise>
  3921.                 </xsl:choose>
  3922.                 <xsl:choose>
  3923.                     <xsl:when test="x:PageSetup/x:Footer/@x:Data">
  3924.                         <style:footer>
  3925.                             <xsl:call-template name="translate-header-footer">
  3926.                                 <xsl:with-param name="content" select="x:PageSetup/x:Footer/@x:Data"/>
  3927.                                 <xsl:with-param name="style-name-header" select="concat(../@ss:Name, substring(name(x:PageSetup/x:Footer),1,1))"/>
  3928.                             </xsl:call-template>
  3929.                         </style:footer>
  3930.                     </xsl:when>
  3931.                     <xsl:otherwise>
  3932.                         <style:footer style:display="false"/>
  3933.                     </xsl:otherwise>
  3934.                 </xsl:choose>
  3935.             </xsl:element>
  3936.         </xsl:for-each>
  3937.     </xsl:template>
  3938.     <xsl:template name="translate-header-footer">
  3939.         <xsl:param name="content"/>
  3940.         <xsl:param name="style-name-header"/>
  3941.         <style:region-left>
  3942.             <text:p>
  3943.                 <xsl:variable name="left-content">
  3944.                     <xsl:call-template name="get-pos-content">
  3945.                         <xsl:with-param name="content" select="$content"/>
  3946.                         <xsl:with-param name="pos" select="'left'"/>
  3947.                     </xsl:call-template>
  3948.                 </xsl:variable>
  3949.                 <xsl:call-template name="locate-header-footer-data">
  3950.                     <xsl:with-param name="header-footer-data" select="$left-content"/>
  3951.                     <xsl:with-param name="style-name-header" select="concat($style-name-header,'L')"/>
  3952.                     <xsl:with-param name="index" select="0"/>
  3953.                     <xsl:with-param name="current-pos" select="1"/>
  3954.                 </xsl:call-template>
  3955.             </text:p>
  3956.         </style:region-left>
  3957.         <style:region-center>
  3958.             <text:p>
  3959.                 <xsl:variable name="center-content">
  3960.                     <xsl:call-template name="get-pos-content">
  3961.                         <xsl:with-param name="content" select="$content"/>
  3962.                         <xsl:with-param name="pos" select="'center'"/>
  3963.                     </xsl:call-template>
  3964.                 </xsl:variable>
  3965.                 <xsl:call-template name="locate-header-footer-data">
  3966.                     <xsl:with-param name="header-footer-data" select="$center-content"/>
  3967.                     <xsl:with-param name="style-name-header" select="concat($style-name-header,'C')"/>
  3968.                     <xsl:with-param name="index" select="0"/>
  3969.                     <xsl:with-param name="current-pos" select="1"/>
  3970.                 </xsl:call-template>
  3971.             </text:p>
  3972.         </style:region-center>
  3973.         <style:region-right>
  3974.             <text:p>
  3975.                 <xsl:variable name="right-content">
  3976.                     <xsl:call-template name="get-pos-content">
  3977.                         <xsl:with-param name="content" select="$content"/>
  3978.                         <xsl:with-param name="pos" select="'right'"/>
  3979.                     </xsl:call-template>
  3980.                 </xsl:variable>
  3981.                 <xsl:call-template name="locate-header-footer-data">
  3982.                     <xsl:with-param name="header-footer-data" select="$right-content"/>
  3983.                     <xsl:with-param name="style-name-header" select="concat($style-name-header,'R')"/>
  3984.                     <xsl:with-param name="index" select="0"/>
  3985.                     <xsl:with-param name="current-pos" select="1"/>
  3986.                 </xsl:call-template>
  3987.             </text:p>
  3988.         </style:region-right>
  3989.     </xsl:template>
  3990.     <xsl:template name="locate-header-footer-data">
  3991.         <xsl:param name="header-footer-data"/>
  3992.         <xsl:param name="style-name-header"/>
  3993.         <xsl:param name="index"/>
  3994.         <xsl:param name="current-pos"/>
  3995.         <xsl:variable name="current-style-data">
  3996.             <xsl:value-of select="substring($header-footer-data,$current-pos)"/>
  3997.         </xsl:variable>
  3998.         <xsl:choose>
  3999.             <xsl:when test="starts-with($current-style-data,'&X') or starts-with($current-style-data,'&Y') or starts-with($current-style-data,'&S') or starts-with($current-style-data,'&U') or starts-with($current-style-data,'&E') or starts-with($current-style-data,'&B')">
  4000.                 <xsl:call-template name="locate-header-footer-data">
  4001.                     <xsl:with-param name="header-footer-data" select="$header-footer-data"/>
  4002.                     <xsl:with-param name="style-name-header" select="$style-name-header"/>
  4003.                     <xsl:with-param name="index" select="$index"/>
  4004.                     <xsl:with-param name="current-pos" select="$current-pos+2"/>
  4005.                 </xsl:call-template>
  4006.             </xsl:when>
  4007.             <xsl:when test="starts-with($current-style-data,'&0') or starts-with($current-style-data,'&1') or starts-with($current-style-data,'&2') or starts-with($current-style-data,'&3') or starts-with($current-style-data,'&4') or starts-with($current-style-data,'&5') or starts-with($current-style-data,'&6') or starts-with($current-style-data,'&7') or starts-with($current-style-data,'&8') or starts-with($current-style-data,'&9')">
  4008.                 <xsl:variable name="font-size-length">
  4009.                     <xsl:call-template name="get-digit-length">
  4010.                         <xsl:with-param name="complexive-string" select="substring-after($current-style-data,'&')"/>
  4011.                     </xsl:call-template>
  4012.                 </xsl:variable>
  4013.                 <xsl:call-template name="locate-header-footer-data">
  4014.                     <xsl:with-param name="header-footer-data" select="$header-footer-data"/>
  4015.                     <xsl:with-param name="style-name-header" select="$style-name-header"/>
  4016.                     <xsl:with-param name="index" select="$index"/>
  4017.                     <xsl:with-param name="current-pos" select="$current-pos+1+$font-size-length"/>
  4018.                 </xsl:call-template>
  4019.             </xsl:when>
  4020.             <xsl:when test="starts-with($current-style-data,'&"')">
  4021.                 <xsl:call-template name="locate-header-footer-data">
  4022.                     <xsl:with-param name="header-footer-data" select="$header-footer-data"/>
  4023.                     <xsl:with-param name="style-name-header" select="$style-name-header"/>
  4024.                     <xsl:with-param name="index" select="$index"/>
  4025.                     <xsl:with-param name="current-pos" select="string-length(substring-before(substring($header-footer-data,$current-pos+2),'"'))+$current-pos+3"/>
  4026.                 </xsl:call-template>
  4027.             </xsl:when>
  4028.             <xsl:otherwise>
  4029.                 <xsl:variable name="current-content-last-pos">
  4030.                     <xsl:call-template name="get-current-content-last-pos">
  4031.                         <xsl:with-param name="style-data" select="$header-footer-data"/>
  4032.                         <xsl:with-param name="current-pos" select="$current-pos"/>
  4033.                     </xsl:call-template>
  4034.                 </xsl:variable>
  4035.                 <xsl:choose>
  4036.                     <xsl:when test="$current-pos > 1">
  4037.                         <text:span text:style-name="{concat($style-name-header,$index)}">
  4038.                             <xsl:call-template name="translate-header-footer-data">
  4039.                                 <xsl:with-param name="header-footer-data" select="substring($header-footer-data,$current-pos,$current-content-last-pos+1-$current-pos)"/>
  4040.                             </xsl:call-template>
  4041.                         </text:span>
  4042.                         <xsl:if test="$current-content-last-pos < string-length($header-footer-data)">
  4043.                             <xsl:call-template name="locate-header-footer-data">
  4044.                                 <xsl:with-param name="header-footer-data" select="$header-footer-data"/>
  4045.                                 <xsl:with-param name="style-name-header" select="$style-name-header"/>
  4046.                                 <xsl:with-param name="index" select="$index+1"/>
  4047.                                 <xsl:with-param name="current-pos" select="$current-content-last-pos+1"/>
  4048.                             </xsl:call-template>
  4049.                         </xsl:if>
  4050.                     </xsl:when>
  4051.                     <xsl:otherwise>
  4052.                         <xsl:call-template name="translate-header-footer-data">
  4053.                             <xsl:with-param name="header-footer-data" select="substring($header-footer-data,$current-pos,$current-content-last-pos+1-$current-pos)"/>
  4054.                         </xsl:call-template>
  4055.                         <xsl:if test="$current-content-last-pos < string-length($header-footer-data)">
  4056.                             <xsl:call-template name="locate-header-footer-data">
  4057.                                 <xsl:with-param name="header-footer-data" select="$header-footer-data"/>
  4058.                                 <xsl:with-param name="style-name-header" select="$style-name-header"/>
  4059.                                 <xsl:with-param name="index" select="$index"/>
  4060.                                 <xsl:with-param name="current-pos" select="$current-content-last-pos+1"/>
  4061.                             </xsl:call-template>
  4062.                         </xsl:if>
  4063.                     </xsl:otherwise>
  4064.                 </xsl:choose>
  4065.             </xsl:otherwise>
  4066.         </xsl:choose>
  4067.     </xsl:template>
  4068.     <xsl:template name="get-current-content-last-pos">
  4069.         <xsl:param name="style-data"/>
  4070.         <xsl:param name="current-pos"/>
  4071.         <xsl:variable name="current-style-data">
  4072.             <xsl:value-of select="substring($style-data,$current-pos)"/>
  4073.         </xsl:variable>
  4074.         <xsl:choose>
  4075.             <xsl:when test="starts-with($current-style-data,'&"') or starts-with($current-style-data,'&X') or starts-with($current-style-data,'&Y') or starts-with($current-style-data,'&S') or starts-with($current-style-data,'&U') or starts-with($current-style-data,'&E') or starts-with($current-style-data,'&B')or starts-with($current-style-data,'&0') or starts-with($current-style-data,'&1') or starts-with($current-style-data,'&2') or starts-with($current-style-data,'&3') or starts-with($current-style-data,'&4') or starts-with($current-style-data,'&5') or starts-with($current-style-data,'&6') or starts-with($current-style-data,'&7') or starts-with($current-style-data,'&8') or starts-with($current-style-data,'&9')">
  4076.                 <xsl:value-of select="$current-pos - 1"/>
  4077.             </xsl:when>
  4078.             <xsl:when test="contains($current-style-data,'&"') or contains($current-style-data,'&X') or contains($current-style-data,'&Y') or contains($current-style-data,'&S') or contains($current-style-data,'&U') or contains($current-style-data,'&E') or contains($current-style-data,'&B')or contains($current-style-data,'&0') or contains($current-style-data,'&1') or contains($current-style-data,'&2') or contains($current-style-data,'&3') or contains($current-style-data,'&4') or contains($current-style-data,'&5') or contains($current-style-data,'&6') or contains($current-style-data,'&7') or contains($current-style-data,'&8') or contains($current-style-data,'&9')">
  4079.                 <xsl:variable name="temp" select="substring-before(substring($current-style-data,2),'&')"/>
  4080.                 <xsl:variable name="next-amp-pos">
  4081.                     <xsl:value-of select="$current-pos+string-length($temp)+1"/>
  4082.                 </xsl:variable>
  4083.                 <xsl:call-template name="get-current-content-last-pos">
  4084.                     <xsl:with-param name="style-data" select="$style-data"/>
  4085.                     <xsl:with-param name="current-pos" select="$next-amp-pos"/>
  4086.                 </xsl:call-template>
  4087.             </xsl:when>
  4088.             <xsl:otherwise>
  4089.                 <xsl:value-of select="string-length($style-data)"/>
  4090.             </xsl:otherwise>
  4091.         </xsl:choose>
  4092.     </xsl:template>
  4093.     <xsl:template name="translate-header-footer-data">
  4094.         <xsl:param name="header-footer-data"/>
  4095.         <xsl:choose>
  4096.             <xsl:when test="contains( $header-footer-data, '&D')">
  4097.                 <xsl:call-template name="translate-header-footer-data">
  4098.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&D')"/>
  4099.                 </xsl:call-template>
  4100.                 <text:date/>
  4101.                 <xsl:call-template name="translate-header-footer-data">
  4102.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&D')"/>
  4103.                 </xsl:call-template>
  4104.             </xsl:when>
  4105.             <xsl:when test="contains( $header-footer-data, '&T')">
  4106.                 <xsl:call-template name="translate-header-footer-data">
  4107.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&T')"/>
  4108.                 </xsl:call-template>
  4109.                 <text:time/>
  4110.                 <xsl:call-template name="translate-header-footer-data">
  4111.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&T')"/>
  4112.                 </xsl:call-template>
  4113.             </xsl:when>
  4114.             <xsl:when test="contains( $header-footer-data, '&P')">
  4115.                 <xsl:call-template name="translate-header-footer-data">
  4116.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&P')"/>
  4117.                 </xsl:call-template>
  4118.                 <text:page-number/>
  4119.                 <xsl:call-template name="translate-header-footer-data">
  4120.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&P')"/>
  4121.                 </xsl:call-template>
  4122.             </xsl:when>
  4123.             <xsl:when test="contains( $header-footer-data, '&N')">
  4124.                 <xsl:call-template name="translate-header-footer-data">
  4125.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&N')"/>
  4126.                 </xsl:call-template>
  4127.                 <text:page-count/>
  4128.                 <xsl:call-template name="translate-header-footer-data">
  4129.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&N')"/>
  4130.                 </xsl:call-template>
  4131.             </xsl:when>
  4132.             <xsl:when test="contains( $header-footer-data, '&A')">
  4133.                 <xsl:call-template name="translate-header-footer-data">
  4134.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&A')"/>
  4135.                 </xsl:call-template>
  4136.                 <text:sheet-name/>
  4137.                 <xsl:call-template name="translate-header-footer-data">
  4138.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&A')"/>
  4139.                 </xsl:call-template>
  4140.             </xsl:when>
  4141.             <xsl:when test="contains( $header-footer-data, '&Z&F')">
  4142.                 <xsl:call-template name="translate-header-footer-data">
  4143.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&Z&F')"/>
  4144.                 </xsl:call-template>
  4145.                 <text:file-name text:display="full"/>
  4146.                 <xsl:call-template name="translate-header-footer-data">
  4147.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&Z&F')"/>
  4148.                 </xsl:call-template>
  4149.             </xsl:when>
  4150.             <xsl:when test="contains( $header-footer-data, '&Z')">
  4151.                 <xsl:call-template name="translate-header-footer-data">
  4152.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&Z')"/>
  4153.                 </xsl:call-template>
  4154.                 <text:file-name text:display="path"/>
  4155.                 <xsl:call-template name="translate-header-footer-data">
  4156.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&Z')"/>
  4157.                 </xsl:call-template>
  4158.             </xsl:when>
  4159.             <xsl:when test="contains( $header-footer-data, '&F')">
  4160.                 <xsl:call-template name="translate-header-footer-data">
  4161.                     <xsl:with-param name="header-footer-data" select="substring-before( $header-footer-data, '&F')"/>
  4162.                 </xsl:call-template>
  4163.                 <text:file-name text:display="name"/>
  4164.                 <xsl:call-template name="translate-header-footer-data">
  4165.                     <xsl:with-param name="header-footer-data" select="substring-after( $header-footer-data, '&F')"/>
  4166.                 </xsl:call-template>
  4167.             </xsl:when>
  4168.             <xsl:otherwise>
  4169.                 <xsl:value-of select="$header-footer-data"/>
  4170.             </xsl:otherwise>
  4171.         </xsl:choose>
  4172.     </xsl:template>
  4173.     <xsl:template name="create-page-master">
  4174.         <xsl:param name="worksheetoptions"/>
  4175.         <xsl:for-each select="$worksheetoptions">
  4176.             <xsl:element name="style:page-layout">
  4177.                 <xsl:attribute name="style:name">
  4178.                     <xsl:call-template name="encode-as-nc-name">
  4179.                         <xsl:with-param name="string" select="concat( 'pm_', ../@ss:Name)"/>
  4180.                     </xsl:call-template>
  4181.                 </xsl:attribute>
  4182.                 <xsl:element name="style:page-layout-properties">
  4183.                     <xsl:choose>
  4184.                         <xsl:when test="x:PageSetup/x:Layout/@x:Orientation = 'Landscape'">
  4185.                             <xsl:attribute name="style:print-orientation">landscape</xsl:attribute>
  4186.                         </xsl:when>
  4187.                         <xsl:otherwise>
  4188.                             <xsl:attribute name="style:print-orientation">portrait</xsl:attribute>
  4189.                         </xsl:otherwise>
  4190.                     </xsl:choose>
  4191.                     <xsl:choose>
  4192.                         <xsl:when test="x:PageSetup/x:Layout/@x:StartPageNumber">
  4193.                             <xsl:attribute name="style:first-page-number">
  4194.                                 <xsl:value-of select="x:PageSetup/x:Layout/@x:StartPageNumber"/>
  4195.                             </xsl:attribute>
  4196.                         </xsl:when>
  4197.                         <xsl:otherwise>
  4198.                             <xsl:attribute name="style:first-page-number">continue</xsl:attribute>
  4199.                         </xsl:otherwise>
  4200.                     </xsl:choose>
  4201.                     <xsl:if test="x:PageSetup/x:PageMargins">
  4202.                         <xsl:attribute name="fo:margin-top">
  4203.                             <xsl:call-template name="convert2cm">
  4204.                                 <xsl:with-param name="value" select="concat(x:PageSetup/x:PageMargins/@x:Top,'pt')"/>
  4205.                             </xsl:call-template>
  4206.                             <xsl:text>cm</xsl:text>
  4207.                         </xsl:attribute>
  4208.                         <xsl:attribute name="fo:margin-bottom">
  4209.                             <xsl:call-template name="convert2cm">
  4210.                                 <xsl:with-param name="value" select="concat(x:PageSetup/x:PageMargins/@x:Bottom,'pt')"/>
  4211.                             </xsl:call-template>
  4212.                             <xsl:text>cm</xsl:text>
  4213.                         </xsl:attribute>
  4214.                         <xsl:attribute name="fo:margin-left">
  4215.                             <xsl:call-template name="convert2cm">
  4216.                                 <xsl:with-param name="value" select="concat(x:PageSetup/x:PageMargins/@x:Left,'pt')"/>
  4217.                             </xsl:call-template>
  4218.                             <xsl:text>cm</xsl:text>
  4219.                         </xsl:attribute>
  4220.                         <xsl:attribute name="fo:margin-right">
  4221.                             <xsl:call-template name="convert2cm">
  4222.                                 <xsl:with-param name="value" select="concat(x:PageSetup/x:PageMargins/@x:Right,'pt')"/>
  4223.                             </xsl:call-template>
  4224.                             <xsl:text>cm</xsl:text>
  4225.                         </xsl:attribute>
  4226.                     </xsl:if>
  4227.                 </xsl:element>
  4228.                 <xsl:if test="x:PageSetup/x:Header">
  4229.                     <style:header-style>
  4230.                         <xsl:element name="style:header-footer-properties">
  4231.                             <xsl:attribute name="fo:min-height">0.75cm</xsl:attribute>
  4232.                             <xsl:choose>
  4233.                                 <xsl:when test="x:PageSetup/x:Header/@x:Margin">
  4234.                                     <xsl:attribute name="fo:margin-bottom">
  4235.                                         <xsl:call-template name="convert2cm">
  4236.                                             <xsl:with-param name="value" select="concat(x:PageSetup/x:Header/@x:Margin,'pt')"/>
  4237.                                         </xsl:call-template>
  4238.                                         <xsl:text>cm</xsl:text>
  4239.                                     </xsl:attribute>
  4240.                                 </xsl:when>
  4241.                                 <xsl:otherwise>
  4242.                                     <xsl:attribute name="fo:margin-bottom">0.25cm</xsl:attribute>
  4243.                                 </xsl:otherwise>
  4244.                             </xsl:choose>
  4245.                         </xsl:element>
  4246.                     </style:header-style>
  4247.                 </xsl:if>
  4248.                 <xsl:if test="x:PageSetup/x:Footer">
  4249.                     <style:footer-style>
  4250.                         <xsl:element name="style:header-footer-properties">
  4251.                             <xsl:attribute name="fo:min-height">0.75cm</xsl:attribute>
  4252.                             <xsl:choose>
  4253.                                 <xsl:when test="x:PageSetup/x:Footer/@x:Margin">
  4254.                                     <xsl:attribute name="fo:margin-top">
  4255.                                         <xsl:call-template name="convert2cm">
  4256.                                             <xsl:with-param name="value" select="concat(x:PageSetup/x:Footer/@x:Margin,'pt')"/>
  4257.                                         </xsl:call-template>
  4258.                                         <xsl:text>cm</xsl:text>
  4259.                                     </xsl:attribute>
  4260.                                 </xsl:when>
  4261.                                 <xsl:otherwise>
  4262.                                     <xsl:attribute name="fo:margin-top">0.25cm</xsl:attribute>
  4263.                                 </xsl:otherwise>
  4264.                             </xsl:choose>
  4265.                         </xsl:element>
  4266.                     </style:footer-style>
  4267.                 </xsl:if>
  4268.             </xsl:element>
  4269.         </xsl:for-each>
  4270.     </xsl:template>
  4271.     <xsl:template match="ss:Style" name="style-style-content" mode="style-style-content">
  4272.         <xsl:element name="style:table-cell-properties">
  4273.             <xsl:if test="ss:Alignment">
  4274.                 <xsl:if test="ss:Alignment/@ss:Vertical">
  4275.                     <xsl:variable name="vertical-align">
  4276.                         <xsl:choose>
  4277.                             <xsl:when test="ss:Alignment/@ss:Vertical = 'Top'">top</xsl:when>
  4278.                             <xsl:when test="ss:Alignment/@ss:Vertical = 'Center'">middle</xsl:when>
  4279.                             <xsl:when test="ss:Alignment/@ss:Vertical = 'Bottom'">bottom</xsl:when>
  4280.                             <xsl:when test="ss:Alignment/@ss:Vertical = 'Automatic'">middle</xsl:when>
  4281.                             <!-- actually for vertical writen characters, not supported by StarOffice/OpenOffice now yet -->
  4282.                             <xsl:otherwise>middle</xsl:otherwise>
  4283.                         </xsl:choose>
  4284.                     </xsl:variable>
  4285.                     <xsl:attribute name="style:vertical-align">
  4286.                         <xsl:value-of select="$vertical-align"/>
  4287.                     </xsl:attribute>
  4288.                 </xsl:if>
  4289.                 <xsl:if test="ss:Alignment/@ss:WrapText = '1'">
  4290.                     <xsl:attribute name="fo:wrap-option">wrap</xsl:attribute>
  4291.                 </xsl:if>
  4292.                 <xsl:if test="ss:Alignment/@ss:Indent">
  4293.                     <xsl:attribute name="fo:padding-left"><!-- Indent is ten times of a point -->
  4294.                         <xsl:variable name="indent" select="ss:Alignment/@ss:Indent * 10"/>
  4295.                         <xsl:call-template name="convert2cm">
  4296.                             <xsl:with-param name="value" select="concat($indent,'pt')"/>
  4297.                         </xsl:call-template>
  4298.                         <xsl:text>cm</xsl:text>
  4299.                     </xsl:attribute>
  4300.                 </xsl:if>
  4301.                 <xsl:if test="ss:Alignment/@ss:Rotate">
  4302.                     <xsl:attribute name="style:rotation-angle">
  4303.                         <xsl:choose>
  4304.                             <xsl:when test="ss:Alignment/@ss:Rotate < 0">
  4305.                                 <xsl:value-of select="360 + ss:Alignment/@ss:Rotate"/>
  4306.                             </xsl:when>
  4307.                             <xsl:otherwise>
  4308.                                 <xsl:value-of select="ss:Alignment/@ss:Rotate"/>
  4309.                             </xsl:otherwise>
  4310.                         </xsl:choose>
  4311.                     </xsl:attribute>
  4312.                     <xsl:attribute name="style:rotation-align">none</xsl:attribute>
  4313.                 </xsl:if>
  4314.                 <xsl:if test="ss:Alignment/@ss:VerticalText = '1'">
  4315.                     <xsl:attribute name="style:direction">ttb</xsl:attribute>
  4316.                     <!-- The horizontal align default for vertical text in Excel is 'center' -->
  4317.                     <xsl:if test="not(ss:Alignment/@ss:Horizontal)">
  4318.                         <!-- OASIS XML removal
  4319.                         <xsl:attribute name="fo:text-align">center</xsl:attribute>-->
  4320.                         <xsl:attribute name="style:text-align-source">fix</xsl:attribute>
  4321.                     </xsl:if>
  4322.                 </xsl:if>
  4323.             </xsl:if>
  4324.             <xsl:if test="ss:Borders">
  4325.                 <xsl:if test="ss:Borders/ss:Border">
  4326.                     <xsl:apply-templates select="ss:Borders/ss:Border"/>
  4327.                 </xsl:if>
  4328.             </xsl:if>
  4329.             <xsl:apply-templates select="ss:Interior" mode="style-style-content"/>
  4330.             <xsl:if test="ss:Protection">
  4331.                 <xsl:choose>
  4332.                     <xsl:when test="ss:Protection/@ss:Protected = '0'">
  4333.                         <xsl:choose>
  4334.                             <xsl:when test="ss:Protection/@ss:HideFormula = '1'">
  4335.                                 <xsl:attribute name="style:cell-protect">hidden-and-protected</xsl:attribute>
  4336.                             </xsl:when>
  4337.                             <xsl:otherwise>
  4338.                                 <xsl:attribute name="style:cell-protect">none</xsl:attribute>
  4339.                             </xsl:otherwise>
  4340.                         </xsl:choose>
  4341.                     </xsl:when>
  4342.                     <xsl:otherwise>
  4343.                         <xsl:choose>
  4344.                             <xsl:when test="ss:Protection/@x:HideFormula = '1'">
  4345.                                 <xsl:attribute name="style:cell-protect">protected formula-hidden</xsl:attribute>
  4346.                             </xsl:when>
  4347.                             <xsl:otherwise>
  4348.                                 <xsl:attribute name="style:cell-protect">none</xsl:attribute>
  4349.                             </xsl:otherwise>
  4350.                         </xsl:choose>
  4351.                     </xsl:otherwise>
  4352.                 </xsl:choose>
  4353.             </xsl:if>
  4354.             <!-- fix means the horizontal alignment is dependent on ss:Horizontal,
  4355.                  but set on paragaraph properties not cell paragraphs -->
  4356.             <xsl:if test="ss:Alignment/@ss:Horizontal">
  4357.                 <xsl:attribute name="style:text-align-source">fix</xsl:attribute>
  4358.             </xsl:if>
  4359.         </xsl:element>
  4360.         <xsl:choose>
  4361.             <xsl:when test="ss:Alignment/@ss:Horizontal">
  4362.                 <xsl:element name="style:paragraph-properties">
  4363.                     <xsl:variable name="text-align">
  4364.                         <xsl:choose>
  4365.                             <xsl:when test="ss:Alignment/@ss:Horizontal = 'Left'">start</xsl:when>
  4366.                             <xsl:when test="ss:Alignment/@ss:Horizontal = 'Center'">center</xsl:when>
  4367.                             <xsl:when test="ss:Alignment/@ss:Horizontal = 'Right'">end</xsl:when>
  4368.                             <xsl:when test="ss:Alignment/@ss:Horizontal = 'Justify'">justify</xsl:when>
  4369.                             <!-- many other text-align not supported yet -->
  4370.                             <xsl:otherwise>start</xsl:otherwise>
  4371.                         </xsl:choose>
  4372.                     </xsl:variable>
  4373.                     <xsl:attribute name="fo:text-align">
  4374.                         <xsl:value-of select="$text-align"/>
  4375.                     </xsl:attribute>
  4376.                 </xsl:element>
  4377.             </xsl:when>
  4378.             <xsl:otherwise>
  4379.                 <!-- The horizontal align default for vertical text in Excel is 'center' -->
  4380.                 <xsl:element name="style:paragraph-properties">
  4381.                     <xsl:if test="ss:Alignment/@ss:VerticalText = '1'">
  4382.                         <xsl:attribute name="fo:text-align">center</xsl:attribute>
  4383.                     </xsl:if>
  4384.                 </xsl:element>
  4385.             </xsl:otherwise>
  4386.         </xsl:choose>
  4387.         <xsl:if test="ss:Font">
  4388.             <xsl:element name="style:text-properties">
  4389.                 <xsl:choose>
  4390.                     <xsl:when test="ss:Font/@ss:FontName">
  4391.                         <xsl:attribute name="style:font-name">
  4392.                             <xsl:value-of select="ss:Font/@ss:FontName"/>
  4393.                         </xsl:attribute>
  4394.                         <xsl:attribute name="style:font-name-asian">
  4395.                             <xsl:value-of select="ss:Font/@ss:FontName"/>
  4396.                         </xsl:attribute>
  4397.                         <xsl:attribute name="style:font-name-complex">
  4398.                             <xsl:value-of select="ss:Font/@ss:FontName"/>
  4399.                         </xsl:attribute>
  4400.                     </xsl:when>
  4401.                     <xsl:otherwise>
  4402.                         <xsl:attribute name="style:font-name">Arial</xsl:attribute>
  4403.                     </xsl:otherwise>
  4404.                 </xsl:choose>
  4405.                 <!-- "ss:Font/@x:Family" is useless here, so can't map to "svg:font-family" attribute -->
  4406.                 <xsl:if test="ss:Font/@ss:Bold = '1'">
  4407.                     <xsl:attribute name="fo:font-weight">bold</xsl:attribute>
  4408.                     <xsl:attribute name="style:font-weight-asian">bold</xsl:attribute>
  4409.                     <xsl:attribute name="style:font-weight-complex">bold</xsl:attribute>
  4410.                 </xsl:if>
  4411.                 <xsl:choose>
  4412.                     <xsl:when test="ss:Font/@ss:Color">
  4413.                         <xsl:attribute name="fo:color">
  4414.                             <xsl:value-of select="ss:Font/@ss:Color"/>
  4415.                         </xsl:attribute>
  4416.                     </xsl:when>
  4417.                     <xsl:otherwise>
  4418.                         <xsl:attribute name="style:use-window-font-color">true</xsl:attribute>
  4419.                     </xsl:otherwise>
  4420.                 </xsl:choose>
  4421.                 <xsl:if test="ss:Font/@ss:Italic = '1'">
  4422.                     <!-- omit font-style oblique -->
  4423.                     <xsl:attribute name="fo:font-style">italic</xsl:attribute>
  4424.                     <xsl:attribute name="style:font-style-asian">italic</xsl:attribute>
  4425.                     <xsl:attribute name="style:font-style-complex">italic</xsl:attribute>
  4426.                 </xsl:if>
  4427.                 <xsl:choose>
  4428.                     <xsl:when test="ss:Font/@ss:Size">
  4429.                         <xsl:attribute name="fo:font-size">
  4430.                             <xsl:value-of select="concat( ss:Font/@ss:Size, 'pt')"/>
  4431.                         </xsl:attribute>
  4432.                         <xsl:attribute name="style:font-size-asian">
  4433.                             <xsl:value-of select="concat( ss:Font/@ss:Size, 'pt')"/>
  4434.                         </xsl:attribute>
  4435.                         <xsl:attribute name="style:font-size-complex">
  4436.                             <xsl:value-of select="concat( ss:Font/@ss:Size, 'pt')"/>
  4437.                         </xsl:attribute>
  4438.                     </xsl:when>
  4439.                     <xsl:otherwise>
  4440.                         <xsl:attribute name="fo:font-size">10pt</xsl:attribute>
  4441.                         <xsl:attribute name="style:font-size-asian">10pt</xsl:attribute>
  4442.                         <xsl:attribute name="style:font-size-complex">10pt</xsl:attribute>
  4443.                     </xsl:otherwise>
  4444.                 </xsl:choose>
  4445.                 <xsl:if test="ss:Font/@ss:Outline = '1'">
  4446.                     <xsl:attribute name="style:text-outline">true</xsl:attribute>
  4447.                 </xsl:if>
  4448.                 <xsl:if test="ss:Font/@ss:Shadow = '1'">
  4449.                     <!-- Not in DTD nor in docu <xsl:attribute name="style:text-shadow">shadow</xsl:attribute> -->
  4450.                     <xsl:attribute name="fo:text-shadow">1pt 1pt</xsl:attribute>
  4451.                 </xsl:if>
  4452.                 <xsl:if test="ss:Font/@ss:StrikeThrough = '1'">
  4453.                     <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  4454.                 </xsl:if>
  4455.                 <xsl:if test="ss:Font/@ss:Underline">
  4456.                     <xsl:choose>
  4457.                         <xsl:when test="ss:Font/@ss:Underline = 'None'">
  4458.                             <xsl:attribute name="style:text-underline-type">none</xsl:attribute>
  4459.                         </xsl:when>
  4460.                         <xsl:when test="ss:Font/@ss:Underline = 'Single'">
  4461.                             <xsl:attribute name="style:text-underline-type">single</xsl:attribute>
  4462.                         </xsl:when>
  4463.                         <xsl:when test="ss:Font/@ss:Underline = 'Double'">
  4464.                             <xsl:attribute name="style:text-underline-type">double</xsl:attribute>
  4465.                         </xsl:when>
  4466.                         <xsl:when test="ss:Font/@ss:Underline = 'SingleAccounting'">
  4467.                             <xsl:attribute name="style:text-underline-type">single</xsl:attribute>"</xsl:when>
  4468.                         <xsl:when test="ss:Font/@ss:Underline = 'DoubleAccounting'">
  4469.                             <xsl:attribute name="style:text-underline-type">double</xsl:attribute>
  4470.                         </xsl:when>
  4471.                         <xsl:otherwise>
  4472.                             <xsl:attribute name="style:text-underline-type">none</xsl:attribute>
  4473.                         </xsl:otherwise>
  4474.                     </xsl:choose>
  4475.                 </xsl:if>
  4476.                 <xsl:if test="ss:Font/@x:Charset">
  4477.                     <!-- quite unclear till now, -->
  4478.                     <xsl:attribute name="style:font-charset">x-symbol</xsl:attribute>
  4479.                 </xsl:if>
  4480.             </xsl:element>
  4481.         </xsl:if>
  4482.     </xsl:template>
  4483.  
  4484.     <xsl:template match="ss:Interior" mode="style-style-content">
  4485.         <xsl:choose>
  4486.             <xsl:when test="@ss:Pattern = 'Solid'">
  4487.                 <xsl:if test="@ss:Color">
  4488.                     <xsl:attribute name="fo:background-color">
  4489.                         <xsl:value-of select="@ss:Color"/>
  4490.                     </xsl:attribute>
  4491.                 </xsl:if>
  4492.             </xsl:when>
  4493.             <xsl:otherwise>
  4494.                 <xsl:if test="@ss:PatternColor">
  4495.                     <xsl:variable name="pattern-value">
  4496.                         <xsl:call-template name="cell-pattern-color">
  4497.                             <xsl:with-param name="pattern" select="concat('0.',substring-after(@ss:Pattern,'y'))"/>
  4498.                             <xsl:with-param name="color-value" select="@ss:Color"/>
  4499.                             <xsl:with-param name="pattern-color-value" select="@ss:PatternColor"/>
  4500.                         </xsl:call-template>
  4501.                     </xsl:variable>
  4502.                     <xsl:attribute name="fo:background-color">
  4503.                         <xsl:value-of select="$pattern-value"/>
  4504.                     </xsl:attribute>
  4505.                 </xsl:if>
  4506.             </xsl:otherwise>
  4507.         </xsl:choose>
  4508.     </xsl:template>
  4509.  
  4510.  
  4511.     <xsl:template match="ss:Style">
  4512.         <!-- style:default-style is meant for application defaults
  4513.         <xsl:when test="@ss:ID = 'Default'">
  4514.             <xsl:element name="style:default-style">
  4515.                 <xsl:call-template name="style-style-content" />
  4516.             </xsl:element>
  4517.         </xsl:when> -->
  4518.         <xsl:element name="style:style">
  4519.             <xsl:attribute name="style:name">
  4520.                 <xsl:value-of select="@ss:ID"/>
  4521.             </xsl:attribute>
  4522.             <xsl:apply-templates select="@ss:Name" />
  4523.             <xsl:choose>
  4524.                 <xsl:when test="@ss:Parent">
  4525.                     <xsl:attribute name="style:parent-style-name">
  4526.                         <xsl:value-of select="@ss:Parent"/>
  4527.                     </xsl:attribute>
  4528.                 </xsl:when>
  4529.                 <!-- no parent, but automatic style are automatically inheriting from a style called 'Default'
  4530.                     not necessary named style -->
  4531.                 <xsl:when test="not(key('Style', @ss:ID)/@ss:Name)">
  4532.                     <xsl:attribute name="style:parent-style-name">
  4533.                         <xsl:text>Default</xsl:text>
  4534.                     </xsl:attribute>
  4535.                 </xsl:when>
  4536.             </xsl:choose>
  4537.             <xsl:if test="ss:NumberFormat/@ss:Format">
  4538.                 <xsl:attribute name="style:data-style-name">
  4539.                     <xsl:value-of select="concat( @ss:ID, 'F')"/>
  4540.                 </xsl:attribute>
  4541.             </xsl:if>
  4542.             <xsl:attribute name="style:family">table-cell</xsl:attribute>
  4543.             <xsl:call-template name="style-style-content"/>
  4544.         </xsl:element>
  4545.     </xsl:template>
  4546.     <xsl:template name="cell-pattern-color">
  4547.         <!-- generates a new color from cell-pattern-color -->
  4548.         <xsl:param name="pattern"/>
  4549.         <xsl:param name="color-value"/>
  4550.         <xsl:param name="pattern-color-value"/>
  4551.         <xsl:variable name="rev-pattern" select="1 - $pattern"/>
  4552.         <xsl:variable name="color-R-value">
  4553.             <xsl:call-template name="hex2decimal">
  4554.                 <xsl:with-param name="hex-number" select="substring($color-value,2,2)"/>
  4555.                 <xsl:with-param name="index" select="1"/>
  4556.                 <xsl:with-param name="str-length" select="2"/>
  4557.                 <xsl:with-param name="last-value" select="0"/>
  4558.             </xsl:call-template>
  4559.         </xsl:variable>
  4560.         <xsl:variable name="color-G-value">
  4561.             <xsl:call-template name="hex2decimal">
  4562.                 <xsl:with-param name="hex-number" select="substring($color-value,4,2)"/>
  4563.                 <xsl:with-param name="index" select="1"/>
  4564.                 <xsl:with-param name="str-length" select="2"/>
  4565.                 <xsl:with-param name="last-value" select="0"/>
  4566.             </xsl:call-template>
  4567.         </xsl:variable>
  4568.         <xsl:variable name="color-B-value">
  4569.             <xsl:call-template name="hex2decimal">
  4570.                 <xsl:with-param name="hex-number" select="substring($color-value,6,2)"/>
  4571.                 <xsl:with-param name="index" select="1"/>
  4572.                 <xsl:with-param name="str-length" select="2"/>
  4573.                 <xsl:with-param name="last-value" select="0"/>
  4574.             </xsl:call-template>
  4575.         </xsl:variable>
  4576.         <xsl:variable name="pattern-R-value">
  4577.             <xsl:call-template name="hex2decimal">
  4578.                 <xsl:with-param name="hex-number" select="substring($pattern-color-value,2,2)"/>
  4579.                 <xsl:with-param name="index" select="1"/>
  4580.                 <xsl:with-param name="str-length" select="2"/>
  4581.                 <xsl:with-param name="last-value" select="0"/>
  4582.             </xsl:call-template>
  4583.         </xsl:variable>
  4584.         <xsl:variable name="pattern-G-value">
  4585.             <xsl:call-template name="hex2decimal">
  4586.                 <xsl:with-param name="hex-number" select="substring($pattern-color-value,4,2)"/>
  4587.                 <xsl:with-param name="index" select="1"/>
  4588.                 <xsl:with-param name="str-length" select="2"/>
  4589.                 <xsl:with-param name="last-value" select="0"/>
  4590.             </xsl:call-template>
  4591.         </xsl:variable>
  4592.         <xsl:variable name="pattern-B-value">
  4593.             <xsl:call-template name="hex2decimal">
  4594.                 <xsl:with-param name="hex-number" select="substring($pattern-color-value,6,2)"/>
  4595.                 <xsl:with-param name="index" select="1"/>
  4596.                 <xsl:with-param name="str-length" select="2"/>
  4597.                 <xsl:with-param name="last-value" select="0"/>
  4598.             </xsl:call-template>
  4599.         </xsl:variable>
  4600.         <xsl:variable name="R-value">
  4601.             <xsl:variable name="combined-R-value">
  4602.                 <xsl:call-template name="decimal2hex">
  4603.                     <xsl:with-param name="dec-number" select="floor($color-R-value * $rev-pattern + $pattern-R-value * $pattern)"/>
  4604.                     <xsl:with-param name="last-value" select="'H'"/>
  4605.                 </xsl:call-template>
  4606.             </xsl:variable>
  4607.             <xsl:choose>
  4608.                 <xsl:when test="string-length($combined-R-value) = 1">
  4609.                     <xsl:value-of select="concat('0',$combined-R-value)"/>
  4610.                 </xsl:when>
  4611.                 <xsl:otherwise>
  4612.                     <xsl:value-of select="$combined-R-value"/>
  4613.                 </xsl:otherwise>
  4614.             </xsl:choose>
  4615.         </xsl:variable>
  4616.         <xsl:variable name="G-value">
  4617.             <xsl:variable name="combined-G-value">
  4618.                 <xsl:call-template name="decimal2hex">
  4619.                     <xsl:with-param name="dec-number" select="floor($color-G-value * $rev-pattern + $pattern-G-value * $pattern)"/>
  4620.                     <xsl:with-param name="last-value" select="'H'"/>
  4621.                 </xsl:call-template>
  4622.             </xsl:variable>
  4623.             <xsl:choose>
  4624.                 <xsl:when test="string-length($combined-G-value) = 1">
  4625.                     <xsl:value-of select="concat('0',$combined-G-value)"/>
  4626.                 </xsl:when>
  4627.                 <xsl:otherwise>
  4628.                     <xsl:value-of select="$combined-G-value"/>
  4629.                 </xsl:otherwise>
  4630.             </xsl:choose>
  4631.         </xsl:variable>
  4632.         <xsl:variable name="B-value">
  4633.             <xsl:variable name="combined-B-value">
  4634.                 <xsl:call-template name="decimal2hex">
  4635.                     <xsl:with-param name="dec-number" select="floor($color-B-value * $rev-pattern + $pattern-B-value * $pattern)"/>
  4636.                     <xsl:with-param name="last-value" select="'H'"/>
  4637.                 </xsl:call-template>
  4638.             </xsl:variable>
  4639.             <xsl:choose>
  4640.                 <xsl:when test="string-length($combined-B-value) = 1">
  4641.                     <xsl:value-of select="concat('0',$combined-B-value)"/>
  4642.                 </xsl:when>
  4643.                 <xsl:otherwise>
  4644.                     <xsl:value-of select="$combined-B-value"/>
  4645.                 </xsl:otherwise>
  4646.             </xsl:choose>
  4647.         </xsl:variable>
  4648.         <xsl:value-of select="concat('#',$R-value,$G-value,$B-value)"/>
  4649.     </xsl:template>
  4650.     <xsl:template name="colorindex2decimal">
  4651.         <xsl:param name="colorindex"/>
  4652.         <xsl:variable name="colorIndexLookup">
  4653.             <xsl:value-of select="$colorindex - 8"/>
  4654.         </xsl:variable>
  4655.         <xsl:variable name="tempColorValue">
  4656.             <xsl:choose>
  4657.                 <!-- Grab the color from the custom color index if it exists... -->
  4658.                 <xsl:when test="/ss:Workbook/o:OfficeDocumentSettings/o:Colors/o:Color/o:Index=$colorIndexLookup">
  4659.                     <xsl:value-of select="substring-after(normalize-space(/ss:Workbook/o:OfficeDocumentSettings/o:Colors/o:Color/o:RGB[/ss:Workbook/o:OfficeDocumentSettings/o:Colors/o:Color/o:Index=$colorIndexLookup]), '#')"/>
  4660.                 </xsl:when >
  4661.                 <xsl:otherwise>
  4662.                     <xsl:choose>
  4663.                         <xsl:when test="$colorindex=8">
  4664.                             <xsl:value-of select="'000000'"/>
  4665.                         </xsl:when>
  4666.                         <xsl:when test="$colorindex=9">
  4667.                             <xsl:value-of select="'FFFFFF'"/>
  4668.                         </xsl:when>
  4669.                         <xsl:when test="$colorindex=10">
  4670.                             <xsl:value-of select="'FF0000'"/>
  4671.                         </xsl:when>
  4672.                         <xsl:when test="$colorindex=11">
  4673.                             <xsl:value-of select="'00FF00'"/>
  4674.                         </xsl:when>
  4675.                         <xsl:when test="$colorindex=12">
  4676.                             <xsl:value-of select="'0000FF'"/>
  4677.                         </xsl:when>
  4678.                         <xsl:when test="$colorindex=13">
  4679.                             <xsl:value-of select="'FFFF00'"/>
  4680.                         </xsl:when>
  4681.                         <xsl:when test="$colorindex=14">
  4682.                             <xsl:value-of select="'FF00FF'"/>
  4683.                         </xsl:when>
  4684.                         <xsl:when test="$colorindex=15">
  4685.                             <xsl:value-of select="'00FFFF'"/>
  4686.                         </xsl:when>
  4687.                         <xsl:when test="$colorindex=16">
  4688.                             <xsl:value-of select="'800000'"/>
  4689.                         </xsl:when>
  4690.                         <xsl:when test="$colorindex=17">
  4691.                             <xsl:value-of select="'008000'"/>
  4692.                         </xsl:when>
  4693.                         <xsl:when test="$colorindex=18">
  4694.                             <xsl:value-of select="'000080'"/>
  4695.                         </xsl:when>
  4696.                         <xsl:when test="$colorindex=19">
  4697.                             <xsl:value-of select="'808000'"/>
  4698.                         </xsl:when>
  4699.                         <xsl:when test="$colorindex=20">
  4700.                             <xsl:value-of select="'800080'"/>
  4701.                         </xsl:when>
  4702.                         <xsl:when test="$colorindex=21">
  4703.                             <xsl:value-of select="'008080'"/>
  4704.                         </xsl:when>
  4705.                         <xsl:when test="$colorindex=22">
  4706.                             <xsl:value-of select="'C0C0C0'"/>
  4707.                         </xsl:when>
  4708.                         <xsl:when test="$colorindex=23">
  4709.                             <xsl:value-of select="'808080'"/>
  4710.                         </xsl:when>
  4711.                         <xsl:when test="$colorindex=24">
  4712.                             <xsl:value-of select="'9999FF'"/>
  4713.                         </xsl:when>
  4714.                         <xsl:when test="$colorindex=25">
  4715.                             <xsl:value-of select="'993366'"/>
  4716.                         </xsl:when>
  4717.                         <xsl:when test="$colorindex=26">
  4718.                             <xsl:value-of select="'FFFFCC'"/>
  4719.                         </xsl:when>
  4720.                         <xsl:when test="$colorindex=27">
  4721.                             <xsl:value-of select="'CCFFFF'"/>
  4722.                         </xsl:when>
  4723.                         <xsl:when test="$colorindex=28">
  4724.                             <xsl:value-of select="'660066'"/>
  4725.                         </xsl:when>
  4726.                         <xsl:when test="$colorindex=29">
  4727.                             <xsl:value-of select="'FF8080'"/>
  4728.                         </xsl:when>
  4729.                         <xsl:when test="$colorindex=30">
  4730.                             <xsl:value-of select="'0066CC'"/>
  4731.                         </xsl:when>
  4732.                         <xsl:when test="$colorindex=31">
  4733.                             <xsl:value-of select="'CCCCFF'"/>
  4734.                         </xsl:when>
  4735.                         <xsl:when test="$colorindex=32">
  4736.                             <xsl:value-of select="'000080'"/>
  4737.                         </xsl:when>
  4738.                         <xsl:when test="$colorindex=33">
  4739.                             <xsl:value-of select="'FF00FF'"/>
  4740.                         </xsl:when>
  4741.                         <xsl:when test="$colorindex=34">
  4742.                             <xsl:value-of select="'FFFF00'"/>
  4743.                         </xsl:when>
  4744.                         <xsl:when test="$colorindex=35">
  4745.                             <xsl:value-of select="'00FFFF'"/>
  4746.                         </xsl:when>
  4747.                         <xsl:when test="$colorindex=36">
  4748.                             <xsl:value-of select="'800080'"/>
  4749.                         </xsl:when>
  4750.                         <xsl:when test="$colorindex=37">
  4751.                             <xsl:value-of select="'800000'"/>
  4752.                         </xsl:when>
  4753.                         <xsl:when test="$colorindex=38">
  4754.                             <xsl:value-of select="'008080'"/>
  4755.                         </xsl:when>
  4756.                         <xsl:when test="$colorindex=39">
  4757.                             <xsl:value-of select="'0000FF'"/>
  4758.                         </xsl:when>
  4759.                         <xsl:when test="$colorindex=40">
  4760.                             <xsl:value-of select="'00CCFF'"/>
  4761.                         </xsl:when>
  4762.                         <xsl:when test="$colorindex=41">
  4763.                             <xsl:value-of select="'CCFFFF'"/>
  4764.                         </xsl:when>
  4765.                         <xsl:when test="$colorindex=42">
  4766.                             <xsl:value-of select="'CCFFCC'"/>
  4767.                         </xsl:when>
  4768.                         <xsl:when test="$colorindex=43">
  4769.                             <xsl:value-of select="'FFFF99'"/>
  4770.                         </xsl:when>
  4771.                         <xsl:when test="$colorindex=44">
  4772.                             <xsl:value-of select="'99CCFF'"/>
  4773.                         </xsl:when>
  4774.                         <xsl:when test="$colorindex=45">
  4775.                             <xsl:value-of select="'FF99CC'"/>
  4776.                         </xsl:when>
  4777.                         <xsl:when test="$colorindex=46">
  4778.                             <xsl:value-of select="'CC99FF'"/>
  4779.                         </xsl:when>
  4780.                         <xsl:when test="$colorindex=47">
  4781.                             <xsl:value-of select="'FFCC99'"/>
  4782.                         </xsl:when>
  4783.                         <xsl:when test="$colorindex=48">
  4784.                             <xsl:value-of select="'3366FF'"/>
  4785.                         </xsl:when>
  4786.                         <xsl:when test="$colorindex=49">
  4787.                             <xsl:value-of select="'33CCCC'"/>
  4788.                         </xsl:when>
  4789.                         <xsl:when test="$colorindex=50">
  4790.                             <xsl:value-of select="'99CC00'"/>
  4791.                         </xsl:when>
  4792.                         <xsl:when test="$colorindex=51">
  4793.                             <xsl:value-of select="'FFCC00'"/>
  4794.                         </xsl:when>
  4795.                         <xsl:when test="$colorindex=52">
  4796.                             <xsl:value-of select="'FF9900'"/>
  4797.                         </xsl:when>
  4798.                         <xsl:when test="$colorindex=53">
  4799.                             <xsl:value-of select="'FF6600'"/>
  4800.                         </xsl:when>
  4801.                         <xsl:when test="$colorindex=54">
  4802.                             <xsl:value-of select="'666699'"/>
  4803.                         </xsl:when>
  4804.                         <xsl:when test="$colorindex=55">
  4805.                             <xsl:value-of select="'969696'"/>
  4806.                         </xsl:when>
  4807.                         <xsl:when test="$colorindex=56">
  4808.                             <xsl:value-of select="'003366'"/>
  4809.                         </xsl:when>
  4810.                         <xsl:when test="$colorindex=57">
  4811.                             <xsl:value-of select="'339966'"/>
  4812.                         </xsl:when>
  4813.                         <xsl:when test="$colorindex=58">
  4814.                             <xsl:value-of select="'003300'"/>
  4815.                         </xsl:when>
  4816.                         <xsl:when test="$colorindex=59">
  4817.                             <xsl:value-of select="'333300'"/>
  4818.                         </xsl:when>
  4819.                         <xsl:when test="$colorindex=60">
  4820.                             <xsl:value-of select="'993300'"/>
  4821.                         </xsl:when>
  4822.                         <xsl:when test="$colorindex=61">
  4823.                             <xsl:value-of select="'993366'"/>
  4824.                         </xsl:when>
  4825.                         <xsl:when test="$colorindex=62">
  4826.                             <xsl:value-of select="'333399'"/>
  4827.                         </xsl:when>
  4828.                         <xsl:when test="$colorindex=63">
  4829.                             <xsl:value-of select="'333333'"/>
  4830.                         </xsl:when>
  4831.                         <xsl:otherwise>
  4832.                             <xsl:value-of select="'NOTFOUND'"/>
  4833.                         </xsl:otherwise>
  4834.                     </xsl:choose>
  4835.                 </xsl:otherwise>
  4836.             </xsl:choose>
  4837.         </xsl:variable>
  4838.         <xsl:variable name="tempColorDecimal">
  4839.             <xsl:choose>
  4840.                     <xsl:when test="not($tempColorValue = 'NOTFOUND')">
  4841.                         <xsl:call-template name="hex2decimal">
  4842.                             <xsl:with-param name="hex-number" select="$tempColorValue"/>
  4843.                             <xsl:with-param name="index" select="1"/>
  4844.                             <xsl:with-param name="str-length" select="6"/>
  4845.                             <xsl:with-param name="last-value" select="0"/>
  4846.                         </xsl:call-template>
  4847.                     </xsl:when>
  4848.                     <xsl:otherwise>
  4849.                         <xsl:value-of select="4294967295"/>
  4850.                     </xsl:otherwise>
  4851.             </xsl:choose>
  4852.         </xsl:variable>
  4853.         <xsl:value-of select="$tempColorDecimal"/>
  4854.     </xsl:template>
  4855.     <xsl:template name="hex2decimal">
  4856.         <!-- transforms a hex number to a decimal number.parses the string from left to right -->
  4857.         <xsl:param name="hex-number"/>
  4858.         <xsl:param name="index"/>
  4859.         <xsl:param name="str-length"/>
  4860.         <xsl:param name="last-value"/>
  4861.         <xsl:variable name="dec-char">
  4862.             <xsl:call-template name="hexNumber2dec">
  4863.                 <xsl:with-param name="hex-value" select="substring($hex-number, $index ,1)"/>
  4864.             </xsl:call-template>
  4865.         </xsl:variable>
  4866.         <xsl:variable name="current-value" select="$last-value * 16 + $dec-char"/>
  4867.         <xsl:if test="$index < $str-length">
  4868.             <xsl:call-template name="hex2decimal">
  4869.                 <xsl:with-param name="hex-number" select="$hex-number"/>
  4870.                 <xsl:with-param name="index" select="$index + 1"/>
  4871.                 <xsl:with-param name="str-length" select="$str-length"/>
  4872.                 <xsl:with-param name="last-value" select="$current-value"/>
  4873.             </xsl:call-template>
  4874.         </xsl:if>
  4875.         <xsl:if test="$index = $str-length">
  4876.             <xsl:value-of select="$current-value"/>
  4877.         </xsl:if>
  4878.     </xsl:template>
  4879.     <xsl:template name="hexNumber2dec">
  4880.         <!-- return a decimal number for a hex character -->
  4881.         <xsl:param name="hex-value"/>
  4882.         <xsl:choose>
  4883.             <xsl:when test="$hex-value = 'A' or ($hex-value = 'a')">
  4884.                 <xsl:value-of select="10"/>
  4885.             </xsl:when>
  4886.             <xsl:when test="$hex-value = 'B' or ($hex-value = 'b')">
  4887.                 <xsl:value-of select="11"/>
  4888.             </xsl:when>
  4889.             <xsl:when test="$hex-value = 'C' or ($hex-value = 'c')">
  4890.                 <xsl:value-of select="12"/>
  4891.             </xsl:when>
  4892.             <xsl:when test="$hex-value = 'D' or ($hex-value = 'd')">
  4893.                 <xsl:value-of select="13"/>
  4894.             </xsl:when>
  4895.             <xsl:when test="$hex-value = 'E' or ($hex-value = 'e')">
  4896.                 <xsl:value-of select="14"/>
  4897.             </xsl:when>
  4898.             <xsl:when test="$hex-value = 'F' or ($hex-value = 'f')">
  4899.                 <xsl:value-of select="15"/>
  4900.             </xsl:when>
  4901.             <xsl:otherwise>
  4902.                 <xsl:value-of select="$hex-value"/>
  4903.             </xsl:otherwise>
  4904.         </xsl:choose>
  4905.     </xsl:template>
  4906.     <xsl:template name="decimal2hex">
  4907.         <!-- transforms a decimal number to a hex number,only for two-bit hex(less than 256 in decimal) currently -->
  4908.         <xsl:param name="dec-number"/>
  4909.         <xsl:param name="last-value"/>
  4910.         <xsl:variable name="current-value">
  4911.             <xsl:call-template name="decNumber2hex">
  4912.                 <xsl:with-param name="dec-value">
  4913.                     <xsl:if test="$dec-number > 15">
  4914.                         <xsl:value-of select="floor($dec-number div 16)"/>
  4915.                     </xsl:if>
  4916.                     <xsl:if test="$dec-number < 16">
  4917.                         <xsl:value-of select="$dec-number"/>
  4918.                     </xsl:if>
  4919.                 </xsl:with-param>
  4920.             </xsl:call-template>
  4921.         </xsl:variable>
  4922.         <xsl:if test="$dec-number > 15">
  4923.             <xsl:call-template name="decimal2hex">
  4924.                 <xsl:with-param name="dec-number" select="$dec-number mod 16"/>
  4925.                 <xsl:with-param name="last-value" select="concat($last-value,$current-value)"/>
  4926.             </xsl:call-template>
  4927.         </xsl:if>
  4928.         <xsl:if test="$dec-number < 16">
  4929.             <xsl:value-of select="substring-after(concat($last-value,$current-value),'H')"/>
  4930.         </xsl:if>
  4931.     </xsl:template>
  4932.     <xsl:template name="decNumber2hex">
  4933.         <!-- return a hex number for a decimal character -->
  4934.         <xsl:param name="dec-value"/>
  4935.         <xsl:choose>
  4936.             <xsl:when test="$dec-value = 10">
  4937.                 <xsl:value-of select="'A'"/>
  4938.             </xsl:when>
  4939.             <xsl:when test="$dec-value = 11">
  4940.                 <xsl:value-of select="'B'"/>
  4941.             </xsl:when>
  4942.             <xsl:when test="$dec-value = 12">
  4943.                 <xsl:value-of select="'C'"/>
  4944.             </xsl:when>
  4945.             <xsl:when test="$dec-value = 13">
  4946.                 <xsl:value-of select="'D'"/>
  4947.             </xsl:when>
  4948.             <xsl:when test="$dec-value = 14">
  4949.                 <xsl:value-of select="'E'"/>
  4950.             </xsl:when>
  4951.             <xsl:when test="$dec-value = 15">
  4952.                 <xsl:value-of select="'F'"/>
  4953.             </xsl:when>
  4954.             <xsl:otherwise>
  4955.                 <xsl:value-of select="$dec-value"/>
  4956.             </xsl:otherwise>
  4957.         </xsl:choose>
  4958.     </xsl:template>
  4959.     <xsl:template match="ss:Border">
  4960.         <xsl:variable name="position">
  4961.             <xsl:choose>
  4962.                 <xsl:when test="@ss:Position = 'Top'">fo:border-top</xsl:when>
  4963.                 <xsl:when test="@ss:Position = 'Bottom'">fo:border-bottom</xsl:when>
  4964.                 <xsl:when test="@ss:Position = 'Left'">fo:border-left</xsl:when>
  4965.                 <xsl:when test="@ss:Position = 'Right'">fo:border-right</xsl:when>
  4966.                 <!-- DiagonalLeft & DiagonalRight are not supported yet, -->
  4967.                 <xsl:otherwise>fo:border-left</xsl:otherwise>
  4968.             </xsl:choose>
  4969.         </xsl:variable>
  4970.         <xsl:variable name="width">
  4971.             <xsl:choose>
  4972.                 <!-- 0: Hairline -->
  4973.                 <xsl:when test="@ss:Weight = '0'">0.002cm</xsl:when>
  4974.                 <!-- 1: Thin -->
  4975.                 <xsl:when test="@ss:Weight = '1'">0.035cm</xsl:when>
  4976.                 <!-- 2: Medium -->
  4977.                 <xsl:when test="@ss:Weight = '2'">0.088cm</xsl:when>
  4978.                 <!-- 3: Thick -->
  4979.                 <xsl:when test="@ss:Weight = '3'">
  4980.                     <xsl:choose>
  4981.                         <xsl:when test="@ss:LineStyle = 'Double'">0.105cm</xsl:when>
  4982.                         <xsl:otherwise>0.141cm</xsl:otherwise>
  4983.                     </xsl:choose>
  4984.                 </xsl:when>
  4985.                 <!-- invalid value, or parameter not exist at all -->
  4986.                 <xsl:otherwise>0.002cm</xsl:otherwise>
  4987.             </xsl:choose>
  4988.         </xsl:variable>
  4989.         <xsl:variable name="linestyle">
  4990.             <xsl:choose>
  4991.                 <xsl:when test="@ss:LineStyle = 'None'">none</xsl:when>
  4992.                 <xsl:when test="@ss:LineStyle = 'Continuous'">solid</xsl:when>
  4993.                 <xsl:when test="@ss:LineStyle = 'Double'">double</xsl:when>
  4994.                 <!-- Dash, Dot, DashDot, DashDotDot, SlantDashDot are not supported yet -->
  4995.                 <xsl:otherwise>solid</xsl:otherwise>
  4996.             </xsl:choose>
  4997.         </xsl:variable>
  4998.         <xsl:variable name="color">
  4999.             <xsl:choose>
  5000.                 <xsl:when test="@ss:Color">
  5001.                     <xsl:value-of select="@ss:Color"/>
  5002.                 </xsl:when>
  5003.                 <!-- default border color is black -->
  5004.                 <xsl:otherwise>#000000</xsl:otherwise>
  5005.             </xsl:choose>
  5006.         </xsl:variable>
  5007.         <xsl:attribute name="{$position}">
  5008.             <xsl:value-of select="concat( $width, ' ', $linestyle, ' ', $color)"/>
  5009.         </xsl:attribute>
  5010.         <xsl:if test="@ss:LineStyle = 'Double'">
  5011.             <xsl:variable name="widthposition">
  5012.                 <xsl:choose>
  5013.                     <xsl:when test="@ss:Position = 'Top'">style:border-line-width-top</xsl:when>
  5014.                     <xsl:when test="@ss:Position = 'Bottom'">style:border-line-width-bottom</xsl:when>
  5015.                     <xsl:when test="@ss:Position = 'Left'">style:border-line-width-left</xsl:when>
  5016.                     <xsl:when test="@ss:Position = 'Right'">style:border-line-width-right</xsl:when>
  5017.                 </xsl:choose>
  5018.             </xsl:variable>
  5019.             <xsl:attribute name="{$widthposition}">0.035cm 0.035cm 0.035cm</xsl:attribute>
  5020.         </xsl:if>
  5021.     </xsl:template>
  5022.     <xsl:template match="ss:Font">
  5023.         <xsl:choose>
  5024.             <xsl:when test="@ss:VerticalAlign = 'Superscript'">
  5025.                 <style:style style:name="{concat(../@ss:ID,'T0')}" style:family="text">
  5026.                     <style:text-properties style:text-position="33% 58%"/>
  5027.                 </style:style>
  5028.             </xsl:when>
  5029.             <xsl:when test="@ss:VerticalAlign = 'Subscript'">
  5030.                 <style:style style:name="{concat(../@ss:ID,'T0')}" style:family="text">
  5031.                     <style:text-properties style:text-position="-33% 58%"/>
  5032.                 </style:style>
  5033.             </xsl:when>
  5034.             <xsl:otherwise/>
  5035.         </xsl:choose>
  5036.     </xsl:template>
  5037.     <xsl:template match="ss:Table">
  5038.         <xsl:variable name="default-column-width">
  5039.             <xsl:choose>
  5040.                 <xsl:when test="@ss:DefaultColumnWidth">
  5041.                     <xsl:call-template name="convert2cm">
  5042.                         <xsl:with-param name="value" select="concat(@ss:DefaultColumnWidth,'pt')"/>
  5043.                     </xsl:call-template>
  5044.                     <xsl:text>cm</xsl:text>
  5045.                 </xsl:when>
  5046.                 <!-- Note: Specify where this value come from.. -->
  5047.                 <xsl:otherwise>2.096cm</xsl:otherwise>
  5048.             </xsl:choose>
  5049.         </xsl:variable>
  5050.         <xsl:variable name="table-pos">
  5051.             <xsl:value-of select="count(../preceding-sibling::ss:Worksheet)+1"/>
  5052.         </xsl:variable>
  5053.         <!-- naming convention the default column style is name co<NumberOfSheet> e.g. co1 for the first sheet -->
  5054.         <style:style style:family="table-column" style:name="{concat('co', $table-pos)}">
  5055.             <style:table-column-properties fo:break-before="auto" style:column-width="{$default-column-width}"/>
  5056.         </style:style>
  5057.         <xsl:choose>
  5058.             <xsl:when test="ss:Column">
  5059.                 <xsl:call-template name="get-column-style-name">
  5060.                     <xsl:with-param name="finishedColumns" select="0"/>
  5061.                     <xsl:with-param name="columnCount" select="count(./ss:Column)"/>
  5062.                     <xsl:with-param name="currentCount" select="1"/>
  5063.                     <xsl:with-param name="table-pos" select="$table-pos"/>
  5064.                     <xsl:with-param name="default-column-width" select="$default-column-width"/>
  5065.                 </xsl:call-template>
  5066.             </xsl:when>
  5067.         </xsl:choose>
  5068.         <xsl:if test="../x:PageBreaks/x:ColBreaks">
  5069.             <style:style style:name="{concat('cob',$table-pos)}" style:family="table-column">
  5070.                 <xsl:element name="style:table-column-properties">
  5071.                     <xsl:attribute name="style:column-width">
  5072.                         <xsl:value-of select="$default-column-width"/>
  5073.                     </xsl:attribute>
  5074.                     <xsl:attribute name="fo:break-before">page</xsl:attribute>
  5075.                 </xsl:element>
  5076.             </style:style>
  5077.         </xsl:if>
  5078.         <xsl:variable name="default-row-height">
  5079.             <xsl:choose>
  5080.                 <xsl:when test="@ss:DefaultRowHeight">
  5081.                     <xsl:call-template name="convert2cm">
  5082.                         <xsl:with-param name="value" select="concat(@ss:DefaultRowHeight,'pt')"/>
  5083.                     </xsl:call-template>
  5084.                     <xsl:text>cm</xsl:text>
  5085.                 </xsl:when>
  5086.                 <!-- Note: This is the default row hight value in spec it is written 255 point, this seems wrong -->
  5087.                 <!-- <xsl:otherwise>0.503cm</xsl:otherwise> -->
  5088.                 <xsl:otherwise>0.45cm</xsl:otherwise>
  5089.             </xsl:choose>
  5090.         </xsl:variable>
  5091.         <style:style style:family="table-row" style:name="{concat('ro', $table-pos)}">
  5092.             <style:table-row-properties style:row-height="{$default-row-height}" style:use-optimal-row-height="false"/>
  5093.         </style:style>
  5094.         <xsl:if test="ss:Row">
  5095.             <xsl:call-template name="get-row-style-name">
  5096.                 <xsl:with-param name="earlierRowNo" select="0"/>
  5097.                 <xsl:with-param name="rowNodeCount" select="count(./ss:Row)"/>
  5098.                 <xsl:with-param name="rowNodeIndex" select="1"/>
  5099.                 <xsl:with-param name="table-pos" select="$table-pos"/>
  5100.                 <xsl:with-param name="default-row-height" select="$default-row-height"/>
  5101.             </xsl:call-template>
  5102.         </xsl:if>
  5103.         <xsl:if test="../x:PageBreaks/x:RowBreaks">
  5104.             <style:style style:name="{concat('rob',$table-pos)}" style:family="table-row">
  5105.                 <xsl:element name="style:table-row-properties">
  5106.                     <xsl:attribute name="style:row-height">
  5107.                         <xsl:value-of select="$default-row-height"/>
  5108.                     </xsl:attribute>
  5109.                     <xsl:attribute name="style:use-optimal-row-height">false</xsl:attribute>
  5110.                     <xsl:attribute name="fo:break-before">page</xsl:attribute>
  5111.                 </xsl:element>
  5112.             </style:style>
  5113.         </xsl:if>
  5114.         <!-- create table-style -->
  5115.         <xsl:element name="style:style">
  5116.             <xsl:attribute name="style:name">
  5117.                 <xsl:value-of select="concat( 'ta', $table-pos)"/>
  5118.             </xsl:attribute>
  5119.             <xsl:attribute name="style:family">table</xsl:attribute>
  5120.             <!-- ss:Name have to be from type 'NCNameChar'      ::=     Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender -->
  5121.             <xsl:attribute name="style:master-page-name">
  5122.                 <xsl:call-template name="encode-as-nc-name">
  5123.                     <xsl:with-param name="string" select="../@ss:Name"/>
  5124.                 </xsl:call-template>
  5125.             </xsl:attribute>
  5126.             <xsl:element name="style:table-properties">
  5127.                 <xsl:choose>
  5128.                     <xsl:when test="../x:WorksheetOptions/x:Visible = 'SheetHidden'">
  5129.                         <xsl:attribute name="table:display">false</xsl:attribute>
  5130.                     </xsl:when>
  5131.                     <xsl:otherwise>
  5132.                         <xsl:attribute name="table:display">true</xsl:attribute>
  5133.                     </xsl:otherwise>
  5134.                 </xsl:choose>
  5135.             </xsl:element>
  5136.         </xsl:element>
  5137.     </xsl:template>
  5138.     <xsl:template name="get-column-style-name">
  5139.         <!-- generate stylename of colbreak after matching the column number and the colbreak number -->
  5140.         <xsl:param name="finishedColumns"/>
  5141.         <xsl:param name="columnCount"/>
  5142.         <xsl:param name="currentCount"/>
  5143.         <xsl:param name="table-pos"/>
  5144.         <xsl:param name="default-column-width"/>
  5145.         <xsl:if test="$currentCount < ($columnCount + 1)">
  5146.             <xsl:variable name="span-value">
  5147.                 <xsl:choose>
  5148.                     <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Span">
  5149.                         <xsl:value-of select="./ss:Column[position() = $currentCount]/@ss:Span + 1"/>
  5150.                     </xsl:when>
  5151.                     <xsl:otherwise>
  5152.                         <xsl:value-of select="0"/>
  5153.                     </xsl:otherwise>
  5154.                 </xsl:choose>
  5155.             </xsl:variable>
  5156.             <xsl:variable name="current-index">
  5157.                 <xsl:choose>
  5158.                     <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Index">
  5159.                         <xsl:value-of select="./ss:Column[position() = $currentCount]/@ss:Index - 1"/>
  5160.                     </xsl:when>
  5161.                     <xsl:otherwise>
  5162.                         <xsl:value-of select="$finishedColumns"/>
  5163.                     </xsl:otherwise>
  5164.                 </xsl:choose>
  5165.             </xsl:variable>
  5166.             <xsl:variable name="column-break">
  5167.                 <xsl:choose>
  5168.                     <xsl:when test="$span-value = 0">
  5169.                         <xsl:if test="../x:PageBreaks/x:ColBreaks/x:ColBreak/x:Column = $current-index">
  5170.                             <xsl:value-of select="1"/>
  5171.                         </xsl:if>
  5172.                     </xsl:when>
  5173.                     <xsl:otherwise>
  5174.                         <xsl:if test="../x:PageBreaks/x:ColBreaks[(x:ColBreak/x:Column > $finishedColumns) and (x:ColBreak/x:Column < ($finishedColumns + $span-value))]">
  5175.                             <xsl:value-of select="1"/>
  5176.                         </xsl:if>
  5177.                     </xsl:otherwise>
  5178.                 </xsl:choose>
  5179.             </xsl:variable>
  5180.             <xsl:if test="$column-break = 1">
  5181.                 <xsl:element name="style:style">
  5182.                     <xsl:attribute name="style:name">
  5183.                         <xsl:call-template name="encode-as-nc-name">
  5184.                             <xsl:with-param name="string" select="concat('cob', $table-pos, '-',$currentCount)"/>
  5185.                         </xsl:call-template>
  5186.                     </xsl:attribute>
  5187.                     <xsl:attribute name="style:family">table-column</xsl:attribute>
  5188.                     <xsl:element name="style:table-column-properties">
  5189.                         <xsl:choose>
  5190.                             <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Width">
  5191.                                 <xsl:attribute name="style:column-width">
  5192.                                     <xsl:call-template name="convert2cm">
  5193.                                         <xsl:with-param name="value" select="concat(./ss:Column[position() = $currentCount]/@ss:Width,'pt')"/>
  5194.                                     </xsl:call-template>
  5195.                                     <xsl:text>cm</xsl:text>
  5196.                                 </xsl:attribute>
  5197.                             </xsl:when>
  5198.                             <xsl:otherwise>
  5199.                                 <xsl:attribute name="style:column-width">
  5200.                                     <xsl:value-of select="$default-column-width"/>
  5201.                                 </xsl:attribute>
  5202.                             </xsl:otherwise>
  5203.                         </xsl:choose>
  5204.                         <xsl:choose>
  5205.                             <xsl:when test="./ss:Column[position() = $currentCount]/@ss:AutoFitWidth = '0'">
  5206.                                 <xsl:attribute name="style:use-optimal-column-width">false</xsl:attribute>
  5207.                             </xsl:when>
  5208.                             <xsl:otherwise>
  5209.                                 <xsl:choose>
  5210.                                     <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Width > 0">
  5211.                                         <xsl:attribute name="style:use-optimal-column-width">false</xsl:attribute>
  5212.                                     </xsl:when>
  5213.                                     <xsl:otherwise>
  5214.                                         <xsl:attribute name="style:use-optimal-column-width">true</xsl:attribute>
  5215.                                     </xsl:otherwise>
  5216.                                 </xsl:choose>
  5217.                             </xsl:otherwise>
  5218.                         </xsl:choose>
  5219.                         <xsl:attribute name="fo:break-before">page</xsl:attribute>
  5220.                     </xsl:element>
  5221.                 </xsl:element>
  5222.             </xsl:if>
  5223.             <style:style style:name="{concat('co', $table-pos, '-',$currentCount)}" style:family="table-column">
  5224.                 <xsl:element name="style:table-column-properties">
  5225.                     <xsl:choose>
  5226.                         <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Width">
  5227.                             <xsl:attribute name="style:column-width">
  5228.                                 <xsl:call-template name="convert2cm">
  5229.                                     <xsl:with-param name="value" select="concat(./ss:Column[position() = $currentCount]/@ss:Width,'pt')"/>
  5230.                                 </xsl:call-template>
  5231.                                 <xsl:text>cm</xsl:text>
  5232.                             </xsl:attribute>
  5233.                         </xsl:when>
  5234.                         <xsl:otherwise>
  5235.                             <xsl:attribute name="style:column-width">
  5236.                                 <xsl:value-of select="$default-column-width"/>
  5237.                             </xsl:attribute>
  5238.                         </xsl:otherwise>
  5239.                     </xsl:choose>
  5240.                     <xsl:attribute name="fo:break-before">auto</xsl:attribute>
  5241.                 </xsl:element>
  5242.             </style:style>
  5243.             <xsl:if test="$currentCount < $columnCount">
  5244.                 <xsl:call-template name="get-column-style-name">
  5245.                     <xsl:with-param name="finishedColumns">
  5246.                         <xsl:choose>
  5247.                             <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Index">
  5248.                                 <xsl:choose>
  5249.                                     <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Span">
  5250.                                         <xsl:value-of select="./ss:Column[position() = $currentCount]/@ss:Index + ./ss:Column[position() = $currentCount]/@ss:Span"/>
  5251.                                     </xsl:when>
  5252.                                     <xsl:otherwise>
  5253.                                         <xsl:value-of select="./ss:Column[position() = $currentCount]/@ss:Index"/>
  5254.                                     </xsl:otherwise>
  5255.                                 </xsl:choose>
  5256.                             </xsl:when>
  5257.                             <xsl:otherwise>
  5258.                                 <xsl:choose>
  5259.                                     <xsl:when test="./ss:Column[position() = $currentCount]/@ss:Span">
  5260.                                         <xsl:value-of select="$finishedColumns + ./ss:Column[position() = $currentCount]/@ss:Span + 1"/>
  5261.                                     </xsl:when>
  5262.                                     <xsl:otherwise>
  5263.                                         <xsl:value-of select="$finishedColumns + 1"/>
  5264.                                     </xsl:otherwise>
  5265.                                 </xsl:choose>
  5266.                             </xsl:otherwise>
  5267.                         </xsl:choose>
  5268.                     </xsl:with-param>
  5269.                     <xsl:with-param name="columnCount" select="$columnCount"/>
  5270.                     <xsl:with-param name="currentCount" select="$currentCount + 1"/>
  5271.                     <xsl:with-param name="table-pos" select="$table-pos"/>
  5272.                     <xsl:with-param name="default-column-width" select="$default-column-width"/>
  5273.                 </xsl:call-template>
  5274.             </xsl:if>
  5275.         </xsl:if>
  5276.     </xsl:template>
  5277.     <xsl:template name="get-row-style-name">
  5278.         <!-- generate stylename of rowbreak after matching the row number and the rowbreak number -->
  5279.         <xsl:param name="earlierRowNo"/>
  5280.         <xsl:param name="rowNodeCount"/>
  5281.         <xsl:param name="rowNodeIndex"/>
  5282.         <xsl:param name="table-pos"/>
  5283.         <xsl:param name="default-row-height"/>
  5284.         <xsl:if test="$rowNodeIndex < ($rowNodeCount + 1)">
  5285.             <xsl:variable name="span-value">
  5286.                 <xsl:choose>
  5287.                     <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Index">
  5288.                         <xsl:choose>
  5289.                             <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Span">
  5290.                                 <xsl:value-of select="./ss:Row[position() = $rowNodeIndex]/@ss:Index - $earlierRowNo+ ./ss:Row[position() = $rowNodeIndex]/@ss:Span"/>
  5291.                             </xsl:when>
  5292.                             <xsl:otherwise>
  5293.                                 <xsl:value-of select="0"/>
  5294.                             </xsl:otherwise>
  5295.                         </xsl:choose>
  5296.                     </xsl:when>
  5297.                     <xsl:otherwise>
  5298.                         <xsl:choose>
  5299.                             <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Span">
  5300.                                 <xsl:value-of select="./ss:Row[position() = $rowNodeIndex]/@ss:Span + 1"/>
  5301.                             </xsl:when>
  5302.                             <xsl:otherwise>
  5303.                                 <xsl:value-of select="0"/>
  5304.                             </xsl:otherwise>
  5305.                         </xsl:choose>
  5306.                     </xsl:otherwise>
  5307.                 </xsl:choose>
  5308.             </xsl:variable>
  5309.             <xsl:variable name="current-index">
  5310.                 <xsl:choose>
  5311.                     <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Index">
  5312.                         <xsl:value-of select="./ss:Row[position() = $rowNodeIndex]/@ss:Index - 1"/>
  5313.                     </xsl:when>
  5314.                     <xsl:otherwise>
  5315.                         <xsl:value-of select="$earlierRowNo"/>
  5316.                     </xsl:otherwise>
  5317.                 </xsl:choose>
  5318.             </xsl:variable>
  5319.             <xsl:variable name="row-break">
  5320.                 <xsl:choose>
  5321.                     <xsl:when test="$span-value = 0">
  5322.                         <xsl:if test="../x:PageBreaks/x:RowBreaks/x:RowBreak/x:Row = $current-index">
  5323.                             <xsl:value-of select="1"/>
  5324.                         </xsl:if>
  5325.                     </xsl:when>
  5326.                     <xsl:otherwise>
  5327.                         <xsl:if test="../x:PageBreaks/x:RowBreaks[(x:RowBreak/x:Row > $earlierRowNo) and (x:RowBreak/x:Row < ($earlierRowNo + $span-value))]">
  5328.                             <xsl:value-of select="1"/>
  5329.                         </xsl:if>
  5330.                     </xsl:otherwise>
  5331.                 </xsl:choose>
  5332.             </xsl:variable>
  5333.             <xsl:if test="$row-break = 1">
  5334.                 <xsl:element name="style:style">
  5335.                     <xsl:choose>
  5336.                         <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:StyleID">
  5337.                             <xsl:attribute name="style:name"><xsl:value-of select="concat('ro', $table-pos, '-',$rowNodeIndex,'-',ss:Row[position() = $rowNodeIndex]/@ss:StyleID)"/></xsl:attribute>
  5338.                         </xsl:when>
  5339.                         <xsl:otherwise>
  5340.                             <xsl:attribute name="style:name"><xsl:value-of select="concat('ro', $table-pos, '-',$rowNodeIndex)"/></xsl:attribute>
  5341.                         </xsl:otherwise>
  5342.                     </xsl:choose>
  5343.                     <xsl:attribute name="style:family">table-row</xsl:attribute>
  5344.  
  5345.  
  5346.                     <xsl:element name="style:table-row-properties">
  5347.                         <xsl:choose>
  5348.                             <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Height">
  5349.                                 <xsl:attribute name="style:row-height">
  5350.                                     <xsl:call-template name="convert2cm">
  5351.                                         <xsl:with-param name="value" select="concat(./ss:Row[position() = $rowNodeIndex]/@ss:Height,'pt')"/>
  5352.                                     </xsl:call-template>
  5353.                                     <xsl:text>cm</xsl:text>
  5354.                                 </xsl:attribute>
  5355.                             </xsl:when>
  5356.                             <xsl:otherwise>
  5357.                                 <xsl:attribute name="style:row-height">
  5358.                                     <xsl:value-of select="$default-row-height"/>
  5359.                                 </xsl:attribute>
  5360.                             </xsl:otherwise>
  5361.                         </xsl:choose>
  5362.                         <xsl:choose>
  5363.                             <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:AutoFitHeight = '0'">
  5364.                                 <xsl:attribute name="style:use-optimal-row-height">false</xsl:attribute>
  5365.                             </xsl:when>
  5366.                             <xsl:otherwise>
  5367.                                 <xsl:choose>
  5368.                                     <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Height > 0">
  5369.                                         <xsl:attribute name="style:use-optimal-row-height">false</xsl:attribute>
  5370.                                     </xsl:when>
  5371.                                     <xsl:otherwise>
  5372.                                         <xsl:attribute name="style:use-optimal-row-height">true</xsl:attribute>
  5373.                                     </xsl:otherwise>
  5374.                                 </xsl:choose>
  5375.                             </xsl:otherwise>
  5376.                         </xsl:choose>
  5377.                         <xsl:attribute name="fo:break-before">page</xsl:attribute>
  5378.                         <xsl:apply-templates select="key('Style', ss:Row[position() = $rowNodeIndex]/@ss:StyleID)/ss:Interior" mode="style-style-content"/>
  5379.                     </xsl:element>
  5380.                     <!--
  5381.                         <xsl:apply-templates select="key('Style', ss:Row[position() = $rowNodeIndex]/@ss:StyleID)" mode="style-style-content" />
  5382.                     -->
  5383.                 </xsl:element>
  5384.             </xsl:if>
  5385.             <!--
  5386.             <style:style style:name="{concat('ro', $table-pos, '-',$rowNodeIndex)}" style:family="table-row">
  5387.             -->
  5388.             <xsl:element name="style:style">
  5389.                 <xsl:choose>
  5390.                     <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:StyleID">
  5391.                         <xsl:attribute name="style:name"><xsl:value-of select="concat('ro', $table-pos, '-',$rowNodeIndex,'-',ss:Row[position() = $rowNodeIndex]/@ss:StyleID)"/></xsl:attribute>
  5392.                     </xsl:when>
  5393.                     <xsl:otherwise>
  5394.                         <xsl:attribute name="style:name"><xsl:value-of select="concat('ro', $table-pos, '-',$rowNodeIndex)"/></xsl:attribute>
  5395.                     </xsl:otherwise>
  5396.                 </xsl:choose>
  5397.                 <xsl:attribute name="style:family">table-row</xsl:attribute>
  5398.  
  5399.  
  5400.                 <xsl:element name="style:table-row-properties">
  5401.                     <xsl:choose>
  5402.                         <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Height">
  5403.                             <xsl:attribute name="style:row-height">
  5404.                                 <xsl:call-template name="convert2cm">
  5405.                                     <xsl:with-param name="value" select="concat(./ss:Row[position() = $rowNodeIndex]/@ss:Height,'pt')"/>
  5406.                                 </xsl:call-template>
  5407.                                 <xsl:text>cm</xsl:text>
  5408.                             </xsl:attribute>
  5409.                         </xsl:when>
  5410.                         <xsl:otherwise>
  5411.                             <xsl:attribute name="style:row-height">
  5412.                                 <xsl:value-of select="$default-row-height"/>
  5413.                             </xsl:attribute>
  5414.                         </xsl:otherwise>
  5415.                     </xsl:choose>
  5416.                     <xsl:choose>
  5417.                         <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:AutoFitHeight">
  5418.                             <xsl:choose>
  5419.                                 <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:AutoFitHeight = '0'">
  5420.                                     <xsl:attribute name="style:use-optimal-row-height">false</xsl:attribute>
  5421.                                 </xsl:when>
  5422.                                 <xsl:otherwise>
  5423.                                     <xsl:attribute name="style:use-optimal-row-height">true</xsl:attribute>
  5424.                                 </xsl:otherwise>
  5425.                             </xsl:choose>
  5426.                         </xsl:when>
  5427.                         <xsl:otherwise>
  5428.                             <xsl:choose>
  5429.                                 <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Height > 0">
  5430.                                     <xsl:attribute name="style:use-optimal-row-height">false</xsl:attribute>
  5431.                                 </xsl:when>
  5432.                                 <xsl:otherwise>
  5433.                                     <xsl:attribute name="style:use-optimal-row-height">true</xsl:attribute>
  5434.                                 </xsl:otherwise>
  5435.                             </xsl:choose>
  5436.                         </xsl:otherwise>
  5437.                     </xsl:choose>
  5438.                     <xsl:attribute name="fo:break-before">auto</xsl:attribute>
  5439.                     <!-- apply to background  -->
  5440.                     <xsl:apply-templates select="key('Style', ss:Row[position() = $rowNodeIndex]/@ss:StyleID)/ss:Interior" mode="style-style-content"/>
  5441.                 </xsl:element>
  5442.                 <!--
  5443.                 <xsl:apply-templates select="key('Style', ss:Row[position() = $rowNodeIndex]/@ss:StyleID)" mode="style-style-content" />
  5444.                 -->
  5445.             </xsl:element>
  5446.             <xsl:if test="$rowNodeIndex < $rowNodeCount">
  5447.                 <xsl:call-template name="get-row-style-name">
  5448.                     <xsl:with-param name="earlierRowNo">
  5449.                         <xsl:choose>
  5450.                             <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Index">
  5451.                                 <xsl:choose>
  5452.                                     <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Span">
  5453.                                         <xsl:value-of select="./ss:Row[position() = $rowNodeIndex]/@ss:Index + ./ss:Row[position() = $rowNodeIndex]/@ss:Span"/>
  5454.                                     </xsl:when>
  5455.                                     <xsl:otherwise>
  5456.                                         <xsl:value-of select="./ss:Row[position() = $rowNodeIndex]/@ss:Index"/>
  5457.                                     </xsl:otherwise>
  5458.                                 </xsl:choose>
  5459.                             </xsl:when>
  5460.                             <xsl:otherwise>
  5461.                                 <xsl:choose>
  5462.                                     <xsl:when test="./ss:Row[position() = $rowNodeIndex]/@ss:Span">
  5463.                                         <xsl:value-of select="$earlierRowNo + ./ss:Row[position() = $rowNodeIndex]/@ss:Span + 1"/>
  5464.                                     </xsl:when>
  5465.                                     <xsl:otherwise>
  5466.                                         <xsl:value-of select="$earlierRowNo + 1"/>
  5467.                                     </xsl:otherwise>
  5468.                                 </xsl:choose>
  5469.                             </xsl:otherwise>
  5470.                         </xsl:choose>
  5471.                     </xsl:with-param>
  5472.                     <xsl:with-param name="rowNodeCount" select="$rowNodeCount"/>
  5473.                     <xsl:with-param name="rowNodeIndex" select="$rowNodeIndex + 1"/>
  5474.                     <xsl:with-param name="table-pos" select="$table-pos"/>
  5475.                     <xsl:with-param name="default-row-height" select="$default-row-height"/>
  5476.                 </xsl:call-template>
  5477.             </xsl:if>
  5478.         </xsl:if>
  5479.     </xsl:template>
  5480.     <xsl:template name="count-spanned-columns">
  5481.         <xsl:param name="expandedColumnCount" select="0"/>
  5482.         <xsl:param name="columns"/>
  5483.         <xsl:param name="columnsCount" select="count($columns)"/>
  5484.         <xsl:param name="columnIndex" select="1"/>
  5485.         <xsl:choose>
  5486.             <xsl:when test="$columnIndex <= $columnsCount">
  5487.                 <xsl:call-template name="count-spanned-columns">
  5488.                     <xsl:with-param name="columns" select="$columns"/>
  5489.                     <xsl:with-param name="columnsCount" select="$columnsCount"/>
  5490.                     <xsl:with-param name="columnIndex" select="$columnIndex + 1"/>
  5491.                     <xsl:with-param name="expandedColumnCount" select="$expandedColumnCount + $columns[$columnIndex]/@ss:Span"/>
  5492.                 </xsl:call-template>
  5493.             </xsl:when>
  5494.             <xsl:otherwise>
  5495.                 <xsl:value-of select="$expandedColumnCount"/>
  5496.             </xsl:otherwise>
  5497.         </xsl:choose>
  5498.     </xsl:template>
  5499.     <xsl:template match="ss:Worksheet">
  5500.         <xsl:element name="table:table">
  5501.             <xsl:attribute name="table:name">
  5502.                 <xsl:value-of select="@ss:Name"/>
  5503.             </xsl:attribute>
  5504.             <!-- other attributes aren't suitable to apply yet -->
  5505.             <xsl:if test="ss:Table">
  5506.                 <xsl:attribute name="table:style-name">
  5507.                     <xsl:value-of select="concat( 'ta', count(preceding-sibling::ss:Worksheet)+1)"/>
  5508.                 </xsl:attribute>
  5509.                 <xsl:if test="@ss:Protected = '1'">
  5510.                     <xsl:attribute name="table:protected">true</xsl:attribute>
  5511.                 </xsl:if>
  5512.                 <xsl:if test="descendant::ss:NamedRange[@ss:Name = 'Print_Area' and contains( @ss:RefersTo, '!R')]">
  5513.                     <xsl:variable name="referto">
  5514.                         <xsl:call-template name="translate-expression">
  5515.                             <xsl:with-param name="cell-row-pos" select="0"/>
  5516.                             <xsl:with-param name="cell-column-pos" select="0"/>
  5517.                             <xsl:with-param name="expression" select="descendant::ss:NamedRange/@ss:RefersTo"/>
  5518.                             <xsl:with-param name="return-value" select="''"/>
  5519.                         </xsl:call-template>
  5520.                     </xsl:variable>
  5521.                     <xsl:attribute name="table:print-ranges">
  5522.                         <xsl:value-of select="translate( $referto, '=', '$')"/>
  5523.                     </xsl:attribute>
  5524.                 </xsl:if>
  5525.                 <xsl:variable name="table-pos">
  5526.                     <xsl:value-of select="count(../preceding-sibling::ss:Worksheet)+1"/>
  5527.                 </xsl:variable>
  5528.                 <xsl:choose>
  5529.                     <xsl:when test="ss:Table/@ss:ExpandedColumnCount">
  5530.                         <xsl:choose>
  5531.                             <xsl:when test="not(ss:Table/ss:Column)">
  5532.                                 <!-- no columns exist -->
  5533.                                 <xsl:call-template name="create-columns-without-input">
  5534.                                     <xsl:with-param name="table-pos" select="$table-pos"/>
  5535.                                 </xsl:call-template>
  5536.                             </xsl:when>
  5537.                             <xsl:otherwise>
  5538.                                 <xsl:call-template name="create-columns">
  5539.                                     <xsl:with-param name="columnCount" select="ss:Table/@ss:ExpandedColumnCount"/>
  5540.                                     <xsl:with-param name="currentColumnNode" select="ss:Table/ss:Column[1]"/>
  5541.                                 </xsl:call-template>
  5542.                             </xsl:otherwise>
  5543.                         </xsl:choose>
  5544.                     </xsl:when>
  5545.                     <xsl:otherwise>
  5546.                         <xsl:choose>
  5547.                             <xsl:when test="ss:Table/ss:Column/@ss:Span">
  5548.                                 <!-- No absolute column number (ss:ExpandedColumnCount) is add the nodes and spanned columns -->
  5549.                                 <xsl:variable name="spannedColumns">
  5550.                                     <xsl:call-template name="count-spanned-columns">
  5551.                                         <xsl:with-param name="columns" select="ss:Table/ss:Column[@ss:Span]"/>
  5552.                                     </xsl:call-template>
  5553.                                 </xsl:variable>
  5554.                                 <xsl:call-template name="create-columns">
  5555.                                     <xsl:with-param name="columnCount" select="count(ss:Table/ss:Column) + number($spannedColumns)"/>
  5556.                                     <xsl:with-param name="currentColumnNode" select="ss:Table/ss:Column[1]"/>
  5557.                                 </xsl:call-template>
  5558.                             </xsl:when>
  5559.                             <xsl:otherwise>
  5560.                                 <!-- No absolute column number (ss:ExpandedColumnCount) is add the nodes -->
  5561.                                 <xsl:call-template name="create-columns">
  5562.                                     <xsl:with-param name="columnCount" select="count(ss:Table/ss:Column)"/>
  5563.                                     <xsl:with-param name="currentColumnNode" select="ss:Table/ss:Column[1]"/>
  5564.                                 </xsl:call-template>
  5565.                             </xsl:otherwise>
  5566.                         </xsl:choose>
  5567.                     </xsl:otherwise>
  5568.                 </xsl:choose>
  5569.                 <!-- generates the string of row\column position if ConditionalFormatting exists -->
  5570.                 <xsl:variable name="condition-pos-str1">
  5571.                     <xsl:if test="./x:ConditionalFormatting">
  5572.                         <xsl:call-template name="condition-row-column-string">
  5573.                             <xsl:with-param name="last" select="''"/>
  5574.                             <xsl:with-param name="total" select="count(./x:ConditionalFormatting)"/>
  5575.                             <xsl:with-param name="index" select="1"/>
  5576.                         </xsl:call-template>
  5577.                     </xsl:if>
  5578.                 </xsl:variable>
  5579.                 <xsl:variable name="condition-pos-str2">
  5580.                     <xsl:if test="./x:DataValidation">
  5581.                         <xsl:call-template name="validation-row-column-string">
  5582.                             <xsl:with-param name="last" select="''"/>
  5583.                             <xsl:with-param name="total" select="count(./x:DataValidation)"/>
  5584.                             <xsl:with-param name="index" select="1"/>
  5585.                         </xsl:call-template>
  5586.                     </xsl:if>
  5587.                 </xsl:variable>
  5588.                 <xsl:variable name="condition-pos-str" select="concat($condition-pos-str1, $condition-pos-str2)"/>
  5589.                 <xsl:choose>
  5590.                     <xsl:when test="./ss:Table/ss:Row">
  5591.                         <xsl:call-template name="create-rows">
  5592.                             <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  5593.                         </xsl:call-template>
  5594.                     </xsl:when>
  5595.                     <xsl:otherwise>
  5596.                         <xsl:choose>
  5597.                             <xsl:when test="./x:PageBreaks/x:RowBreaks">
  5598.                                 <xsl:for-each select="./x:PageBreaks/x:RowBreaks/x:RowBreak">
  5599.                                     <xsl:variable name="number-repeated">
  5600.                                         <xsl:choose>
  5601.                                             <xsl:when test="position() = 1">
  5602.                                                 <xsl:value-of select="./x:Row"/>
  5603.                                             </xsl:when>
  5604.                                             <xsl:otherwise>
  5605.                                                 <xsl:value-of select=". - preceding::x:RowBreak[position()=count(.)]/x:Row - 1"/>
  5606.                                             </xsl:otherwise>
  5607.                                         </xsl:choose>
  5608.                                     </xsl:variable>
  5609.                                     <xsl:if test="$number-repeated > 0">
  5610.                                         <xsl:element name="table:table-row">
  5611.                                             <xsl:if test="@ss:Hidden = '1'">
  5612.                                                 <xsl:attribute name="table:visibility">collapse</xsl:attribute>
  5613.                                             </xsl:if>
  5614.                                             <xsl:attribute name="table:style-name">
  5615.                                                 <xsl:value-of select="concat('ro',$table-pos)"/>
  5616.                                             </xsl:attribute>
  5617.                                             <xsl:attribute name="table:number-rows-repeated">
  5618.                                                 <xsl:value-of select="$number-repeated"/>
  5619.                                             </xsl:attribute>
  5620.                                             <xsl:choose>
  5621.                                                 <xsl:when test="ss:Table/@ss:ExpandedColumnCount">
  5622.                                                     <table:table-cell table:number-columns-repeated="{ss:Table/@ss:ExpandedColumnCount}"/>
  5623.                                                 </xsl:when>
  5624.                                                 <xsl:otherwise>
  5625.                                                     <!-- OASIS XML row can not be empty -->
  5626.                                                     <table:table-cell table:number-columns-repeated="256"/>
  5627.                                                 </xsl:otherwise>
  5628.                                             </xsl:choose>
  5629.                                         </xsl:element>
  5630.                                     </xsl:if>
  5631.                                     <xsl:element name="table:table-row">
  5632.                                         <xsl:if test="@ss:Hidden = '1'">
  5633.                                             <xsl:attribute name="table:visibility">collapse</xsl:attribute>
  5634.                                         </xsl:if>
  5635.                                         <xsl:attribute name="table:style-name">
  5636.                                             <xsl:value-of select="concat('rob',$table-pos)"/>
  5637.                                         </xsl:attribute>
  5638.                                         <xsl:choose>
  5639.                                             <xsl:when test="ss:Table/@ss:ExpandedColumnCount">
  5640.                                                 <table:table-cell table:number-columns-repeated="{ss:Table/@ss:ExpandedColumnCount}"/>
  5641.                                             </xsl:when>
  5642.                                             <xsl:otherwise>
  5643.                                                 <!-- OASIS XML row can not be empty -->
  5644.                                                 <table:table-cell table:number-columns-repeated="256"/>
  5645.                                             </xsl:otherwise>
  5646.                                         </xsl:choose>
  5647.                                     </xsl:element>
  5648.                                 </xsl:for-each>
  5649.                             </xsl:when>
  5650.                             <xsl:otherwise>
  5651.                                 <!-- in case no table row exists (empty spreadsheet) -->
  5652.                                 <xsl:element name="table:table-row">
  5653.                                     <xsl:choose>
  5654.                                         <xsl:when test="ss:Table/@ss:StyleID">
  5655.                                             <xsl:attribute name="table:style-name">
  5656.                                                 <xsl:value-of select="ss:Table/@ss:StyleID"/>
  5657.                                             </xsl:attribute>
  5658.                                             <xsl:element name="table:table-cell">
  5659.                                                 <xsl:attribute name="table:style-name">
  5660.                                                     <xsl:value-of select="ss:Table/@ss:StyleID"/>
  5661.                                                 </xsl:attribute>
  5662.                                             </xsl:element>
  5663.                                         </xsl:when>
  5664.                                         <xsl:otherwise>
  5665.                                             <xsl:attribute name="table:style-name">
  5666.                                                 <xsl:value-of select="concat('ro',$table-pos)"/>
  5667.                                             </xsl:attribute>
  5668.                                             <xsl:element name="table:table-cell"/>
  5669.                                         </xsl:otherwise>
  5670.                                     </xsl:choose>
  5671.                                 </xsl:element>
  5672.                             </xsl:otherwise>
  5673.                         </xsl:choose>
  5674.                         <xsl:if test="./x:ConditionalFormatting">
  5675.                             <xsl:variable name="condition-row-max">
  5676.                                 <xsl:call-template name="condition-row-col-pos-max">
  5677.                                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  5678.                                     <xsl:with-param name="last-value" select="0"/>
  5679.                                     <xsl:with-param name="div-value" select="'R'"/>
  5680.                                 </xsl:call-template>
  5681.                             </xsl:variable>
  5682.                             <xsl:variable name="condition-col-max">
  5683.                                 <xsl:call-template name="condition-row-col-pos-max">
  5684.                                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  5685.                                     <xsl:with-param name="last-value" select="0"/>
  5686.                                     <xsl:with-param name="div-value" select="'C'"/>
  5687.                                 </xsl:call-template>
  5688.                             </xsl:variable>
  5689.                             <xsl:variable name="break-row-max">
  5690.                                 <xsl:call-template name="break-row-beyond-max">
  5691.                                     <xsl:with-param name="pos" select="1"/>
  5692.                                     <xsl:with-param name="last-value" select="0"/>
  5693.                                     <xsl:with-param name="count-value" select="count(./x:PageBreaks/x:RowBreaks/x:RowBreak)"/>
  5694.                                 </xsl:call-template>
  5695.                             </xsl:variable>
  5696.                             <xsl:variable name="end-value">
  5697.                                 <xsl:choose>
  5698.                                     <xsl:when test="$condition-row-max < $break-row-max">
  5699.                                         <xsl:value-of select="$break-row-max"/>
  5700.                                     </xsl:when>
  5701.                                     <xsl:otherwise>
  5702.                                         <xsl:value-of select="$condition-row-max"/>
  5703.                                     </xsl:otherwise>
  5704.                                 </xsl:choose>
  5705.                             </xsl:variable>
  5706.                             <xsl:call-template name="get-row-beyond-last">
  5707.                                 <xsl:with-param name="index-value" select="1"/>
  5708.                                 <xsl:with-param name="worksheetNo" select="count(preceding-sibling::ss:Worksheet)+1"/>
  5709.                                 <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  5710.                                 <xsl:with-param name="end-pos" select="$end-value"/>
  5711.                                 <xsl:with-param name="total-col" select="$condition-col-max"/>
  5712.                             </xsl:call-template>
  5713.                         </xsl:if>
  5714.                         <!-- if exists attribute of StyleID in tag of ss:Table but no Row/Column -->
  5715.                         <xsl:if test="./ss:Table/@ss:StyleID">
  5716.                             <table:table-row table:style-name="{concat('ro',$table-pos)}" table:number-rows-repeated="65564">
  5717.                                 <table:table-cell table:number-columns-repeated="256"/>
  5718.                             </table:table-row>
  5719.                         </xsl:if>
  5720.                     </xsl:otherwise>
  5721.                 </xsl:choose>
  5722.             </xsl:if>
  5723.         </xsl:element>
  5724.     </xsl:template>
  5725.     <!-- Note: Need to be refactored -->
  5726.     <xsl:template name="create-columns-without-input">
  5727.         <xsl:param name="table-pos"/>
  5728.         <xsl:choose>
  5729.             <xsl:when test="./x:PageBreaks/x:ColBreaks">
  5730.                 <xsl:for-each select="./x:PageBreaks/x:ColBreaks/x:ColBreak">
  5731.                     <xsl:variable name="number-repeated">
  5732.                         <xsl:choose>
  5733.                             <xsl:when test="position() = 1">
  5734.                                 <xsl:value-of select="./x:Column"/>
  5735.                             </xsl:when>
  5736.                             <xsl:otherwise>
  5737.                                 <xsl:value-of select=". - preceding::x:ColBreak[position()=count(.)]/x:Column - 1"/>
  5738.                             </xsl:otherwise>
  5739.                         </xsl:choose>
  5740.                     </xsl:variable>
  5741.                     <xsl:if test="$number-repeated > 0">
  5742.                         <xsl:element name="table:table-column">
  5743.                             <xsl:if test="ancestor::ss:Worksheet/ss:Table/@ss:StyleID">
  5744.                                 <xsl:attribute name="table:default-cell-style-name">
  5745.                                     <xsl:value-of select="ancestor::ss:Worksheet/ss:Table/@ss:StyleID"/>
  5746.                                 </xsl:attribute>
  5747.                             </xsl:if>
  5748.                             <xsl:if test="@ss:Hidden = '1'">
  5749.                                 <xsl:attribute name="table:visibility">collapse</xsl:attribute>
  5750.                             </xsl:if>
  5751.                             <xsl:attribute name="table:style-name">
  5752.                                 <xsl:value-of select="concat('co',$table-pos)"/>
  5753.                             </xsl:attribute>
  5754.                             <xsl:attribute name="table:number-columns-repeated">
  5755.                                 <xsl:value-of select="$number-repeated"/>
  5756.                             </xsl:attribute>
  5757.                         </xsl:element>
  5758.                     </xsl:if>
  5759.                     <xsl:element name="table:table-column">
  5760.                         <!-- column style be made out beforehead -->
  5761.                         <xsl:if test="ancestor::ss:Worksheet/ss:Table/@ss:StyleID">
  5762.                             <xsl:attribute name="table:default-cell-style-name">
  5763.                                 <xsl:value-of select="ancestor::ss:Worksheet/ss:Table/@ss:StyleID"/>
  5764.                             </xsl:attribute>
  5765.                         </xsl:if>
  5766.                         <xsl:if test="@ss:Hidden = '1'">
  5767.                             <xsl:attribute name="table:visibility">collapse</xsl:attribute>
  5768.                         </xsl:if>
  5769.                         <xsl:attribute name="table:style-name">
  5770.                             <xsl:value-of select="concat('cob',$table-pos)"/>
  5771.                         </xsl:attribute>
  5772.                     </xsl:element>
  5773.                 </xsl:for-each>
  5774.             </xsl:when>
  5775.             <xsl:otherwise>
  5776.                 <xsl:element name="table:table-column">
  5777.                     <xsl:choose>
  5778.                         <xsl:when test="ss:Table/@ss:StyleID">
  5779.                             <xsl:attribute name="table:style-name">
  5780.                                 <xsl:value-of select="ss:Table/@ss:StyleID"/>
  5781.                             </xsl:attribute>
  5782.                         </xsl:when>
  5783.                         <xsl:otherwise>
  5784.                             <xsl:attribute name="table:style-name">
  5785.                                 <xsl:text>co1</xsl:text>
  5786.                             </xsl:attribute>
  5787.                         </xsl:otherwise>
  5788.                     </xsl:choose>
  5789.                     <xsl:if test="ss:Table/@ss:ExpandedColumnCount and ss:Table/@ss:ExpandedColumnCount > 0">
  5790.                         <xsl:attribute name="table:number-columns-repeated">
  5791.                             <xsl:value-of select="ss:Table/@ss:ExpandedColumnCount"/>
  5792.                         </xsl:attribute>
  5793.                     </xsl:if>
  5794.                     <xsl:attribute name="table:default-cell-style-name">
  5795.                         <xsl:text>Default</xsl:text>
  5796.                     </xsl:attribute>
  5797.                 </xsl:element>
  5798.             </xsl:otherwise>
  5799.         </xsl:choose>
  5800.     </xsl:template>
  5801.     <!--
  5802.      Example:
  5803.         <ss:Table>
  5804.             <ss:Column ss:Index="4" ss:Width="500" ss:Span="3" />
  5805.             <ss:Column ss:Width="200" />
  5806.         </ss:Table>
  5807.  
  5808.     Prior column (ss:Index - 1) is written
  5809.     The given fourth cell (ss:Index="4") is handled as repeated three times (ss:Span="3").
  5810.     The eight column got a width of "200"
  5811.  
  5812.     ContextNode: ss:Worksheet
  5813.     -->
  5814.     <xsl:key match="/ss:Workbook/ss:Worksheet/x:PageBreaks/x:ColBreaks/x:ColBreak" name="ColBreak" use="Column"/>
  5815.     <xsl:template name="create-columns">
  5816.         <xsl:param name="columnCount"/>
  5817.         <xsl:param name="currentColumn" select="1"/>
  5818.         <xsl:param name="finishedColumns" select="0"/>
  5819.         <xsl:param name="worksheetNo" select="count(preceding-sibling::ss:Worksheet)+1"/>
  5820.         <xsl:param name="currentColumnNode"/>
  5821.         <xsl:choose>
  5822.             <xsl:when test="$finishedColumns < $columnCount">
  5823.                 <xsl:choose>
  5824.                     <xsl:when test="$currentColumnNode">
  5825.                         <xsl:choose>
  5826.                             <xsl:when test="$currentColumnNode/@ss:Index - $finishedColumns > 1">
  5827.                                 <!-- found column with index.
  5828.                                  filling up table with empty columns until Index is reached -->
  5829.                                 <xsl:call-template name="create-default-column">
  5830.                                     <xsl:with-param name="currentColumn" select="$currentColumn"/>
  5831.                                     <xsl:with-param name="currentColumnNode" select="$currentColumnNode"/>
  5832.                                     <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  5833.                                 </xsl:call-template>
  5834.                                 <xsl:call-template name="create-columns">
  5835.                                     <xsl:with-param name="columnCount" select="$columnCount"/>
  5836.                                     <xsl:with-param name="currentColumn" select="$currentColumn"/>
  5837.                                     <xsl:with-param name="currentColumnNode" select="$currentColumnNode"/>
  5838.                                     <xsl:with-param name="finishedColumns" select="$finishedColumns + 1"/>
  5839.                                     <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  5840.                                 </xsl:call-template>
  5841.                             </xsl:when>
  5842.                             <xsl:otherwise>
  5843.                                 <xsl:element name="table:table-column">
  5844.                                     <xsl:if test="$currentColumnNode/@ss:Hidden = '1'">
  5845.                                         <xsl:attribute name="table:visibility">collapse</xsl:attribute>
  5846.                                     </xsl:if>
  5847.                                     <xsl:if test="$currentColumnNode/@ss:Span">
  5848.                                         <xsl:attribute name="table:number-columns-repeated">
  5849.                                             <xsl:value-of select="$currentColumnNode/@ss:Span + 1"/>
  5850.                                         </xsl:attribute>
  5851.                                     </xsl:if>
  5852.                                     <xsl:choose>
  5853.                                         <xsl:when test="key('ColBreak', $currentColumn)">
  5854.                                             <xsl:attribute name="table:style-name">
  5855.                                                 <xsl:value-of select="concat('cob', $worksheetNo, '-', $currentColumn)"/>
  5856.                                             </xsl:attribute>
  5857.                                         </xsl:when>
  5858.                                         <xsl:otherwise>
  5859.                                             <xsl:attribute name="table:style-name">
  5860.                                                 <xsl:value-of select="concat('co', $worksheetNo, '-', $currentColumn)"/>
  5861.                                             </xsl:attribute>
  5862.                                         </xsl:otherwise>
  5863.                                     </xsl:choose>
  5864.                                     <xsl:choose>
  5865.                                         <xsl:when test="$currentColumnNode/@ss:StyleID">
  5866.                                             <xsl:attribute name="table:default-cell-style-name">
  5867.                                                 <xsl:value-of select="$currentColumnNode/@ss:StyleID"/>
  5868.                                             </xsl:attribute>
  5869.                                         </xsl:when>
  5870.                                         <xsl:otherwise>
  5871.                                             <xsl:attribute name="table:default-cell-style-name">
  5872.                                                 <xsl:text>Default</xsl:text>
  5873.                                             </xsl:attribute>
  5874.                                         </xsl:otherwise>
  5875.                                     </xsl:choose>
  5876.                                 </xsl:element>
  5877.                                 <xsl:call-template name="create-columns">
  5878.                                     <xsl:with-param name="columnCount" select="$columnCount"/>
  5879.                                     <xsl:with-param name="currentColumn" select="$currentColumn + 1"/>
  5880.                                     <xsl:with-param name="finishedColumns">
  5881.                                         <xsl:choose>
  5882.                                             <xsl:when test="$currentColumnNode/@ss:Span">
  5883.                                                 <xsl:value-of select="$finishedColumns + $currentColumnNode/@ss:Span + 1"/>
  5884.                                             </xsl:when>
  5885.                                             <xsl:otherwise>
  5886.                                                 <xsl:value-of select="$finishedColumns + 1"/>
  5887.                                             </xsl:otherwise>
  5888.                                         </xsl:choose>
  5889.                                     </xsl:with-param>
  5890.                                     <xsl:with-param name="currentColumnNode" select="ss:Table/ss:Column[$currentColumn + 1]"/>
  5891.                                     <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  5892.                                 </xsl:call-template>
  5893.                             </xsl:otherwise>
  5894.                         </xsl:choose>
  5895.                     </xsl:when>
  5896.                     <xsl:otherwise>
  5897.                     <!--                                 <xsl:if test="not($finishedColumns + 1 = $columnCount)"> -->
  5898.                         <xsl:call-template name="create-default-column">
  5899.                             <xsl:with-param name="currentColumn" select="$currentColumn"/>
  5900.                             <xsl:with-param name="currentColumnNode" select="$currentColumnNode"/>
  5901.                             <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  5902.                         </xsl:call-template>
  5903.                         <xsl:call-template name="create-columns">
  5904.                             <xsl:with-param name="columnCount" select="$columnCount"/>
  5905.                             <xsl:with-param name="currentColumn" select="$currentColumn"/>
  5906.                             <xsl:with-param name="finishedColumns" select="$finishedColumns + 1"/>
  5907.                             <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  5908.                         </xsl:call-template>
  5909.                     </xsl:otherwise>
  5910.                 </xsl:choose>
  5911.             </xsl:when>
  5912.             <xsl:otherwise>
  5913.                 <xsl:if test="$currentColumn = $columnCount">
  5914.                     <!-- Note: name test document for this case and refactor the template -->
  5915.                     <xsl:if test="x:PageBreaks/x:ColBreaks/x:ColBreak/x:Column > $finishedColumns">
  5916.                         <xsl:call-template name="get-column-beyond-last">
  5917.                             <xsl:with-param name="index-value" select="$finishedColumns"/>
  5918.                             <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  5919.                         </xsl:call-template>
  5920.                     </xsl:if>
  5921.                     <!--Note: Test Scenario for this case: generates some special tags for whole row style
  5922.                 <xsl:if test="(./ss:Table[@ss:StyleID] or ./ss:Table/ss:Row[@ss:StyleID]) and (256 - $finishedColumns > 0)">
  5923.                     <xsl:element name="table:table-column">
  5924.                         <xsl:attribute name="table:default-cell-style-name"><xsl:choose><xsl:when test="./ss:Table[@ss:StyleID]"><xsl:value-of select="./ss:Table/@ss:StyleID" /></xsl:when><xsl:otherwise><xsl:value-of select="'Default'" /></xsl:otherwise></xsl:choose></xsl:attribute>
  5925.                         <xsl:attribute name="table:style-name"><xsl:value-of select="'co1'" /></xsl:attribute>
  5926.                         <xsl:attribute name="table:number-columns-repeated"><xsl:value-of select="256 - $finishedColumns" /></xsl:attribute>
  5927.                     </xsl:element>
  5928.                 </xsl:if>
  5929.                 -->
  5930.                 </xsl:if>
  5931.             </xsl:otherwise>
  5932.         </xsl:choose>
  5933.     </xsl:template>
  5934.     <xsl:template name="create-default-column">
  5935.         <xsl:param name="currentColumn"/>
  5936.         <xsl:param name="currentColumnNode"/>
  5937.         <xsl:param name="worksheetNo"/>
  5938.         <xsl:param name="nextColumnNo"/>
  5939.         <xsl:element name="table:table-column">
  5940.             <xsl:attribute name="table:default-cell-style-name">
  5941.                 <xsl:call-template name="get-default-cell-style">
  5942.                     <xsl:with-param name="currentColumnNode" select="$currentColumnNode"/>
  5943.                 </xsl:call-template>
  5944.             </xsl:attribute>
  5945.             <!-- <xsl:attribute name="table:default-cell-style-name"><xsl:value-of select="$nextColumnNo - $currentColumn"/></xsl:attribute>  -->
  5946.             <xsl:choose>
  5947.                 <xsl:when test="key('ColBreak', $currentColumn)">
  5948.                     <xsl:attribute name="table:style-name">
  5949.                         <xsl:value-of select="concat('cob',$worksheetNo)"/>
  5950.                     </xsl:attribute>
  5951.                 </xsl:when>
  5952.                 <xsl:otherwise>
  5953.                     <xsl:attribute name="table:style-name">
  5954.                         <xsl:value-of select="concat('co',$worksheetNo)"/>
  5955.                     </xsl:attribute>
  5956.                 </xsl:otherwise>
  5957.             </xsl:choose>
  5958.         </xsl:element>
  5959.     </xsl:template>
  5960.     <xsl:template name="create-rows">
  5961.         <xsl:param name="condition-pos-str"/>
  5962.         <xsl:apply-templates select="ss:Table/ss:Row[1]" mode="create-rows">
  5963.             <xsl:with-param name="worksheetNo" select="count(preceding-sibling::ss:Worksheet)+1"/>
  5964.             <xsl:with-param name="rowNodeCount" select="count(ss:Table/ss:Row)"/>
  5965.             <xsl:with-param name="rowNodeIndex" select="1"/>
  5966.             <xsl:with-param name="expandedRowCount">
  5967.                 <xsl:call-template name="get-expanded-row-count"/>
  5968.             </xsl:with-param>
  5969.             <xsl:with-param name="expandedRowCountIndex" select="1"/>
  5970.             <xsl:with-param name="expandedColumnCount">
  5971.                 <xsl:call-template name="get-expanded-column-count"/>
  5972.             </xsl:with-param>
  5973.             <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  5974.         </xsl:apply-templates>
  5975.     </xsl:template>
  5976.     <xsl:template match="ss:Row" mode="create-rows">
  5977.         <xsl:param name="worksheetNo"/>
  5978.         <xsl:param name="rowNodeCount"/>
  5979.         <xsl:param name="rowNodeIndex" select="1"/>
  5980.         <xsl:param name="expandedRowCount"/>
  5981.         <xsl:param name="expandedRowCountIndex" select="1"/>
  5982.         <xsl:param name="expandedColumnCount"/>
  5983.         <xsl:param name="condition-pos-str"/>
  5984.         <xsl:variable name="currentRowNo">
  5985.             <xsl:choose>
  5986.                 <xsl:when test="@ss:Index">
  5987.                     <xsl:value-of select="@ss:Index"/>
  5988.                 </xsl:when>
  5989.                 <xsl:otherwise>
  5990.                     <xsl:value-of select="$expandedRowCountIndex"/>
  5991.                 </xsl:otherwise>
  5992.             </xsl:choose>
  5993.         </xsl:variable>
  5994.         <xsl:if test="@ss:Index - $expandedRowCountIndex > 0">
  5995.             <!-- create the precding missing rows -->
  5996.             <xsl:element name="table:table-row">
  5997.                 <!-- fill the preceding gap with rows without a cell -->
  5998.                 <xsl:attribute name="table:number-rows-repeated">
  5999.                     <xsl:value-of select="@ss:Index - $expandedRowCountIndex"/>
  6000.                 </xsl:attribute>
  6001.                 <xsl:choose>
  6002.                     <xsl:when test="$expandedColumnCount != 0">
  6003.                         <table:table-cell table:number-columns-repeated="{$expandedColumnCount}"/>
  6004.                     </xsl:when>
  6005.                     <xsl:otherwise>
  6006.                         <!-- OASIS XML row can not be empty -->
  6007.                         <table:table-cell table:number-columns-repeated="256"/>
  6008.                     </xsl:otherwise>
  6009.                 </xsl:choose>
  6010.             </xsl:element>
  6011.         </xsl:if>
  6012.         <xsl:element name="table:table-row">
  6013.             <xsl:attribute name="table:style-name">
  6014.                 <xsl:choose>
  6015.                     <xsl:when test="@ss:StyleID">
  6016.                         <xsl:value-of select="concat('ro',$worksheetNo, '-',$rowNodeIndex,'-', @ss:StyleID)"/>
  6017.                     </xsl:when>
  6018.                     <xsl:otherwise>
  6019.                         <xsl:value-of select="concat('ro',$worksheetNo,'-',$rowNodeIndex)"/>
  6020.                     </xsl:otherwise>
  6021.                 </xsl:choose>
  6022.             </xsl:attribute>
  6023.             <xsl:if test="@ss:Hidden = '1'">
  6024.                 <xsl:attribute name="table:visibility">collapse</xsl:attribute>
  6025.             </xsl:if>
  6026.             <xsl:if test="@ss:Span">
  6027.                 <xsl:attribute name="table:number-rows-repeated">
  6028.                     <xsl:value-of select="@ss:Span + 1"/>
  6029.                 </xsl:attribute>
  6030.             </xsl:if>
  6031.             <xsl:choose>
  6032.                 <!-- Excel row without content -->
  6033.                 <xsl:when test="not(*)">
  6034.                     <!-- OASIS OpenDocument Format does not allow rows without a cell -->
  6035.                 <xsl:choose>
  6036.                     <xsl:when test="$expandedColumnCount != 0">
  6037.                         <table:table-cell table:number-columns-repeated="{$expandedColumnCount}"/>
  6038.                     </xsl:when>
  6039.                     <xsl:otherwise>
  6040.                         <!-- OASIS XML row can not be empty -->
  6041.                         <table:table-cell table:number-columns-repeated="256"/>
  6042.                     </xsl:otherwise>
  6043.                 </xsl:choose>
  6044.  
  6045.                 </xsl:when>
  6046.                 <xsl:otherwise>
  6047.                     <xsl:call-template name="create-cells">
  6048.                         <xsl:with-param name="row-pos" select="$currentRowNo"/>
  6049.                         <xsl:with-param name="expandedColumnCount" select="$expandedColumnCount"/>
  6050.                         <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6051.                     </xsl:call-template>
  6052.                 </xsl:otherwise>
  6053.             </xsl:choose>
  6054.         </xsl:element>
  6055.         <!-- columns are painting over the expanded RowCount -->
  6056.         <xsl:choose>
  6057.             <xsl:when test="count(following-sibling::ss:Row) != 0">
  6058.                 <xsl:apply-templates select="following-sibling::ss:Row[1]" mode="create-rows">
  6059.                     <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  6060.                     <xsl:with-param name="rowNodeCount" select="$rowNodeCount"/>
  6061.                     <xsl:with-param name="rowNodeIndex" select="$rowNodeIndex + 1"/>
  6062.                     <xsl:with-param name="expandedRowCount" select="$expandedRowCount"/>
  6063.                     <xsl:with-param name="expandedRowCountIndex">
  6064.                         <xsl:choose>
  6065.                             <xsl:when test="@ss:Index and @ss:Span">
  6066.                                 <xsl:value-of select="@ss:Index + @ss:Span + 1"/>
  6067.                             </xsl:when>
  6068.                             <xsl:when test="@ss:Index">
  6069.                                 <xsl:value-of select="@ss:Index + 1"/>
  6070.                             </xsl:when>
  6071.                             <xsl:when test="@ss:Span">
  6072.                                 <xsl:value-of select="$expandedRowCountIndex + @ss:Span + 1"/>
  6073.                             </xsl:when>
  6074.                             <xsl:otherwise>
  6075.                                 <xsl:value-of select="$expandedRowCountIndex + 1"/>
  6076.                             </xsl:otherwise>
  6077.                         </xsl:choose>
  6078.                     </xsl:with-param>
  6079.                     <xsl:with-param name="expandedColumnCount" select="$expandedColumnCount"/>
  6080.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6081.                 </xsl:apply-templates>
  6082.             </xsl:when>
  6083.             <xsl:when test="$currentRowNo < 65536">
  6084.                 <xsl:element name="table:table-row">
  6085.                     <!-- fill the preceding gap with rows without a cell -->
  6086.                     <xsl:attribute name="table:number-rows-repeated">
  6087.                         <xsl:value-of select="65536 - $currentRowNo"/>
  6088.                     </xsl:attribute>
  6089.                     <xsl:choose>
  6090.                         <xsl:when test="$expandedColumnCount != 0">
  6091.                             <table:table-cell table:number-columns-repeated="{$expandedColumnCount}"/>
  6092.                         </xsl:when>
  6093.                         <xsl:otherwise>
  6094.                             <!-- OASIS XML row can not be empty -->
  6095.                             <table:table-cell table:number-columns-repeated="256"/>
  6096.                         </xsl:otherwise>
  6097.                     </xsl:choose>
  6098.                 </xsl:element>
  6099.             </xsl:when>
  6100.         </xsl:choose>
  6101.     </xsl:template>
  6102.     <xsl:template name="get-expanded-column-count">
  6103.         <xsl:choose>
  6104.             <xsl:when test="ss:Table/@ss:ExpandedColumnCount">
  6105.                 <xsl:value-of select="ss:Table/@ss:ExpandedColumnCount"/>
  6106.             </xsl:when>
  6107.             <xsl:otherwise>
  6108.                 <xsl:choose>
  6109.                     <xsl:when test="ss:Table/ss:Column/@ss:Span">
  6110.                         <!-- No absolute column number (ss:ExpandedColumnCount) is add the nodes and spanned columns -->
  6111.                         <xsl:variable name="spannedColumns">
  6112.                             <xsl:call-template name="count-spanned-columns">
  6113.                                 <xsl:with-param name="columns" select="ss:Table/ss:Column[@ss:Span]"/>
  6114.                             </xsl:call-template>
  6115.                         </xsl:variable>
  6116.                         <xsl:value-of select="count(ss:Table/ss:Column) + number($spannedColumns)"/>
  6117.                     </xsl:when>
  6118.                     <xsl:otherwise>
  6119.                         <!-- No absolute column number (ss:ExpandedColumnCount) is add the nodes -->
  6120.                         <xsl:value-of select="count(ss:Table/ss:Column)"/>
  6121.                     </xsl:otherwise>
  6122.                 </xsl:choose>
  6123.             </xsl:otherwise>
  6124.         </xsl:choose>
  6125.     </xsl:template>
  6126.     <xsl:template name="get-expanded-row-count">
  6127.         <xsl:choose>
  6128.             <xsl:when test="ss:Table/@ss:ExpandedRowCount">
  6129.                 <xsl:value-of select="ss:Table/@ss:ExpandedRowCount"/>
  6130.             </xsl:when>
  6131.             <xsl:otherwise>
  6132.                 <xsl:choose>
  6133.                     <xsl:when test="ss:Table/ss:Row/@ss:Index and not(ss:Table/ss:Row/@ss:Span)">
  6134.                         <xsl:variable name="lastIndexedRow" select="ss:Table/ss:Row[@ss:Index][last()]"/>
  6135.                         <xsl:value-of select="number($lastIndexedRow/@ss:Index) + count($lastIndexedRow/following-sibling::ss:Row)"/>
  6136.                     </xsl:when>
  6137.                     <xsl:when test="ss:Table/ss:Row/@ss:Index and ss:Table/ss:Row/@ss:Span">
  6138.                         <xsl:variable name="lastIndexedRow" select="ss:Table/ss:Row[@ss:Index][last()]"/>
  6139.                         <xsl:variable name="spannedRows">
  6140.                             <xsl:call-template name="count-spanned-rows">
  6141.                                 <xsl:with-param name="rows" select="$lastIndexedRow/following-sibling::ss:Row[@ss:Span]"/>
  6142.                             </xsl:call-template>
  6143.                         </xsl:variable>
  6144.                         <xsl:value-of select="number($lastIndexedRow/@ss:Index) + count($lastIndexedRow/following-sibling::ss:Row) + number($spannedRows)"/>
  6145.                     </xsl:when>
  6146.                     <xsl:when test="not(ss:Table/ss:Row/@ss:Index) and ss:Table/ss:Row/@ss:Span">
  6147.                         <xsl:variable name="spannedRows">
  6148.                             <xsl:call-template name="count-spanned-rows">
  6149.                                 <xsl:with-param name="rows" select="ss:Table/ss:Rows[@ss:Span]"/>
  6150.                             </xsl:call-template>
  6151.                         </xsl:variable>
  6152.                         <xsl:value-of select="count(ss:Table/ss:Row + number($spannedRows))"/>
  6153.                     </xsl:when>
  6154.                     <xsl:otherwise>
  6155.                         <xsl:value-of select="count(ss:Table/ss:Row)"/>
  6156.                     </xsl:otherwise>
  6157.                 </xsl:choose>
  6158.             </xsl:otherwise>
  6159.         </xsl:choose>
  6160.     </xsl:template>
  6161.     <xsl:template name="count-spanned-rows">
  6162.         <xsl:param name="expandedRowCount" select="0"/>
  6163.         <xsl:param name="rows"/>
  6164.         <xsl:param name="rowsCount" select="count($rows)"/>
  6165.         <xsl:param name="rowIndex" select="1"/>
  6166.         <xsl:choose>
  6167.             <xsl:when test="$rowIndex <= $rowsCount">
  6168.                 <xsl:call-template name="count-spanned-rows">
  6169.                     <xsl:with-param name="rows" select="$rows"/>
  6170.                     <xsl:with-param name="rowsCount" select="$rowsCount"/>
  6171.                     <xsl:with-param name="rowIndex" select="$rowIndex + 1"/>
  6172.                     <xsl:with-param name="expandedRowCount" select="$expandedRowCount + $rows[$rowIndex]/@ss:Span"/>
  6173.                 </xsl:call-template>
  6174.             </xsl:when>
  6175.             <xsl:otherwise>
  6176.                 <xsl:value-of select="$expandedRowCount"/>
  6177.             </xsl:otherwise>
  6178.         </xsl:choose>
  6179.     </xsl:template>
  6180.     <xsl:template name="get-default-cell-style">
  6181.         <xsl:param name="currentColumnNode"/>
  6182.         <xsl:choose>
  6183.             <xsl:when test="$currentColumnNode">
  6184.                 <xsl:choose>
  6185.                     <xsl:when test="$currentColumnNode/@ss:StyleID">
  6186.                         <xsl:value-of select="$currentColumnNode/@ss:StyleID"/>
  6187.                     </xsl:when>
  6188.                     <xsl:otherwise>Default</xsl:otherwise>
  6189.                 </xsl:choose>
  6190.             </xsl:when>
  6191.             <xsl:otherwise>
  6192.                 <xsl:choose>
  6193.                     <xsl:when test="./ss:Table[@ss:StyleID]">
  6194.                         <xsl:value-of select="./ss:Table/@ss:StyleID"/>
  6195.                     </xsl:when>
  6196.                     <xsl:otherwise>Default</xsl:otherwise>
  6197.                 </xsl:choose>
  6198.             </xsl:otherwise>
  6199.         </xsl:choose>
  6200.     </xsl:template>
  6201.     <xsl:template name="get-row-beyond-last">
  6202.         <!-- dealing the RowBreak after last row by recursion -->
  6203.         <xsl:param name="index-value"/>
  6204.         <xsl:param name="worksheetNo"/>
  6205.         <xsl:param name="condition-pos-str"/>
  6206.         <xsl:param name="end-pos"/>
  6207.         <xsl:param name="total-col"/>
  6208.         <xsl:variable name="current" select="concat('R',$index-value)"/>
  6209.         <xsl:element name="table:table-row">
  6210.             <xsl:choose>
  6211.                 <xsl:when test="./x:PageBreaks/x:RowBreaks/x:RowBreak/x:Row = ($index-value - 1)">
  6212.                     <xsl:attribute name="table:style-name">
  6213.                         <xsl:value-of select="concat('rob',$worksheetNo)"/>
  6214.                     </xsl:attribute>
  6215.                 </xsl:when>
  6216.                 <xsl:otherwise>
  6217.                     <xsl:attribute name="table:style-name">
  6218.                         <xsl:value-of select="concat('ro',$worksheetNo)"/>
  6219.                     </xsl:attribute>
  6220.                 </xsl:otherwise>
  6221.             </xsl:choose>
  6222.             <xsl:choose>
  6223.                 <!-- Note: 2 be refactored
  6224.                 <xsl:when test="./ss:Table/ss:Column[@ss:StyleID] or ./ss:Table[@ss:StyleID]">
  6225.                     <xsl:if test="256 - count(ss:Table/ss:Column) > 0">
  6226.                         <table:table-cell table:number-columns-repeated="{256 - count(ss:Table/ss:Column)}" />
  6227.                     </xsl:if>
  6228.                 </xsl:when>-->
  6229.                 <xsl:when test="contains($condition-pos-str,$current)">
  6230.                     <xsl:call-template name="create-spanning-cells">
  6231.                         <xsl:with-param name="row-pos" select="$index-value"/>
  6232.                         <xsl:with-param name="c-start" select="1"/>
  6233.                         <xsl:with-param name="c-end" select="$total-col"/>
  6234.                         <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6235.                     </xsl:call-template>
  6236.                 </xsl:when>
  6237.                 <xsl:otherwise>
  6238.                     <!-- OASIS XML does not allow rows without a cell -->
  6239.                     <table:table-cell/>
  6240.                 </xsl:otherwise>
  6241.             </xsl:choose>
  6242.         </xsl:element>
  6243.         <xsl:if test="$index-value < ($end-pos + 1)">
  6244.             <xsl:call-template name="get-row-beyond-last">
  6245.                 <xsl:with-param name="index-value" select="$index-value + 1"/>
  6246.                 <xsl:with-param name="worksheetNo" select="$worksheetNo"/>
  6247.                 <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6248.                 <xsl:with-param name="end-pos" select="$end-pos"/>
  6249.                 <xsl:with-param name="total-col" select="$total-col"/>
  6250.             </xsl:call-template>
  6251.         </xsl:if>
  6252.     </xsl:template>
  6253.     <xsl:template name="break-row-beyond-max">
  6254.         <!-- returns the max position of the row from condition-pos-str -->
  6255.         <xsl:param name="pos"/>
  6256.         <xsl:param name="last-value"/>
  6257.         <xsl:param name="count-value"/>
  6258.         <xsl:variable name="pre-value" select="./x:PageBreaks/x:RowBreaks/x:RowBreak[position() = $pos]/x:Row"/>
  6259.         <xsl:variable name="end-value">
  6260.             <xsl:choose>
  6261.                 <xsl:when test="$last-value < $pre-value">
  6262.                     <xsl:value-of select="$pre-value"/>
  6263.                 </xsl:when>
  6264.                 <xsl:otherwise>
  6265.                     <xsl:value-of select="$last-value"/>
  6266.                 </xsl:otherwise>
  6267.             </xsl:choose>
  6268.         </xsl:variable>
  6269.         <xsl:choose>
  6270.             <xsl:when test="$pos < $count-value">
  6271.                 <xsl:call-template name="break-row-beyond-max">
  6272.                     <xsl:with-param name="pos" select="$pos + 1"/>
  6273.                     <xsl:with-param name="last-value" select="$end-value"/>
  6274.                     <xsl:with-param name="count-value" select="$count-value"/>
  6275.                 </xsl:call-template>
  6276.             </xsl:when>
  6277.             <xsl:otherwise>
  6278.                 <xsl:value-of select="$end-value"/>
  6279.             </xsl:otherwise>
  6280.         </xsl:choose>
  6281.     </xsl:template>
  6282.     <xsl:template name="get-column-beyond-last">
  6283.         <!-- dealing the ColBreak after last column by recursion -->
  6284.         <xsl:param name="index-value"/>
  6285.         <xsl:param name="worksheetNo"/>
  6286.         <xsl:for-each select="./x:PageBreaks/x:ColBreaks/x:ColBreak">
  6287.             <xsl:variable name="each-column-value" select="./x:Column"/>
  6288.             <xsl:choose>
  6289.                 <xsl:when test="$each-column-value + 1 > $index-value">
  6290.                     <xsl:variable name="number-repeated">
  6291.                         <xsl:choose>
  6292.                             <xsl:when test="preceding-sibling::x:ColBreak[position()=count(.)]/x:Column + 1 = $index-value">
  6293.                                 <xsl:value-of select="$each-column-value - preceding-sibling::x:ColBreak[position()=count(.)]/x:Column - 1"/>
  6294.                             </xsl:when>
  6295.                             <xsl:when test="preceding-sibling::x:ColBreak[position()=count(.)]/x:Column + 1 > $index-value">
  6296.                                 <xsl:value-of select="$each-column-value - preceding-sibling::x:ColBreak[position()=count(.)]/x:Column - 1"/>
  6297.                             </xsl:when>
  6298.                             <xsl:otherwise>
  6299.                                 <xsl:value-of select="$each-column-value - $index-value + 1"/>
  6300.                             </xsl:otherwise>
  6301.                         </xsl:choose>
  6302.                     </xsl:variable>
  6303.                     <xsl:if test="$number-repeated > 0">
  6304.                         <xsl:element name="table:table-column">
  6305.                             <xsl:attribute name="table:style-name">
  6306.                                 <xsl:value-of select="'co1'"/>
  6307.                             </xsl:attribute>
  6308.                             <xsl:attribute name="table:number-columns-repeated">
  6309.                                 <xsl:value-of select="$number-repeated"/>
  6310.                             </xsl:attribute>
  6311.                         </xsl:element>
  6312.                     </xsl:if>
  6313.                     <xsl:element name="table:table-column">
  6314.                         <xsl:if test="./../../../ss:Table[@ss:StyleID]">
  6315.                             <xsl:attribute name="table:default-cell-style-name">
  6316.                                 <xsl:value-of select="./ss:Table/@ss:StyleID"/>
  6317.                             </xsl:attribute>
  6318.                         </xsl:if>
  6319.                         <xsl:attribute name="table:style-name">
  6320.                             <xsl:value-of select="concat('cob',$worksheetNo)"/>
  6321.                         </xsl:attribute>
  6322.                     </xsl:element>
  6323.                 </xsl:when>
  6324.                 <xsl:when test="$each-column-value + 1 = $index-value">
  6325.                     <xsl:element name="table:table-column">
  6326.                         <xsl:if test="./../../../ss:Table[@ss:StyleID]">
  6327.                             <xsl:attribute name="table:default-cell-style-name">
  6328.                                 <xsl:value-of select="./../../../ss:Table/@ss:StyleID"/>
  6329.                             </xsl:attribute>
  6330.                         </xsl:if>
  6331.                         <xsl:attribute name="table:style-name">
  6332.                             <xsl:value-of select="concat('cob',$worksheetNo)"/>
  6333.                         </xsl:attribute>
  6334.                     </xsl:element>
  6335.                 </xsl:when>
  6336.             </xsl:choose>
  6337.         </xsl:for-each>
  6338.     </xsl:template>
  6339.     <xsl:template name="create-spanning-cells">
  6340.         <!-- judge the position of the Cell in the condition-pos-str -->
  6341.         <xsl:param name="row-pos"/>
  6342.         <xsl:param name="c-start"/>
  6343.         <xsl:param name="c-end"/>
  6344.         <xsl:param name="condition-pos-str"/>
  6345.  
  6346.         <xsl:variable name="current" select="concat('R',$row-pos,'C',$c-start,',')"/>
  6347.         <xsl:variable name="style-name">
  6348.             <xsl:choose>
  6349.                 <xsl:when test="contains($condition-pos-str,$current)">
  6350.                     <xsl:variable name="temp-str">
  6351.                         <xsl:call-template name="condition-str">
  6352.                             <xsl:with-param name="param-str" select="substring-before($condition-pos-str,$current)"/>
  6353.                         </xsl:call-template>
  6354.                     </xsl:variable>
  6355.                     <xsl:choose>
  6356.                         <xsl:when test="starts-with($temp-str, 'c')">
  6357.                             <xsl:value-of select="concat('ce', substring-after($temp-str, 'c'))"/>
  6358.                         </xsl:when>
  6359.                         <xsl:when test="starts-with($temp-str, 'v')">
  6360.                             <xsl:value-of select="concat('val', substring-after($temp-str, 'v'))"/>
  6361.                         </xsl:when>
  6362.                     </xsl:choose>
  6363.                 </xsl:when>
  6364.                 <xsl:otherwise>
  6365.                     <!-- as for the spanned cells no style is taken.. -->
  6366.                     <xsl:choose>
  6367.                         <!-- inherit style from parent row style-->
  6368.                         <xsl:when test="../@ss:StyleID">
  6369.                             <xsl:value-of select="../@ss:StyleID"/>
  6370.                         </xsl:when>
  6371.                         <!-- if no correspondent column style exisit.. -->
  6372.                         <!-- inherit style from parent table style -->
  6373.                         <xsl:when test="../../@ss:StyleID">
  6374.                             <!-- function to give in col-pos and get back column style  -->
  6375.                             <xsl:variable name="relatedColumnStyle">
  6376.                                 <xsl:call-template name="get-related-column-style">
  6377.                                     <!-- the given position of the cell in the table, a column style is searched -->
  6378.                                     <xsl:with-param name="calculatedCellPosition" select="$c-start" />
  6379.                                     <!-- all columns in XML -->
  6380.                                     <xsl:with-param name="columnXMLNodes" select="../../ss:Column"/>
  6381.                                 </xsl:call-template>
  6382.                             </xsl:variable>
  6383.                             <xsl:if test="$relatedColumnStyle = ''">
  6384.                                 <xsl:value-of select="../../@ss:StyleID"/>
  6385.                             </xsl:if>
  6386.                         </xsl:when>
  6387.                     </xsl:choose>
  6388.                 </xsl:otherwise>
  6389.             </xsl:choose>
  6390.         </xsl:variable>
  6391.         <xsl:element name="table:table-cell">
  6392.             <xsl:if test="not($style-name = '')">
  6393.                 <xsl:choose>
  6394.                     <xsl:when test="starts-with($style-name, 'val')">
  6395.                         <xsl:attribute name="table:content-validation-name">
  6396.                             <xsl:value-of select="$style-name"/>
  6397.                         </xsl:attribute>
  6398.                     </xsl:when>
  6399.                     <xsl:when test="starts-with($style-name, 'ce')">
  6400.                         <xsl:attribute name="table:style-name">
  6401.                             <xsl:value-of select="$style-name"/>
  6402.                         </xsl:attribute>
  6403.                     </xsl:when>
  6404.                     <xsl:otherwise>
  6405.                         <xsl:attribute name="table:style-name">
  6406.                             <xsl:value-of select="$style-name"/>
  6407.                         </xsl:attribute>
  6408.                     </xsl:otherwise>
  6409.                 </xsl:choose>
  6410.             </xsl:if>
  6411.             <xsl:if test="$c-start < $c-end">
  6412.                 <xsl:attribute name="table:number-columns-repeated">
  6413.                     <xsl:value-of select="$c-end - $c-start + 1"/>
  6414.                 </xsl:attribute>
  6415.             </xsl:if>
  6416.         </xsl:element>
  6417.     </xsl:template>
  6418.     <xsl:template name="condition-row-col-pos-max">
  6419.         <!-- returns the max position of the column or row from condition-pos-str -->
  6420.         <xsl:param name="condition-pos-str"/>
  6421.         <xsl:param name="last-value"/>
  6422.         <xsl:param name="div-value"/>
  6423.         <xsl:variable name="pre-value">
  6424.             <xsl:choose>
  6425.                 <xsl:when test="$div-value = 'R'">
  6426.                     <xsl:value-of select="substring-before(substring-after($condition-pos-str,$div-value),'C')"/>
  6427.                 </xsl:when>
  6428.                 <xsl:otherwise>
  6429.                     <xsl:value-of select="substring-before(substring-after($condition-pos-str,$div-value),',')"/>
  6430.                 </xsl:otherwise>
  6431.             </xsl:choose>
  6432.         </xsl:variable>
  6433.         <xsl:variable name="end-value">
  6434.             <xsl:choose>
  6435.                 <xsl:when test="$last-value < $pre-value">
  6436.                     <xsl:value-of select="$pre-value"/>
  6437.                 </xsl:when>
  6438.                 <xsl:otherwise>
  6439.                     <xsl:value-of select="$last-value"/>
  6440.                 </xsl:otherwise>
  6441.             </xsl:choose>
  6442.         </xsl:variable>
  6443.         <xsl:choose>
  6444.             <xsl:when test="contains($condition-pos-str,$div-value)">
  6445.                 <xsl:call-template name="condition-row-col-pos-max">
  6446.                     <xsl:with-param name="condition-pos-str" select="substring-after($condition-pos-str,$div-value)"/>
  6447.                     <xsl:with-param name="last-value" select="$end-value"/>
  6448.                     <xsl:with-param name="div-value" select="$div-value"/>
  6449.                 </xsl:call-template>
  6450.             </xsl:when>
  6451.             <xsl:otherwise>
  6452.                 <xsl:value-of select="$end-value"/>
  6453.             </xsl:otherwise>
  6454.         </xsl:choose>
  6455.     </xsl:template>
  6456.     <xsl:template name="condition-str">
  6457.         <!-- returns the string of style name of condition-pos-str -->
  6458.         <xsl:param name="param-str"/>
  6459.         <xsl:choose>
  6460.             <xsl:when test="contains($param-str,'(')">
  6461.                 <xsl:call-template name="condition-str">
  6462.                     <xsl:with-param name="param-str" select="substring-after($param-str,'(')"/>
  6463.                 </xsl:call-template>
  6464.             </xsl:when>
  6465.             <xsl:otherwise>
  6466.                 <xsl:value-of select="substring-before($param-str,':')"/>
  6467.             </xsl:otherwise>
  6468.         </xsl:choose>
  6469.     </xsl:template>
  6470.     <xsl:key name="Style" match="/ss:Workbook/ss:Styles/ss:Style" use="@ss:ID"/>
  6471.     <xsl:template name="create-cells">
  6472.         <xsl:param name="row-pos"/>
  6473.         <xsl:param name="expandedColumnCount"/>
  6474.         <xsl:param name="condition-pos-str"/>
  6475.         <xsl:choose>
  6476.             <xsl:when test="ss:Cell">
  6477.                 <xsl:apply-templates select="ss:Cell[1]" mode="selected">
  6478.                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6479.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6480.                     <xsl:with-param name="col-pos-max" select="$expandedColumnCount"/>
  6481.                     <!--
  6482.                         <xsl:call-template name="condition-row-col-pos-max">
  6483.                             <xsl:with-param name="condition-pos-str" select="$condition-pos-str" />
  6484.                             <xsl:with-param name="last-value" select="0" />
  6485.                             <xsl:with-param name="div-value" select="'C'" />
  6486.                         </xsl:call-template>
  6487.                     </xsl:with-param> -->
  6488.                     <xsl:with-param name="col-pos-written" select="0"/>
  6489.                 </xsl:apply-templates>
  6490.             </xsl:when>
  6491.             <xsl:otherwise>
  6492.                 <xsl:variable name="current" select="concat('R',$row-pos,'C')"/>
  6493.                 <xsl:choose>
  6494.                     <xsl:when test="contains($condition-pos-str,$current)">
  6495.                         <xsl:call-template name="create-spanning-cells">
  6496.                             <xsl:with-param name="row-pos" select="$row-pos"/>
  6497.                             <xsl:with-param name="c-start" select="1"/>
  6498.                             <xsl:with-param name="c-end">
  6499.                                 <xsl:call-template name="condition-row-col-pos-max">
  6500.                                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6501.                                     <xsl:with-param name="last-value" select="0"/>
  6502.                                     <xsl:with-param name="div-value" select="'C'"/>
  6503.                                 </xsl:call-template>
  6504.                             </xsl:with-param>
  6505.                             <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6506.                             <xsl:with-param name="col-pos" select="1"/>
  6507.                         </xsl:call-template>
  6508.                     </xsl:when>
  6509.                     <xsl:otherwise>
  6510.                         <!-- OASIS XML does not allow an empty row -->
  6511.                         <xsl:choose>
  6512.                             <xsl:when test="$expandedColumnCount != 0">
  6513.                                 <table:table-cell table:number-columns-repeated="{$expandedColumnCount}"/>
  6514.                             </xsl:when>
  6515.                             <xsl:otherwise>
  6516.                                 <!-- OASIS XML row can not be empty -->
  6517.                                 <table:table-cell table:number-columns-repeated="256"/>
  6518.                             </xsl:otherwise>
  6519.                         </xsl:choose>
  6520.                     </xsl:otherwise>
  6521.                 </xsl:choose>
  6522.             </xsl:otherwise>
  6523.         </xsl:choose>
  6524.     </xsl:template>
  6525.     <xsl:template match="ss:Cell" name="ss:Cell" mode="selected">
  6526.         <!-- Contains the max position of the column or row from the concatenation from
  6527.             x:ConditionalFormatting
  6528.                 and
  6529.             x:DataValidation -->
  6530.         <xsl:param name="condition-pos-str"/>
  6531.         <xsl:param name="col-pos-max"/>
  6532.         <xsl:param name="col-pos-written" select="0"/>
  6533.         <xsl:param name="col-pos-current" select="0"/>
  6534.         <xsl:param name="row-pos"/>
  6535.         <xsl:param name="col-repeated" select="1"/>
  6536.  
  6537.         <!-- The column position of the cell (might jumped by ss:Index) -->
  6538.         <xsl:variable name="col-pos">
  6539.             <xsl:choose>
  6540.                 <xsl:when test="@ss:Index">
  6541.                     <xsl:choose>
  6542.                         <xsl:when test="@ss:MergeAcross">
  6543.                             <xsl:value-of select="@ss:MergeAcross + @ss:Index"/>
  6544.                         </xsl:when>
  6545.                         <xsl:otherwise>
  6546.                             <xsl:value-of select="@ss:Index"/>
  6547.                         </xsl:otherwise>
  6548.                     </xsl:choose>
  6549.                 </xsl:when>
  6550.                 <xsl:otherwise>
  6551.                     <xsl:choose>
  6552.                         <xsl:when test="@ss:MergeAcross">
  6553.                             <xsl:value-of select="1 + @ss:MergeAcross + $col-pos-current"/>
  6554.                         </xsl:when>
  6555.                         <xsl:otherwise>
  6556.                             <xsl:value-of select="1 + $col-pos-current"/>
  6557.                         </xsl:otherwise>
  6558.                     </xsl:choose>
  6559.                 </xsl:otherwise>
  6560.             </xsl:choose>
  6561.         </xsl:variable>
  6562.         <xsl:variable name="nextCell" select="following-sibling::ss:Cell[1]"/>
  6563.         <!-- Multiple empty cells with the same or no style will be moved to one cell with a 'table:number-columns-repeated' attribute -->
  6564.         <xsl:variable name="cell-is-repeatable" select="
  6565.                                                         not(current()/*)
  6566.                                                     and
  6567.                                                         not(current()/text())
  6568.                                                     and
  6569.                                                         (
  6570.                                                             not($nextCell)
  6571.                                                             and $col-pos > $col-pos-written + 1
  6572.                                                         or
  6573.                                                             (
  6574.                                                                 $nextCell
  6575.                                                                 and
  6576.                                                                 not($nextCell/*)
  6577.                                                                 and
  6578.                                                                 not($nextCell/text())
  6579.                                                                 and
  6580.                                                                 (
  6581.                                                                     (current()/@ss:StyleID = $nextCell/@ss:StyleID)
  6582.                                                                     or
  6583.                                                                     (not(current()/@ss:StyleID) and not($nextCell/@ss:StyleID))
  6584.                                                                 )
  6585.                                                                 and
  6586.                                                                 (
  6587.                                                                     not($nextCell/@ss:Index)
  6588.                                                                     or
  6589.                                                                        ($nextCell/@ss:Index = $col-pos + 1)
  6590.                                                                  )
  6591.                                                              )
  6592.                                                          ) "/>
  6593.         <xsl:choose>
  6594.             <!-- Scenario: The missing cells scipped by using the ss:Index attribute will be added -->
  6595.             <xsl:when test="@ss:Index and @ss:Index > $col-pos-written + 1">
  6596.                 <!-- In Open Document nothing comparable to Index exists,
  6597.                     the missing cells might have to be created, if they had content as only style will be repeated-->
  6598.                 <xsl:call-template name="create-spanning-cells">
  6599.                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6600.                     <xsl:with-param name="c-start" select="$col-pos-current + 1"/>
  6601.                     <xsl:with-param name="c-end" select="@ss:Index - 1"/>
  6602.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6603.                 </xsl:call-template>
  6604.                 <xsl:call-template name="ss:Cell">
  6605.                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6606.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6607.                     <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6608.                     <xsl:with-param name="col-pos-written" select="@ss:Index - 1"/>
  6609.                     <xsl:with-param name="col-pos-current" select="$col-pos"/>
  6610.                     <xsl:with-param name="col-repeated" select="$col-repeated"/>
  6611.                 </xsl:call-template>
  6612.             </xsl:when>
  6613.             <!-- Scenario: A sequence of cells can be put together as one cell -->
  6614.             <xsl:when test="$cell-is-repeatable">
  6615.                 <xsl:apply-templates select="$nextCell" mode="selected">
  6616.                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6617.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6618.                     <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6619.                     <xsl:with-param name="col-pos-written" select="$col-pos-written"/>
  6620.                     <xsl:with-param name="col-pos-current" select="$col-pos"/>
  6621.                     <xsl:with-param name="col-repeated" select="$col-repeated"/>
  6622.                 </xsl:apply-templates>
  6623.             </xsl:when>
  6624.             <xsl:otherwise>
  6625.                 <!-- if the cell wasn't repeated yet, created first -->
  6626.                 <xsl:if test="$col-repeated = 1">
  6627.                     <xsl:element name="table:table-cell">
  6628.                         <!-- in case the cell has an Index and is repeatable (s.above) and therefore has not been repeated earlier  -->
  6629.                         <xsl:choose>
  6630.                             <xsl:when test="@ss:MergeAcross">
  6631.                                 <xsl:if test="$col-pos - @ss:MergeAcross > $col-pos-written + 1">
  6632.                                     <xsl:attribute name="table:number-columns-repeated">
  6633.                                         <xsl:value-of select="$col-pos - $col-pos-written"/>
  6634.                                     </xsl:attribute>
  6635.                                 </xsl:if>
  6636.                             </xsl:when>
  6637.                             <xsl:otherwise>
  6638.                                 <xsl:if test="$col-pos > $col-pos-written + 1">
  6639.                                     <xsl:attribute name="table:number-columns-repeated">
  6640.                                         <xsl:value-of select="$col-pos - $col-pos-written"/>
  6641.                                     </xsl:attribute>
  6642.                                 </xsl:if>
  6643.                             </xsl:otherwise>
  6644.                         </xsl:choose>
  6645.                         <xsl:call-template name="create-table-cell-attributes">
  6646.                             <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6647.                             <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6648.                             <xsl:with-param name="col-pos" select="$col-pos"/>
  6649.                             <xsl:with-param name="row-pos" select="$row-pos"/>
  6650.                         </xsl:call-template>
  6651.                         <xsl:call-template name="create-table-cell-content">
  6652.                             <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6653.                             <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6654.                             <xsl:with-param name="col-pos" select="$col-pos"/>
  6655.                             <xsl:with-param name="row-pos" select="$row-pos"/>
  6656.                         </xsl:call-template>
  6657.                     </xsl:element>
  6658.                     <!-- ss:MergeAcross (column spanned) indicates a covered table-cell in Open Document XML-->
  6659.                     <xsl:if test="@ss:MergeAcross">
  6660.                         <xsl:element name="table:covered-table-cell">
  6661.                             <xsl:if test="@ss:MergeAcross > 1">
  6662.                                 <xsl:attribute name="table:number-columns-repeated">
  6663.                                     <xsl:value-of select="@ss:MergeAcross"/>
  6664.                                 </xsl:attribute>
  6665.                             </xsl:if>
  6666.                         </xsl:element>
  6667.                     </xsl:if>
  6668.                 </xsl:if>
  6669.                 <xsl:choose>
  6670.                     <!-- the following block is not used, if the cell had been repeated earlier -->
  6671.                     <xsl:when test="$nextCell and not($cell-is-repeatable and $col-repeated = 1)">
  6672.                         <xsl:choose>
  6673.                             <!-- After cells can not longer be repeated write out the attribute -->
  6674.                             <xsl:when test="not($cell-is-repeatable) and $col-repeated > 1">
  6675.                                 <xsl:attribute name="table:number-columns-repeated">
  6676.                                     <xsl:value-of select="$col-repeated"/>
  6677.                                 </xsl:attribute>
  6678.                             </xsl:when>
  6679.                             <!-- At the end of the row -->
  6680.                             <xsl:when test="not($nextCell)">
  6681.                                 <xsl:if test="../../../x:ConditionalFormatting">
  6682.                                     <!-- at the last position of the Cell tag,inspecting the following cell before condition-row-col-pos-max -->
  6683.                                     <xsl:call-template name="create-spanning-cells">
  6684.                                         <xsl:with-param name="row-pos" select="$row-pos"/>
  6685.                                         <xsl:with-param name="c-start" select="$col-pos"/>
  6686.                                         <xsl:with-param name="c-end" select="$col-pos-max"/>
  6687.                                         <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6688.                                     </xsl:call-template>
  6689.                                 </xsl:if>
  6690.                             </xsl:when>
  6691.                             <!-- If the cells can not be repeated (default) -->
  6692.                             <xsl:when test="not($cell-is-repeatable)">
  6693.                                 <!-- Traverse the following Cell -->
  6694.                                 <xsl:apply-templates select="$nextCell" mode="selected">
  6695.                                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6696.                                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6697.                                     <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6698.                                     <xsl:with-param name="col-pos-written" select="$col-pos"/>
  6699.                                     <xsl:with-param name="col-pos-current" select="$col-pos"/>
  6700.                                 </xsl:apply-templates>
  6701.                             </xsl:when>
  6702.                             <!-- Go on with started repetition -->
  6703.                             <xsl:otherwise>
  6704.                                 <xsl:apply-templates select="$nextCell" mode="selected">
  6705.                                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6706.                                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6707.                                     <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6708.                                     <xsl:with-param name="col-pos-written" select="$col-pos"/>
  6709.                                     <xsl:with-param name="col-pos-current" select="$col-pos"/>
  6710.                                     <xsl:with-param name="col-repeated" select="$col-repeated + 1"/>
  6711.                                 </xsl:apply-templates>
  6712.                             </xsl:otherwise>
  6713.                         </xsl:choose>
  6714.                     </xsl:when>
  6715.                     <xsl:when test="not($nextCell)">
  6716.                         <xsl:choose>
  6717.                             <xsl:when test="$col-repeated = 1 and ($col-pos < $col-pos-max)">
  6718.                                 <table:table-cell table:number-columns-repeated="{$col-pos-max - $col-pos}"/>
  6719.                             </xsl:when>
  6720.                             <xsl:when test="$col-repeated > 1">
  6721.                                 <xsl:attribute name="table:number-columns-repeated">
  6722.                                     <xsl:value-of select="$col-repeated"/>
  6723.                                 </xsl:attribute>
  6724.                             </xsl:when>
  6725.                         </xsl:choose>
  6726.                     </xsl:when>
  6727.                     <xsl:otherwise>
  6728.                         <xsl:apply-templates select="$nextCell" mode="skip">
  6729.                             <xsl:with-param name="row-pos" select="$row-pos"/>
  6730.                             <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6731.                             <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6732.                             <xsl:with-param name="col-pos-written" select="$col-pos"/>
  6733.                         </xsl:apply-templates>
  6734.                     </xsl:otherwise>
  6735.                 </xsl:choose>
  6736.             </xsl:otherwise>
  6737.         </xsl:choose>
  6738.     </xsl:template>
  6739.     <xsl:template match="ss:Cell" mode="skip">
  6740.         <xsl:param name="condition-pos-str"/>
  6741.         <xsl:param name="col-pos-max"/>
  6742.         <xsl:param name="col-pos-written"/>
  6743.         <xsl:param name="row-pos"/>
  6744.  
  6745.         <xsl:variable name="nextCell" select="following-sibling::ss:Cell[1]"/>
  6746.         <!-- Multiple empty cells with the same style will be moved to one cell with a 'table:number-columns-repeated' attribute -->
  6747.         <xsl:variable name="cell-is-repeatable" select="not($nextCell/*) and not($nextCell/text()) and ((current()/@ss:StyleID = $nextCell/@ss:StyleID) or (not(current()/@ss:StyleID) and not($nextCell/@ss:StyleID))) and not($nextCell/@ss:Index)"/>
  6748.         <xsl:choose>
  6749.             <xsl:when test="$cell-is-repeatable">
  6750.                 <xsl:apply-templates select="$nextCell" mode="skip">
  6751.                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6752.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6753.                     <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6754.                     <xsl:with-param name="col-pos-written" select="$col-pos-written + 1"/>
  6755.                 </xsl:apply-templates>
  6756.             </xsl:when>
  6757.             <xsl:otherwise>
  6758.                 <xsl:apply-templates select="$nextCell" mode="selected">
  6759.                     <xsl:with-param name="row-pos" select="$row-pos"/>
  6760.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6761.                     <xsl:with-param name="col-pos-max" select="$col-pos-max"/>
  6762.                     <xsl:with-param name="col-pos-written" select="$col-pos-written + 1"/>
  6763.                     <xsl:with-param name="col-pos-current" select="$col-pos-written + 1"/>
  6764.                 </xsl:apply-templates>
  6765.             </xsl:otherwise>
  6766.         </xsl:choose>
  6767.     </xsl:template>
  6768.     <xsl:template name="create-table-cell-attributes">
  6769.         <xsl:param name="condition-pos-str"/>
  6770.         <xsl:param name="col-pos-max"/>
  6771.         <xsl:param name="col-pos"/>
  6772.         <xsl:param name="row-pos"/>
  6773.  
  6774.         <xsl:choose>
  6775.             <xsl:when test="$condition-pos-str">
  6776.                 <xsl:call-template name="get-condition-dependent-cell-attributes">
  6777.                     <xsl:with-param name="condition-pos-str" select="$condition-pos-str"/>
  6778.                     <xsl:with-param name="current-pos-str" select="concat('R',$row-pos,'C',$col-pos,',')"/>
  6779.                 </xsl:call-template>
  6780.             </xsl:when>
  6781.             <xsl:otherwise>
  6782.                 <xsl:choose>
  6783.                     <xsl:when test="@ss:StyleID">
  6784.                         <xsl:attribute name="table:style-name">
  6785.                             <xsl:value-of select="@ss:StyleID"/>
  6786.                         </xsl:attribute>
  6787.                     </xsl:when>
  6788.                     <!-- inherit style from parent row style-->
  6789.                     <xsl:when test="../@ss:StyleID">
  6790.                         <xsl:attribute name="table:style-name">
  6791.                             <xsl:value-of select="../@ss:StyleID"/>
  6792.                         </xsl:attribute>
  6793.                     </xsl:when>
  6794.                     <!-- if no correspondent column style exisit.. -->
  6795.                     <!-- inherit style from parent table style -->
  6796.                     <xsl:when test="../../@ss:StyleID">
  6797.                         <!-- function to give in col-pos and get back column style  -->
  6798.                         <xsl:variable name="relatedColumnStyle">
  6799.                             <xsl:call-template name="get-related-column-style">
  6800.                                 <!-- the given position of the cell in the table, a column style is searched -->
  6801.                                 <xsl:with-param name="calculatedCellPosition" select="$col-pos" />
  6802.                                 <!-- all columns in XML -->
  6803.                                 <xsl:with-param name="columnXMLNodes" select="../../ss:Column"/>
  6804.                             </xsl:call-template>
  6805.                         </xsl:variable>
  6806.                         <xsl:if test="$relatedColumnStyle = ''">
  6807.                             <xsl:attribute name="table:style-name">
  6808.                                 <xsl:value-of select="../../@ss:StyleID"/>
  6809.                             </xsl:attribute>
  6810.                         </xsl:if>
  6811.                     </xsl:when>
  6812.                 </xsl:choose>
  6813.             </xsl:otherwise>
  6814.         </xsl:choose>
  6815.         <xsl:if test="@ss:MergeAcross or @ss:MergeDown">
  6816.             <xsl:choose>
  6817.                 <xsl:when test="@ss:MergeAcross">
  6818.                     <xsl:attribute name="table:number-columns-spanned">
  6819.                         <xsl:value-of select="@ss:MergeAcross + 1"/>
  6820.                     </xsl:attribute>
  6821.                 </xsl:when>
  6822.                 <xsl:otherwise>
  6823.                     <xsl:attribute name="table:number-columns-spanned">1</xsl:attribute>
  6824.                 </xsl:otherwise>
  6825.             </xsl:choose>
  6826.             <xsl:choose>
  6827.                 <xsl:when test="@ss:MergeDown">
  6828.                     <xsl:attribute name="table:number-rows-spanned">
  6829.                         <xsl:value-of select="@ss:MergeDown+1"/>
  6830.                     </xsl:attribute>
  6831.                 </xsl:when>
  6832.                 <xsl:otherwise>
  6833.                     <xsl:attribute name="table:number-rows-spanned">1</xsl:attribute>
  6834.                 </xsl:otherwise>
  6835.             </xsl:choose>
  6836.         </xsl:if>
  6837.         <xsl:if test="@ss:Formula">
  6838.             <!-- formula translation from Excel to Calc -->
  6839.             <xsl:variable name="calc-formula">
  6840.                 <xsl:call-template name="translate-expression">
  6841.                     <xsl:with-param name="cell-row-pos" select="$row-pos"/>
  6842.                     <xsl:with-param name="cell-column-pos" select="$col-pos"/>
  6843.                     <xsl:with-param name="expression" select="@ss:Formula"/>
  6844.                     <xsl:with-param name="return-value" select="''"/>
  6845.                 </xsl:call-template>
  6846.             </xsl:variable>
  6847.             <xsl:attribute name="table:formula">
  6848.                 <xsl:value-of select="$calc-formula"/>
  6849.             </xsl:attribute>
  6850.         </xsl:if>
  6851.         <xsl:if test="ss:Data">
  6852.             <xsl:variable name="data-format">
  6853.                 <xsl:value-of select="key('Style', @ss:StyleID)/ss:NumberFormat/@ss:Format"/>
  6854.             </xsl:variable>
  6855.             <xsl:choose>
  6856.                 <xsl:when test="ss:Data/@ss:Type = 'Number'">
  6857.                     <xsl:choose>
  6858.                         <xsl:when test="$data-format = 'Percent' or contains( $data-format, '%')">
  6859.                             <xsl:attribute name="office:value-type">percentage</xsl:attribute>
  6860.                         </xsl:when>
  6861.                         <xsl:when test="contains(key('Style', @ss:StyleID)/ss:NumberFormat/@ss:Format, 'Currency')">
  6862.                             <xsl:attribute name="office:value-type">currency</xsl:attribute>
  6863.                         </xsl:when>
  6864.                         <xsl:otherwise>
  6865.                             <xsl:attribute name="office:value-type">float</xsl:attribute>
  6866.                         </xsl:otherwise>
  6867.                     </xsl:choose>
  6868.                     <xsl:attribute name="office:value">
  6869.                         <xsl:value-of select="ss:Data"/>
  6870.                     </xsl:attribute>
  6871.                 </xsl:when>
  6872.                 <xsl:when test="ss:Data/@ss:Type = 'DateTime'">
  6873.                     <xsl:choose>
  6874.                         <xsl:when test="(contains( $data-format, 'Date') or contains($data-format,'y') or contains($data-format,'g') or contains($data-format,'d') or contains($data-format,'e') or starts-with( substring( ss:Data, 11), 'T00:00:00.000' ) ) and (not (contains( $data-format, 'Time') ) )">
  6875.                             <xsl:attribute name="office:value-type">date</xsl:attribute>
  6876.                             <xsl:attribute name="office:date-value">
  6877.                                 <xsl:value-of select="substring-before(ss:Data, 'T')"/>
  6878.                             </xsl:attribute>
  6879.                         </xsl:when>
  6880.                         <xsl:otherwise>
  6881.                             <xsl:attribute name="office:value-type">time</xsl:attribute>
  6882.                             <xsl:attribute name="office:time-value">
  6883.                                 <xsl:value-of select="concat('P',substring(ss:Data, 11, 3), 'H', substring(ss:Data, 15, 2), 'M', substring(ss:Data, 18,2), 'S')"/>
  6884.                             </xsl:attribute>
  6885.                         </xsl:otherwise>
  6886.                     </xsl:choose>
  6887.                 </xsl:when>
  6888.                 <xsl:when test="ss:Data/@ss:Type = 'Boolean'">
  6889.                     <xsl:attribute name="office:value-type">boolean</xsl:attribute>
  6890.                     <xsl:attribute name="office:boolean-value">
  6891.                         <xsl:choose>
  6892.                             <xsl:when test="ss:Data = '1'">true</xsl:when>
  6893.                             <xsl:otherwise>false</xsl:otherwise>
  6894.                         </xsl:choose>
  6895.                     </xsl:attribute>
  6896.                 </xsl:when>
  6897.                 <xsl:when test="ss:Data/@ss:Type = 'String'">
  6898.                     <xsl:attribute name="office:value-type">string</xsl:attribute>
  6899.                 </xsl:when>
  6900.             </xsl:choose>
  6901.         </xsl:if>
  6902.     </xsl:template>
  6903.     <xsl:template name="get-related-column-style">
  6904.         <!-- the given position of the cell in the table, a column style is searched -->
  6905.         <xsl:param name="calculatedCellPosition" />
  6906.         <!-- the current position of the column as XML node -->
  6907.         <xsl:param name="columnXMLPosition" select="1" />
  6908.         <!-- all columns in XML -->
  6909.         <xsl:param name="columnXMLNodes" />
  6910.         <!-- the ending column position of the earlier column style in the table -->
  6911.         <xsl:param name="earlierCalculatedColumnEnd" select="0" />
  6912.  
  6913.         <!-- the current column as XML node -->
  6914.         <xsl:variable name="columnXMLNode" select="$columnXMLNodes[1]" />
  6915.         <xsl:if test="$columnXMLNodes and count($columnXMLNodes) > 0">
  6916.             <!-- the starting column position of the style in the table -->
  6917.             <xsl:variable name="calculatedColumnStart">
  6918.                 <!-- if ss:Index exists, this is the start of the column -->
  6919.                 <xsl:choose>
  6920.                     <xsl:when test="$columnXMLNode/@ss:Index">
  6921.                         <xsl:value-of select="$columnXMLNode/@ss:Index" />
  6922.                     </xsl:when>
  6923.                     <xsl:otherwise>
  6924.                         <xsl:value-of select="$earlierCalculatedColumnEnd + 1" />
  6925.                     </xsl:otherwise>
  6926.                 </xsl:choose>
  6927.             </xsl:variable>
  6928.             <!-- the ending column position of the style in the table -->
  6929.             <xsl:variable name="calculatedColumnEnd">
  6930.                 <xsl:choose>
  6931.                     <xsl:when test="$columnXMLNode/@ss:Span">
  6932.                         <xsl:value-of select="$calculatedColumnStart + $columnXMLNode/@ss:Span" />
  6933.                     </xsl:when>
  6934.                     <xsl:otherwise>
  6935.                         <xsl:value-of select="$calculatedColumnStart" />
  6936.                     </xsl:otherwise>
  6937.                 </xsl:choose>
  6938.             </xsl:variable>
  6939.             <xsl:choose>
  6940.                 <xsl:when test="$calculatedColumnStart >= $calculatedCellPosition and $calculatedCellPosition <= $calculatedColumnEnd">
  6941.                     <xsl:value-of select="$columnXMLNode/@ss:StyleID"/>
  6942.                 </xsl:when>
  6943.                 <xsl:when test="$calculatedColumnEnd <= $calculatedCellPosition">
  6944.                     <xsl:call-template name="get-related-column-style">
  6945.                         <!-- the given position of the cell in the table, a column style is searched -->
  6946.                         <xsl:with-param name="calculatedCellPosition" select="$calculatedCellPosition" />
  6947.                         <!-- all columns in XML -->
  6948.                         <xsl:with-param name="columnXMLNodes" select="$columnXMLNodes[position() != 1]"/>
  6949.                         <!-- the ending column position of the style in the table -->
  6950.                         <xsl:with-param name="earlierCalculatedColumnEnd" select="$calculatedColumnEnd" />
  6951.                     </xsl:call-template>
  6952.                 </xsl:when>
  6953.             </xsl:choose>
  6954.         </xsl:if>
  6955.     </xsl:template>
  6956.  
  6957.     <xsl:template name="create-table-cell-content">
  6958.         <xsl:param name="condition-pos-str"/>
  6959.         <xsl:param name="col-pos-max"/>
  6960.         <xsl:param name="col-pos"/>
  6961.         <xsl:param name="row-pos"/>
  6962.         <xsl:apply-templates select="ss:Comment" mode="body"/>
  6963.         <xsl:if test="ss:Data">
  6964.             <text:p>
  6965.                 <xsl:call-template name="create-data-content">
  6966.                     <xsl:with-param name="style-id" select="@ss:StyleID"/>
  6967.                 </xsl:call-template>
  6968.             </text:p>
  6969.         </xsl:if>
  6970.     </xsl:template>
  6971.     <xsl:template name="create-data-content">
  6972.         <xsl:param name="style-id" select="@ss:StyleID"/>
  6973.         <!-- collect every HTML 3.2 children, which are not empty -->
  6974.         <xsl:variable name="html-children" select="ss:Data/descendant-or-self::*[namespace-uri()='http://www.w3.org/TR/REC-html40'][string-length(text()) != 0]"/>
  6975.         <xsl:choose>
  6976.             <xsl:when test="$html-children and $html-children != ''">
  6977.                 <xsl:for-each select="$html-children">
  6978.                     <text:span text:style-name="{concat($style-id, 'T', count(preceding::ss:Data[child::html:*]), '_', position())}">
  6979.                         <xsl:copy-of select="text()"/>
  6980.                     </text:span>
  6981.                 </xsl:for-each>
  6982.             </xsl:when>
  6983.             <xsl:when test="contains(key('Style', $style-id)/ss:Font/@ss:VerticalAlign, 'script')">
  6984.                 <text:span text:style-name="{concat($style-id, 'T0')}">
  6985.                     <xsl:choose>
  6986.                         <xsl:when test="@ss:HRef">
  6987.                             <text:a xlink:href="{@ss:HRef}">
  6988.                                 <xsl:value-of select="ss:Data"/>
  6989.                             </text:a>
  6990.                         </xsl:when>
  6991.                         <xsl:otherwise>
  6992.                             <xsl:value-of select="ss:Data"/>
  6993.                         </xsl:otherwise>
  6994.                     </xsl:choose>
  6995.                 </text:span>
  6996.             </xsl:when>
  6997.             <xsl:when test="@ss:HRef">
  6998.                 <text:a xlink:href="{@ss:HRef}">
  6999.                     <xsl:value-of select="ss:Data"/>
  7000.                 </text:a>
  7001.             </xsl:when>
  7002.             <xsl:otherwise>
  7003.                 <xsl:value-of select="ss:Data"/>
  7004.             </xsl:otherwise>
  7005.         </xsl:choose>
  7006.     </xsl:template>
  7007.     <xsl:template name="get-condition-dependent-cell-attributes">
  7008.         <xsl:param name="condition-pos-str"/>
  7009.         <xsl:param name="current-pos-str"/>
  7010.         <xsl:variable name="temp-str">
  7011.             <xsl:call-template name="condition-str">
  7012.                 <xsl:with-param name="param-str" select="substring-before($condition-pos-str,$current-pos-str)"/>
  7013.             </xsl:call-template>
  7014.         </xsl:variable>
  7015.         <xsl:variable name="style-name">
  7016.             <xsl:choose>
  7017.                 <xsl:when test="contains($condition-pos-str, $current-pos-str) and starts-with($temp-str, 'c')">
  7018.                     <xsl:value-of select="concat(@ss:StyleID, '-ce', substring-after($temp-str, 'c'))"/>
  7019.                 </xsl:when>
  7020.                 <xsl:otherwise>
  7021.                     <xsl:choose>
  7022.                         <xsl:when test="@ss:StyleID">
  7023.                             <xsl:value-of select="@ss:StyleID"/>
  7024.                         </xsl:when>
  7025.                         <xsl:when test="../@ss:StyleID">
  7026.                             <xsl:value-of select="../@ss:StyleID"/>
  7027.                         </xsl:when>
  7028.                         <xsl:when test="../../@ss:StyleID">
  7029.                             <xsl:value-of select="../../@ss:StyleID"/>
  7030.                         </xsl:when>
  7031.                     </xsl:choose>
  7032.                 </xsl:otherwise>
  7033.             </xsl:choose>
  7034.         </xsl:variable>
  7035.         <xsl:choose>
  7036.             <xsl:when test="starts-with($style-name, 'val')">
  7037.                 <xsl:attribute name="table:content-validation-name">
  7038.                     <xsl:value-of select="$style-name"/>
  7039.                 </xsl:attribute>
  7040.             </xsl:when>
  7041.             <xsl:when test="not($style-name = '')">
  7042.                 <xsl:attribute name="table:style-name">
  7043.                     <xsl:value-of select="$style-name"/>
  7044.                 </xsl:attribute>
  7045.             </xsl:when>
  7046.         </xsl:choose>
  7047.         <!-- maybe multi functions occur at same time in the same Cell, such as ConditionalFormatting and DataValidation -->
  7048.         <xsl:if test="contains($condition-pos-str, $current-pos-str)">
  7049.             <xsl:choose>
  7050.                 <xsl:when test="starts-with($temp-str, 'v')">
  7051.                     <xsl:attribute name="table:content-validation-name">
  7052.                         <xsl:value-of select="concat('val', substring-after($temp-str, 'v'))"/>
  7053.                     </xsl:attribute>
  7054.                 </xsl:when>
  7055.                 <xsl:otherwise>
  7056.                     <xsl:variable name="after-str" select="substring-after($condition-pos-str, $current-pos-str)"/>
  7057.                     <xsl:if test="contains( $after-str, $current-pos-str)">
  7058.                         <xsl:variable name="temp-str-2">
  7059.                             <xsl:call-template name="condition-str">
  7060.                                 <xsl:with-param name="param-str" select="substring-before( $after-str,$current-pos-str)"/>
  7061.                             </xsl:call-template>
  7062.                         </xsl:variable>
  7063.                         <xsl:if test="starts-with( $temp-str-2, 'v')">
  7064.                             <xsl:attribute name="table:content-validation-name">
  7065.                                 <xsl:value-of select="concat('val', substring-after($temp-str-2, 'v'))"/>
  7066.                             </xsl:attribute>
  7067.                         </xsl:if>
  7068.                     </xsl:if>
  7069.                 </xsl:otherwise>
  7070.             </xsl:choose>
  7071.         </xsl:if>
  7072.     </xsl:template>
  7073.     <xsl:template name="validation-row-column-string">
  7074.         <!-- returns a string with structer,including row\column position by extraction from x:DataValidation -->
  7075.         <xsl:param name="last"/>
  7076.         <xsl:param name="total"/>
  7077.         <xsl:param name="index"/>
  7078.         <xsl:variable name="table-pos" select="count(preceding-sibling::ss:Worksheet)+1"/>
  7079.         <xsl:variable name="current">
  7080.             <xsl:call-template name="parse-range">
  7081.                 <xsl:with-param name="range-value" select="./x:DataValidation[position() = $index]/x:Range"/>
  7082.             </xsl:call-template>
  7083.         </xsl:variable>
  7084.         <xsl:variable name="current-value" select="concat('(v',$index,':', $current,');')"/>
  7085.         <xsl:if test="$index < $total">
  7086.             <xsl:call-template name="validation-row-column-string">
  7087.                 <xsl:with-param name="last" select="concat($last, $current-value)"/>
  7088.                 <xsl:with-param name="total" select="$total"/>
  7089.                 <xsl:with-param name="index" select="$index + 1"/>
  7090.             </xsl:call-template>
  7091.         </xsl:if>
  7092.         <xsl:if test="$index = $total">
  7093.             <xsl:value-of select="concat($last, $current-value)"/>
  7094.         </xsl:if>
  7095.     </xsl:template>
  7096.     <xsl:template name="condition-row-column-string">
  7097.         <!-- returns a string with structer,including row\column position by extraction from x:ConditionalFormatting -->
  7098.         <xsl:param name="last"/>
  7099.         <xsl:param name="total"/>
  7100.         <xsl:param name="index"/>
  7101.         <xsl:variable name="table-pos" select="count(preceding-sibling::ss:Worksheet)+1"/>
  7102.         <xsl:variable name="current">
  7103.             <xsl:call-template name="parse-range">
  7104.                 <xsl:with-param name="range-value" select="./x:ConditionalFormatting[position() = $index]/x:Range"/>
  7105.             </xsl:call-template>
  7106.         </xsl:variable>
  7107.         <xsl:variable name="current-value" select="concat('(c',$table-pos,'-',$index,':', $current,');')"/>
  7108.         <xsl:if test="$index < $total">
  7109.             <xsl:call-template name="condition-row-column-string">
  7110.                 <xsl:with-param name="last" select="concat($last, $current-value)"/>
  7111.                 <xsl:with-param name="total" select="$total"/>
  7112.                 <xsl:with-param name="index" select="$index + 1"/>
  7113.             </xsl:call-template>
  7114.         </xsl:if>
  7115.         <xsl:if test="$index = $total">
  7116.             <xsl:value-of select="concat($last, $current-value)"/>
  7117.         </xsl:if>
  7118.     </xsl:template>
  7119.     <xsl:template name="parse-range">
  7120.         <!-- returns a string,input param:the value of x:Range -->
  7121.         <xsl:param name="range-value"/>
  7122.         <xsl:param name="last"/>
  7123.         <xsl:variable name="first-pit">
  7124.             <xsl:choose>
  7125.                 <xsl:when test="contains($range-value,',')">
  7126.                     <xsl:value-of select="substring-before($range-value,',')"/>
  7127.                 </xsl:when>
  7128.                 <xsl:otherwise>
  7129.                     <xsl:value-of select="$range-value"/>
  7130.                 </xsl:otherwise>
  7131.             </xsl:choose>
  7132.         </xsl:variable>
  7133.         <xsl:variable name="current">
  7134.             <xsl:choose>
  7135.                 <xsl:when test="contains($first-pit,':')">
  7136.                     <xsl:variable name="R-start" select="substring-before(substring-after($first-pit,'R'),'C')"/>
  7137.                     <xsl:variable name="C-start" select="substring-before(substring-after($first-pit,'C'),':')"/>
  7138.                     <xsl:variable name="second-pit" select="substring-after($first-pit,':')"/>
  7139.                     <xsl:variable name="R-end" select="substring-before(substring-after($second-pit,'R'),'C')"/>
  7140.                     <xsl:variable name="C-end" select="substring-after($second-pit,'C')"/>
  7141.                     <xsl:variable name="the-str">
  7142.                         <xsl:call-template name="condition-rc-str">
  7143.                             <xsl:with-param name="r-start" select="$R-start"/>
  7144.                             <xsl:with-param name="r-end" select="$R-end"/>
  7145.                             <xsl:with-param name="c-start" select="$C-start"/>
  7146.                             <xsl:with-param name="c-end" select="$C-end"/>
  7147.                             <xsl:with-param name="last" select="''"/>
  7148.                         </xsl:call-template>
  7149.                     </xsl:variable>
  7150.                     <xsl:value-of select="$the-str"/>
  7151.                 </xsl:when>
  7152.                 <xsl:otherwise>
  7153.                     <xsl:value-of select="concat($first-pit,',')"/>
  7154.                 </xsl:otherwise>
  7155.             </xsl:choose>
  7156.         </xsl:variable>
  7157.         <xsl:choose>
  7158.             <xsl:when test="contains($range-value,',')">
  7159.                 <xsl:call-template name="parse-range">
  7160.                     <xsl:with-param name="range-value" select="substring-after($range-value,',')"/>
  7161.                     <xsl:with-param name="last" select="concat($last,$current)"/>
  7162.                 </xsl:call-template>
  7163.             </xsl:when>
  7164.             <xsl:otherwise>
  7165.                 <xsl:value-of select="concat($last,$current)"/>
  7166.             </xsl:otherwise>
  7167.         </xsl:choose>
  7168.     </xsl:template>
  7169.     <xsl:template name="condition-rc-str">
  7170.         <!-- dealing the range of row\column -->
  7171.         <xsl:param name="r-start"/>
  7172.         <xsl:param name="r-end"/>
  7173.         <xsl:param name="c-start"/>
  7174.         <xsl:param name="c-end"/>
  7175.         <xsl:param name="last"/>
  7176.         <xsl:variable name="current">
  7177.             <xsl:call-template name="condition-c-str">
  7178.                 <xsl:with-param name="rc-str" select="concat('R',$r-start)"/>
  7179.                 <xsl:with-param name="start" select="$c-start"/>
  7180.                 <xsl:with-param name="end" select="$c-end"/>
  7181.                 <xsl:with-param name="last" select="''"/>
  7182.             </xsl:call-template>
  7183.         </xsl:variable>
  7184.         <xsl:if test="$r-start < $r-end">
  7185.             <xsl:call-template name="condition-rc-str">
  7186.                 <xsl:with-param name="r-start" select="$r-start + 1"/>
  7187.                 <xsl:with-param name="r-end" select="$r-end"/>
  7188.                 <xsl:with-param name="c-start" select="$c-start"/>
  7189.                 <xsl:with-param name="c-end" select="$c-end"/>
  7190.                 <xsl:with-param name="last" select="concat($last,$current)"/>
  7191.             </xsl:call-template>
  7192.         </xsl:if>
  7193.         <xsl:if test="$r-start = $r-end">
  7194.             <xsl:value-of select="concat($last,$current)"/>
  7195.         </xsl:if>
  7196.     </xsl:template>
  7197.     <xsl:template name="condition-c-str">
  7198.         <!-- return value for the template condition-rc-str -->
  7199.         <xsl:param name="rc-str"/>
  7200.         <xsl:param name="start"/>
  7201.         <xsl:param name="end"/>
  7202.         <xsl:param name="last"/>
  7203.         <xsl:variable name="current" select="concat($rc-str,'C',$start,',')"/>
  7204.         <xsl:if test="$start < $end">
  7205.             <xsl:call-template name="condition-c-str">
  7206.                 <xsl:with-param name="rc-str" select="$rc-str"/>
  7207.                 <xsl:with-param name="start" select="$start + 1"/>
  7208.                 <xsl:with-param name="end" select="$end"/>
  7209.                 <xsl:with-param name="last" select="concat($last,$current)"/>
  7210.             </xsl:call-template>
  7211.         </xsl:if>
  7212.         <xsl:if test="$start = $end">
  7213.             <xsl:value-of select="concat($last,$current)"/>
  7214.         </xsl:if>
  7215.     </xsl:template>
  7216.     <xsl:template match="ss:Data">
  7217.         <xsl:for-each select="descendant-or-self::*[namespace-uri()='http://www.w3.org/TR/REC-html40'][string-length(text()) != 0]">
  7218.             <style:style style:name="{concat(ancestor::ss:Cell/@ss:StyleID,'T',count(preceding::ss:Data[child::html:*]), '_', position())}" style:family="text">
  7219.                 <xsl:element name="style:text-properties">
  7220.                     <xsl:if test="ancestor-or-self::html:Font/@html:Face">
  7221.                         <xsl:attribute name="style:font-name">
  7222.                             <xsl:value-of select="ancestor-or-self::html:Font/@html:Face"/>
  7223.                         </xsl:attribute>
  7224.                     </xsl:if>
  7225.                     <xsl:if test="ancestor-or-self::html:Font/@html:Size">
  7226.                         <xsl:attribute name="fo:font-size">
  7227.                             <xsl:value-of select="concat(ancestor-or-self::html:Font/@html:Size,'pt')"/>
  7228.                         </xsl:attribute>
  7229.                         <xsl:attribute name="style:font-size-asian">
  7230.                             <xsl:value-of select="concat(ancestor-or-self::html:Font/@html:Size,'pt')"/>
  7231.                         </xsl:attribute>
  7232.                         <xsl:attribute name="style:font-size-complex">
  7233.                             <xsl:value-of select="concat(ancestor-or-self::html:Font/@html:Size,'pt')"/>
  7234.                         </xsl:attribute>
  7235.                     </xsl:if>
  7236.                     <xsl:if test="ancestor-or-self::html:Font/@html:Color">
  7237.                         <xsl:attribute name="fo:color">
  7238.                             <xsl:value-of select="ancestor-or-self::html:Font/@html:Color"/>
  7239.                         </xsl:attribute>
  7240.                     </xsl:if>
  7241.                     <xsl:if test="ancestor-or-self::html:B">
  7242.                         <xsl:attribute name="fo:font-weight">bold</xsl:attribute>
  7243.                         <xsl:attribute name="style:font-weight-asian">bold</xsl:attribute>
  7244.                         <xsl:attribute name="style:font-weight-complex">bold</xsl:attribute>
  7245.                     </xsl:if>
  7246.                     <xsl:if test="ancestor-or-self::html:I">
  7247.                         <xsl:attribute name="fo:font-style">italic</xsl:attribute>
  7248.                         <xsl:attribute name="style:font-style-asian">italic</xsl:attribute>
  7249.                         <xsl:attribute name="style:font-style-complex">italic</xsl:attribute>
  7250.                     </xsl:if>
  7251.                     <xsl:if test="ancestor-or-self::html:U">
  7252.                         <xsl:attribute name="style:text-underline-type">single</xsl:attribute>
  7253.                     </xsl:if>
  7254.                     <xsl:if test="ancestor-or-self::html:S">
  7255.                         <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  7256.                     </xsl:if>
  7257.                     <xsl:if test="ancestor-or-self::html:Sup">
  7258.                         <xsl:attribute name="style:text-position">33% 58%</xsl:attribute>
  7259.                     </xsl:if>
  7260.                     <xsl:if test="ancestor-or-self::html:Sub">
  7261.                         <xsl:attribute name="style:text-position">-33% 58%</xsl:attribute>
  7262.                     </xsl:if>
  7263.                 </xsl:element>
  7264.             </style:style>
  7265.         </xsl:for-each>
  7266.     </xsl:template>
  7267.     <xsl:template name="get-pos-content">
  7268.         <xsl:param name="content"/>
  7269.         <xsl:param name="pos"/>
  7270.         <xsl:choose>
  7271.             <xsl:when test="$pos = 'left'">
  7272.                 <xsl:choose>
  7273.                     <xsl:when test="contains($content,'&C')">
  7274.                         <xsl:value-of select="substring-before( substring-after( $content, '&L'), '&C')"/>
  7275.                     </xsl:when>
  7276.                     <xsl:when test="contains($content,'&R')">
  7277.                         <xsl:value-of select="substring-before( substring-after( $content, '&L'), '&R')"/>
  7278.                     </xsl:when>
  7279.                     <xsl:when test="contains($content,'&L')">
  7280.                         <xsl:value-of select="substring-after( $content, '&L')"/>
  7281.                     </xsl:when>
  7282.                     <xsl:otherwise/>
  7283.                 </xsl:choose>
  7284.             </xsl:when>
  7285.             <xsl:when test="$pos = 'center'">
  7286.                 <xsl:choose>
  7287.                     <xsl:when test="contains($content,'&R')">
  7288.                         <xsl:value-of select="substring-before( substring-after( $content, '&C'), '&R')"/>
  7289.                     </xsl:when>
  7290.                     <xsl:when test="contains($content,'&C')">
  7291.                         <xsl:value-of select="substring-after( $content, '&C')"/>
  7292.                     </xsl:when>
  7293.                     <xsl:when test="contains($content,'&L')"/>
  7294.                     <xsl:otherwise>
  7295.                         <xsl:value-of select="$content"/>
  7296.                     </xsl:otherwise>
  7297.                 </xsl:choose>
  7298.             </xsl:when>
  7299.             <xsl:when test="$pos = 'right'">
  7300.                 <xsl:value-of select="substring-after( $content, '&R')"/>
  7301.             </xsl:when>
  7302.         </xsl:choose>
  7303.     </xsl:template>
  7304.     <xsl:template match="@x:Data">
  7305.         <xsl:variable name="style-name-header">
  7306.             <xsl:value-of select="concat(ancestor::ss:Worksheet/@ss:Name, substring(name(..),1,1))"/>
  7307.         </xsl:variable>
  7308.         <xsl:variable name="left-style-data">
  7309.             <xsl:call-template name="get-pos-content">
  7310.                 <xsl:with-param name="content" select="."/>
  7311.                 <xsl:with-param name="pos" select="'left'"/>
  7312.             </xsl:call-template>
  7313.         </xsl:variable>
  7314.         <xsl:if test="string-length($left-style-data)>0 and contains($left-style-data,'&')">
  7315.             <xsl:call-template name="create-header-footer-style">
  7316.                 <xsl:with-param name="style-name-header" select="concat($style-name-header,'L')"/>
  7317.                 <xsl:with-param name="style-data" select="$left-style-data"/>
  7318.                 <xsl:with-param name="index" select="0"/>
  7319.                 <xsl:with-param name="current-pos" select="1"/>
  7320.             </xsl:call-template>
  7321.         </xsl:if>
  7322.         <xsl:variable name="center-style-data">
  7323.             <xsl:call-template name="get-pos-content">
  7324.                 <xsl:with-param name="content" select="."/>
  7325.                 <xsl:with-param name="pos" select="'center'"/>
  7326.             </xsl:call-template>
  7327.         </xsl:variable>
  7328.         <xsl:if test="string-length($center-style-data)>0 and contains($center-style-data,'&')">
  7329.             <xsl:call-template name="create-header-footer-style">
  7330.                 <xsl:with-param name="style-name-header" select="concat($style-name-header,'C')"/>
  7331.                 <xsl:with-param name="style-data" select="$center-style-data"/>
  7332.                 <xsl:with-param name="index" select="0"/>
  7333.                 <xsl:with-param name="current-pos" select="1"/>
  7334.             </xsl:call-template>
  7335.         </xsl:if>
  7336.         <xsl:variable name="right-style-data">
  7337.             <xsl:call-template name="get-pos-content">
  7338.                 <xsl:with-param name="content" select="."/>
  7339.                 <xsl:with-param name="pos" select="'right'"/>
  7340.             </xsl:call-template>
  7341.         </xsl:variable>
  7342.         <xsl:if test="string-length($right-style-data)>0 and contains($right-style-data,'&')">
  7343.             <xsl:call-template name="create-header-footer-style">
  7344.                 <xsl:with-param name="style-name-header" select="concat($style-name-header,'R')"/>
  7345.                 <xsl:with-param name="style-data" select="$right-style-data"/>
  7346.                 <xsl:with-param name="index" select="0"/>
  7347.                 <xsl:with-param name="current-pos" select="1"/>
  7348.             </xsl:call-template>
  7349.         </xsl:if>
  7350.     </xsl:template>
  7351.     <xsl:template name="create-header-footer-style">
  7352.         <xsl:param name="style-name-header"/>
  7353.         <xsl:param name="style-data"/>
  7354.         <xsl:param name="index"/>
  7355.         <xsl:param name="current-pos"/>
  7356.         <xsl:variable name="current-style-data">
  7357.             <xsl:value-of select="substring($style-data,$current-pos)"/>
  7358.         </xsl:variable>
  7359.         <xsl:choose>
  7360.             <xsl:when test="starts-with($current-style-data,'&D') or starts-with($current-style-data,'&T') or starts-with($current-style-data,'&P') or starts-with($current-style-data,'&N') or starts-with($current-style-data,'&A') or starts-with($current-style-data,'&F') or starts-with($current-style-data,'&Z')">
  7361.                 <xsl:call-template name="create-header-footer-style">
  7362.                     <xsl:with-param name="style-name-header" select="$style-name-header"/>
  7363.                     <xsl:with-param name="style-data" select="$style-data"/>
  7364.                     <xsl:with-param name="index" select="$index"/>
  7365.                     <xsl:with-param name="current-pos" select="$current-pos +2"/>
  7366.                 </xsl:call-template>
  7367.             </xsl:when>
  7368.             <xsl:when test="starts-with($current-style-data,'&')">
  7369.                 <xsl:element name="style:style">
  7370.                     <xsl:attribute name="style:name">
  7371.                         <xsl:value-of select="concat($style-name-header,$index)"/>
  7372.                     </xsl:attribute>
  7373.                     <xsl:attribute name="style:family">text</xsl:attribute>
  7374.                     <xsl:element name="style:text-properties">
  7375.                         <xsl:call-template name="process-header-footer-style-properties">
  7376.                             <xsl:with-param name="style-data" select="$style-data"/>
  7377.                             <xsl:with-param name="current-pos" select="$current-pos"/>
  7378.                         </xsl:call-template>
  7379.                     </xsl:element>
  7380.                 </xsl:element>
  7381.                 <xsl:variable name="next-style-header-pos">
  7382.                     <xsl:call-template name="get-current-content-pos">
  7383.                         <xsl:with-param name="style-data" select="$style-data"/>
  7384.                         <xsl:with-param name="current-pos" select="$current-pos"/>
  7385.                     </xsl:call-template>
  7386.                 </xsl:variable>
  7387.                 <xsl:call-template name="create-header-footer-style">
  7388.                     <xsl:with-param name="style-name-header" select="$style-name-header"/>
  7389.                     <xsl:with-param name="style-data" select="$style-data"/>
  7390.                     <xsl:with-param name="index" select="$index+1"/>
  7391.                     <xsl:with-param name="current-pos" select="$next-style-header-pos"/>
  7392.                 </xsl:call-template>
  7393.             </xsl:when>
  7394.             <xsl:when test="contains($current-style-data,'&')">
  7395.                 <xsl:variable name="temp" select="substring-before($current-style-data,'&')"/>
  7396.                 <xsl:call-template name="create-header-footer-style">
  7397.                     <xsl:with-param name="style-name-header" select="$style-name-header"/>
  7398.                     <xsl:with-param name="style-data" select="$style-data"/>
  7399.                     <xsl:with-param name="index" select="$index"/>
  7400.                     <xsl:with-param name="current-pos" select="string-length($temp)+$current-pos"/>
  7401.                 </xsl:call-template>
  7402.             </xsl:when>
  7403.             <xsl:otherwise/>
  7404.         </xsl:choose>
  7405.     </xsl:template>
  7406.     <xsl:template name="process-header-footer-style-properties">
  7407.         <xsl:param name="style-data"/>
  7408.         <xsl:param name="current-pos"/>
  7409.         <xsl:variable name="current-style-data">
  7410.             <xsl:value-of select="substring($style-data,$current-pos)"/>
  7411.         </xsl:variable>
  7412.         <xsl:choose>
  7413.             <!-- stack operations necessary -->
  7414.             <xsl:when test="starts-with($current-style-data,'&"')">
  7415.                 <xsl:attribute name="style:font-name">
  7416.                     <xsl:value-of select="substring-before(substring-after($current-style-data,'&"'),',')"/>
  7417.                 </xsl:attribute>
  7418.                 <xsl:if test="contains(substring-before(substring-after($current-style-data,','),'"'),'Bold')">
  7419.                     <xsl:attribute name="fo:font-weight">bold</xsl:attribute>
  7420.                     <xsl:attribute name="style:font-weight-asian">bold</xsl:attribute>
  7421.                     <xsl:attribute name="style:font-weight-complex">bold</xsl:attribute>
  7422.                 </xsl:if>
  7423.                 <xsl:if test="contains(substring-before(substring-after($current-style-data,','),'"'),'Italic')">
  7424.                     <xsl:attribute name="fo:font-style">italic</xsl:attribute>
  7425.                     <xsl:attribute name="style:font-style-asian">italic</xsl:attribute>
  7426.                     <xsl:attribute name="style:font-style-complex">italic</xsl:attribute>
  7427.                 </xsl:if>
  7428.                 <xsl:variable name="temp" select="substring-before(substring($style-data,$current-pos+2),'"')"/>
  7429.                 <xsl:call-template name="process-header-footer-style-properties">
  7430.                     <xsl:with-param name="style-data" select="$style-data"/>
  7431.                     <xsl:with-param name="current-pos" select="string-length($temp)+$current-pos+3"/>
  7432.                 </xsl:call-template>
  7433.             </xsl:when>
  7434.             <xsl:when test="starts-with($current-style-data,'&0') or starts-with($current-style-data,'&1') or starts-with($current-style-data,'&2') or starts-with($current-style-data,'&3') or starts-with($current-style-data,'&4') or starts-with($current-style-data,'&5') or starts-with($current-style-data,'&6') or starts-with($current-style-data,'&7') or starts-with($current-style-data,'&8') or starts-with($current-style-data,'&9')">
  7435.                 <xsl:variable name="font-size-length">
  7436.                     <xsl:call-template name="get-digit-length">
  7437.                         <xsl:with-param name="complexive-string" select="substring-after($current-style-data,'&')"/>
  7438.                     </xsl:call-template>
  7439.                 </xsl:variable>
  7440.                 <xsl:attribute name="fo:font-size">
  7441.                     <xsl:value-of select="concat(substring($current-style-data,2,$font-size-length),'pt')"/>
  7442.                 </xsl:attribute>
  7443.                 <xsl:call-template name="process-header-footer-style-properties">
  7444.                     <xsl:with-param name="style-data" select="$style-data"/>
  7445.                     <xsl:with-param name="current-pos" select="$current-pos + 1 + $font-size-length"/>
  7446.                 </xsl:call-template>
  7447.             </xsl:when>
  7448.             <!-- dont' consider tangled or adjoined '&X' and '&Y', '&U' & '&E', processing-check is necessary, too complex. :( -->
  7449.             <xsl:when test="starts-with($current-style-data,'&X')">
  7450.                 <xsl:variable name="superscript-count-before">
  7451.                     <xsl:call-template name="get-substyle-count-in-data">
  7452.                         <xsl:with-param name="style-data" select="substring($style-data,1,$current-pos)"/>
  7453.                         <xsl:with-param name="substyle" select="'&X'"/>
  7454.                         <xsl:with-param name="count" select="0"/>
  7455.                     </xsl:call-template>
  7456.                 </xsl:variable>
  7457.                 <xsl:if test="$superscript-count-before mod 2 = 0">
  7458.                     <xsl:attribute name="style:text-position">33% 58%</xsl:attribute>
  7459.                 </xsl:if>
  7460.                 <xsl:call-template name="process-header-footer-style-properties">
  7461.                     <xsl:with-param name="style-data" select="$style-data"/>
  7462.                     <xsl:with-param name="current-pos" select="$current-pos + 2"/>
  7463.                 </xsl:call-template>
  7464.             </xsl:when>
  7465.             <xsl:when test="starts-with($current-style-data,'&B')">
  7466.                 <xsl:variable name="subscript-count-before">
  7467.                     <xsl:call-template name="get-substyle-count-in-data">
  7468.                         <xsl:with-param name="style-data" select="substring($style-data,1,$current-pos)"/>
  7469.                         <xsl:with-param name="substyle" select="'&B'"/>
  7470.                         <xsl:with-param name="count" select="0"/>
  7471.                     </xsl:call-template>
  7472.                 </xsl:variable>
  7473.                 <xsl:if test="$subscript-count-before mod 2 = 0">
  7474.                     <xsl:attribute name="fo:font-weight">bold</xsl:attribute>
  7475.                     <xsl:attribute name="style:font-weight-asian">bold</xsl:attribute>
  7476.                     <xsl:attribute name="style:font-weight-complex">bold</xsl:attribute>
  7477.                 </xsl:if>
  7478.                 <xsl:call-template name="process-header-footer-style-properties">
  7479.                     <xsl:with-param name="style-data" select="$style-data"/>
  7480.                     <xsl:with-param name="current-pos" select="$current-pos + 2"/>
  7481.                 </xsl:call-template>
  7482.             </xsl:when>
  7483.             <xsl:when test="starts-with($current-style-data,'&Y')">
  7484.                 <xsl:variable name="subscript-count-before">
  7485.                     <xsl:call-template name="get-substyle-count-in-data">
  7486.                         <xsl:with-param name="style-data" select="substring($style-data,1,$current-pos)"/>
  7487.                         <xsl:with-param name="substyle" select="'&Y'"/>
  7488.                         <xsl:with-param name="count" select="0"/>
  7489.                     </xsl:call-template>
  7490.                 </xsl:variable>
  7491.                 <xsl:if test="$subscript-count-before mod 2 = 0">
  7492.                     <xsl:attribute name="style:text-position">-33% 58%</xsl:attribute>
  7493.                 </xsl:if>
  7494.                 <xsl:call-template name="process-header-footer-style-properties">
  7495.                     <xsl:with-param name="style-data" select="$style-data"/>
  7496.                     <xsl:with-param name="current-pos" select="$current-pos + 2"/>
  7497.                 </xsl:call-template>
  7498.             </xsl:when>
  7499.             <xsl:when test="starts-with($current-style-data,'&S')">
  7500.                 <xsl:variable name="strikethrough-count-before">
  7501.                     <xsl:call-template name="get-substyle-count-in-data">
  7502.                         <xsl:with-param name="style-data" select="substring($style-data,1,$current-pos)"/>
  7503.                         <xsl:with-param name="substyle" select="'&S'"/>
  7504.                         <xsl:with-param name="count" select="0"/>
  7505.                     </xsl:call-template>
  7506.                 </xsl:variable>
  7507.                 <xsl:if test="$strikethrough-count-before mod 2 = 0">
  7508.                     <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  7509.                 </xsl:if>
  7510.                 <xsl:call-template name="process-header-footer-style-properties">
  7511.                     <xsl:with-param name="style-data" select="$style-data"/>
  7512.                     <xsl:with-param name="current-pos" select="$current-pos + 2"/>
  7513.                 </xsl:call-template>
  7514.             </xsl:when>
  7515.             <xsl:when test="starts-with($current-style-data,'&U')">
  7516.                 <xsl:variable name="single-underline-count-before">
  7517.                     <xsl:call-template name="get-substyle-count-in-data">
  7518.                         <xsl:with-param name="style-data" select="substring($style-data,1,$current-pos)"/>
  7519.                         <xsl:with-param name="substyle" select="'&U'"/>
  7520.                         <xsl:with-param name="count" select="0"/>
  7521.                     </xsl:call-template>
  7522.                 </xsl:variable>
  7523.                 <xsl:if test="$single-underline-count-before mod 2 = 0">
  7524.                     <xsl:attribute name="style:text-underline-type">single</xsl:attribute>
  7525.                 </xsl:if>
  7526.                 <xsl:call-template name="process-header-footer-style-properties">
  7527.                     <xsl:with-param name="style-data" select="$style-data"/>
  7528.                     <xsl:with-param name="current-pos" select="$current-pos + 2"/>
  7529.                 </xsl:call-template>
  7530.             </xsl:when>
  7531.             <xsl:when test="starts-with($current-style-data,'&E')">
  7532.                 <xsl:variable name="double-underline-count-before">
  7533.                     <xsl:call-template name="get-substyle-count-in-data">
  7534.                         <xsl:with-param name="style-data" select="substring($style-data,1,$current-pos)"/>
  7535.                         <xsl:with-param name="substyle" select="'&E'"/>
  7536.                         <xsl:with-param name="count" select="0"/>
  7537.                     </xsl:call-template>
  7538.                 </xsl:variable>
  7539.                 <xsl:if test="$double-underline-count-before mod 2 = 0">
  7540.                     <xsl:attribute name="style:text-underline-type">double</xsl:attribute>
  7541.                 </xsl:if>
  7542.                 <xsl:call-template name="process-header-footer-style-properties">
  7543.                     <xsl:with-param name="style-data" select="$style-data"/>
  7544.                     <xsl:with-param name="current-pos" select="$current-pos + 2"/>
  7545.                 </xsl:call-template>
  7546.             </xsl:when>
  7547.             <xsl:otherwise/>
  7548.         </xsl:choose>
  7549.     </xsl:template>
  7550.     <xsl:template name="get-substyle-count-in-data">
  7551.         <xsl:param name="style-data"/>
  7552.         <xsl:param name="substyle"/>
  7553.         <xsl:param name="count"/>
  7554.         <xsl:choose>
  7555.             <xsl:when test="contains($style-data,$substyle)">
  7556.                 <xsl:call-template name="get-substyle-count-in-data">
  7557.                     <xsl:with-param name="style-data" select="substring-after($style-data,$substyle)"/>
  7558.                     <xsl:with-param name="substyle" select="$substyle"/>
  7559.                     <xsl:with-param name="count" select="$count+1"/>
  7560.                 </xsl:call-template>
  7561.             </xsl:when>
  7562.             <xsl:otherwise>
  7563.                 <xsl:value-of select="$count"/>
  7564.             </xsl:otherwise>
  7565.         </xsl:choose>
  7566.     </xsl:template>
  7567.     <xsl:template name="get-current-content-pos">
  7568.         <xsl:param name="style-data"/>
  7569.         <xsl:param name="current-pos"/>
  7570.         <xsl:variable name="current-style-data">
  7571.             <xsl:value-of select="substring($style-data,$current-pos)"/>
  7572.         </xsl:variable>
  7573.         <xsl:choose>
  7574.             <xsl:when test="starts-with($current-style-data,'&X') or starts-with($current-style-data,'&Y') or starts-with($current-style-data,'&S') or starts-with($current-style-data,'&U') or starts-with($current-style-data,'&E') or starts-with($current-style-data,'&B')">
  7575.                 <xsl:call-template name="get-current-content-pos">
  7576.                     <xsl:with-param name="style-data" select="$style-data"/>
  7577.                     <xsl:with-param name="current-pos" select="$current-pos+2"/>
  7578.                 </xsl:call-template>
  7579.             </xsl:when>
  7580.             <xsl:when test="starts-with($current-style-data,'&0') or starts-with($current-style-data,'&1') or starts-with($current-style-data,'&2') or starts-with($current-style-data,'&3') or starts-with($current-style-data,'&4') or starts-with($current-style-data,'&5') or starts-with($current-style-data,'&6') or starts-with($current-style-data,'&7') or starts-with($current-style-data,'&8') or starts-with($current-style-data,'&9')">
  7581.                 <xsl:variable name="font-size-length">
  7582.                     <xsl:call-template name="get-digit-length">
  7583.                         <xsl:with-param name="complexive-string" select="substring-after($current-style-data,'&')"/>
  7584.                     </xsl:call-template>
  7585.                 </xsl:variable>
  7586.                 <xsl:call-template name="get-current-content-pos">
  7587.                     <xsl:with-param name="style-data" select="$style-data"/>
  7588.                     <xsl:with-param name="current-pos" select="$current-pos+1+$font-size-length"/>
  7589.                 </xsl:call-template>
  7590.             </xsl:when>
  7591.             <xsl:when test="starts-with($current-style-data,'&"')">
  7592.                 <xsl:variable name="temp" select="substring-before(substring($style-data,$current-pos+2),'"')"/>
  7593.                 <xsl:call-template name="get-current-content-pos">
  7594.                     <xsl:with-param name="style-data" select="$style-data"/>
  7595.                     <xsl:with-param name="current-pos" select="string-length($temp)+$current-pos+3"/>
  7596.                 </xsl:call-template>
  7597.             </xsl:when>
  7598.             <xsl:otherwise>
  7599.                 <xsl:value-of select="$current-pos"/>
  7600.             </xsl:otherwise>
  7601.         </xsl:choose>
  7602.     </xsl:template>
  7603.     <!-- OASIS OpenDocument Format change:
  7604.         Excel   "=RC4*6"
  7605.         OOoXML "=$D22*6"
  7606.      OASIS XML "oooc:=[.$D22]*6" -->
  7607.     <xsl:template name="translate-expression">
  7608.         <!--  return position or range for formula or other -->
  7609.         <xsl:param name="cell-row-pos"/>
  7610.         <!-- the position in row (vertical) of cell -->
  7611.         <xsl:param name="cell-column-pos"/>
  7612.         <!-- the position in column (horizontal of cell -->
  7613.         <xsl:param name="expression"/>
  7614.         <!-- recomposed expression containing cell positions after every conversion -->
  7615.         <xsl:param name="is-range-mode" select="false()"/>
  7616.         <!-- as mode changes a '[.' resp. ']' is written out  -->
  7617.         <xsl:param name="return-value"/>
  7618.         <!-- expression of table:cell-range-address is different than formula (e.g. no prefix)  -->
  7619.         <xsl:param name="isRangeAddress"/>
  7620.         <!-- determines if the currently processed expression is relative -->
  7621.         <xsl:param name="isRelative" select="false()" />
  7622.  
  7623.         <!-- value to be given out later -->
  7624.         <!-- to judge whether this input expression contains any cell position to convert -->
  7625.         <xsl:variable name="temp-range">
  7626.             <xsl:choose>
  7627.                 <xsl:when test="$expression != ''">
  7628.                     <xsl:call-template name="parse-range-name">
  7629.                         <xsl:with-param name="expression" select="$expression"/>
  7630.                         <xsl:with-param name="return-value" select="''"/>
  7631.                     </xsl:call-template>
  7632.                 </xsl:when>
  7633.                 <xsl:otherwise>
  7634.                     <xsl:value-of select="''"/>
  7635.                 </xsl:otherwise>
  7636.             </xsl:choose>
  7637.         </xsl:variable>
  7638.         <!-- if $range-type = 1, then range is representing a sheet, function's name or separated symbol, but not cell position,
  7639.              or if $range-type = 2, range should be handled because it contains certain cell position.
  7640.              The first character marks the type of that expression. -->
  7641.         <xsl:variable name="range-type">
  7642.             <xsl:choose>
  7643.                 <xsl:when test="substring($temp-range, 1, 1) = '1'">
  7644.                     <xsl:value-of select="1"/>
  7645.                 </xsl:when>
  7646.                 <xsl:when test="substring($temp-range, 1, 1) = '2'">
  7647.                     <xsl:value-of select="2"/>
  7648.                 </xsl:when>
  7649.                 <xsl:otherwise>
  7650.                     <xsl:value-of select="2"/>
  7651.                 </xsl:otherwise>
  7652.             </xsl:choose>
  7653.         </xsl:variable>
  7654.         <!-- remove that added range type token -->
  7655.         <xsl:variable name="current-range">
  7656.             <xsl:value-of select="substring($temp-range, 2)"/>
  7657.         </xsl:variable>
  7658.         <xsl:choose>
  7659.             <xsl:when test="$range-type = 1">
  7660.                 <!-- Nothing to convert, so just join the front and behind strings. -->
  7661.                 <xsl:call-template name="translate-expression">
  7662.                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  7663.                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  7664.                     <xsl:with-param name="expression">
  7665.                         <!-- get current converting position from $temp-token or $current-range, then join the expression. -->
  7666.                         <xsl:choose>
  7667.                             <xsl:when test="contains($current-range, '#$')">
  7668.                                 <!-- because of recomposing of string, the $current-range may not be the pit
  7669.                             of $expression, so the char #$ should not be used for nominal -->
  7670.                                 <xsl:variable name="temp-token">
  7671.                                     <xsl:choose>
  7672.                                         <xsl:when test="contains($current-range, '\')">
  7673.                                             <xsl:value-of select="concat(']', substring-after($current-range, '#$'), "'")"/>
  7674.                                         </xsl:when>
  7675.                                         <xsl:otherwise>
  7676.                                             <xsl:value-of select="substring-after($current-range, '#$')"/>
  7677.                                         </xsl:otherwise>
  7678.                                     </xsl:choose>
  7679.                                 </xsl:variable>
  7680.                                 <xsl:value-of select="substring-after($expression, $temp-token)"/>
  7681.                             </xsl:when>
  7682.                             <xsl:otherwise>
  7683.                                 <xsl:value-of select="substring-after($expression, $current-range)"/>
  7684.                             </xsl:otherwise>
  7685.                         </xsl:choose>
  7686.                     </xsl:with-param>
  7687.                     <xsl:with-param name="return-value">
  7688.                         <!-- react on range mode change (when to insert closing ']' or in case of '!' change the mode to RANGE and create open '[' -->
  7689.                         <xsl:choose>
  7690.                             <xsl:when test="$current-range = '=' and $return-value = '' and not($isRangeAddress)">
  7691.                                 <xsl:text>oooc:=</xsl:text>
  7692.                             </xsl:when>
  7693.                             <xsl:when test="contains($current-range, '!') and not($isRangeAddress)">
  7694.                                 <xsl:value-of select="concat($return-value, '[', $current-range)"/>
  7695.                             </xsl:when>
  7696.                             <xsl:otherwise>
  7697.                                 <xsl:choose>
  7698.                                     <xsl:when test="$is-range-mode = 'true' and $current-range != ':' and not($isRangeAddress)">
  7699.                                         <xsl:value-of select="concat($return-value, ']', substring-before($expression, $current-range), $current-range)"/>
  7700.                                     </xsl:when>
  7701.                                     <xsl:otherwise>
  7702.                                         <xsl:value-of select="concat($return-value, substring-before($expression, $current-range), $current-range)"/>
  7703.                                     </xsl:otherwise>
  7704.                                 </xsl:choose>
  7705.                             </xsl:otherwise>
  7706.                         </xsl:choose>
  7707.                     </xsl:with-param>
  7708.                     <xsl:with-param name="is-range-mode">
  7709.                         <xsl:choose>
  7710.                             <!-- ! is the separator of worksheet and range
  7711.                                  : is the separator for a cell range -->
  7712.                             <xsl:when test="contains($current-range, '!') or $current-range = ':'">
  7713.                                 <xsl:value-of select="true()"/>
  7714.                             </xsl:when>
  7715.                             <xsl:otherwise>
  7716.                                 <xsl:value-of select="false()"/>
  7717.                             </xsl:otherwise>
  7718.                         </xsl:choose>
  7719.                     </xsl:with-param>
  7720.                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  7721.                 </xsl:call-template>
  7722.             </xsl:when>
  7723.             <xsl:otherwise>
  7724.                 <!-- types of range to handle in $current-range, i.e. the cell position expression to convert
  7725.                     1: special cell including row and column; e.g. R4C5
  7726.                     2: whole row; e.g. R3
  7727.                     3: whole column; e.g. C5
  7728.                     4: other name not for cell or row/column; e.g. RANDOM() or something unknown
  7729.                 -->
  7730.                 <xsl:variable name="handle-type">
  7731.                     <xsl:choose>
  7732.                         <xsl:when test="starts-with($current-range, 'R')">
  7733.                             <!-- It's type 1 or type 2 or 4/unknown cell position. -->
  7734.                             <xsl:choose>
  7735.                                 <xsl:when test="contains($current-range, 'C')">
  7736.                                     <!-- It's type 1, specifying the cell position or 4/unknown -->
  7737.                                     <xsl:variable name="part-type-r">
  7738.                                         <xsl:call-template name="handle-type-number">
  7739.                                             <xsl:with-param name="t-part" select="substring-before( substring-after($current-range, 'R'), 'C')"/>
  7740.                                         </xsl:call-template>
  7741.                                     </xsl:variable>
  7742.                                     <xsl:variable name="part-type-c">
  7743.                                         <xsl:call-template name="handle-type-number">
  7744.                                             <xsl:with-param name="t-part" select="substring-after($current-range, 'C')"/>
  7745.                                         </xsl:call-template>
  7746.                                     </xsl:variable>
  7747.                                     <xsl:choose>
  7748.                                         <xsl:when test="($part-type-r = 1) and ($part-type-c = 1)">
  7749.                                             <xsl:value-of select="1"/>
  7750.                                         </xsl:when>
  7751.                                         <xsl:otherwise>
  7752.                                             <xsl:value-of select="4"/>
  7753.                                         </xsl:otherwise>
  7754.                                     </xsl:choose>
  7755.                                 </xsl:when>
  7756.                                 <xsl:otherwise>
  7757.                                     <!-- It's type 2 specifying the cell position, or 4/unknown. -->
  7758.                                     <xsl:variable name="part-type">
  7759.                                         <xsl:call-template name="handle-type-number">
  7760.                                             <xsl:with-param name="t-part" select="substring-after($current-range, 'R')"/>
  7761.                                         </xsl:call-template>
  7762.                                     </xsl:variable>
  7763.                                     <xsl:choose>
  7764.                                         <xsl:when test="$part-type = 1">
  7765.                                             <xsl:value-of select="2"/>
  7766.                                         </xsl:when>
  7767.                                         <xsl:when test="$part-type = 2">
  7768.                                             <xsl:value-of select="4"/>
  7769.                                         </xsl:when>
  7770.                                         <xsl:otherwise>
  7771.                                             <xsl:value-of select="4"/>
  7772.                                         </xsl:otherwise>
  7773.                                     </xsl:choose>
  7774.                                 </xsl:otherwise>
  7775.                             </xsl:choose>
  7776.                         </xsl:when>
  7777.                         <xsl:when test="starts-with($current-range, 'C')">
  7778.                             <!-- It's type 3 of cell position, or 4/unknown -->
  7779.                             <xsl:variable name="part-type">
  7780.                                 <xsl:call-template name="handle-type-number">
  7781.                                     <xsl:with-param name="t-part" select="substring-after($current-range, 'C')"/>
  7782.                                 </xsl:call-template>
  7783.                             </xsl:variable>
  7784.                             <xsl:choose>
  7785.                                 <xsl:when test="$part-type = 1">
  7786.                                     <xsl:value-of select="3"/>
  7787.                                 </xsl:when>
  7788.                                 <xsl:when test="$part-type = 2">
  7789.                                     <xsl:value-of select="4"/>
  7790.                                 </xsl:when>
  7791.                                 <xsl:otherwise>
  7792.                                     <xsl:value-of select="4"/>
  7793.                                 </xsl:otherwise>
  7794.                             </xsl:choose>
  7795.                         </xsl:when>
  7796.                         <xsl:otherwise>
  7797.                             <!-- It's type 4, not cell position -->
  7798.                             <xsl:value-of select="4"/>
  7799.                         </xsl:otherwise>
  7800.                     </xsl:choose>
  7801.                 </xsl:variable>
  7802.                 <!-- Start to convert that cell position expression, that cell position unit -->
  7803.                 <xsl:choose>
  7804.                     <xsl:when test="$handle-type = 1">
  7805.                         <!-- It's type 1, e.g. R1C2 -->
  7806.                         <!-- process the row part -->
  7807.                         <xsl:variable name="after-R">
  7808.                             <xsl:value-of select="substring(substring-after($current-range,'R'),1,1)"/>
  7809.                         </xsl:variable>
  7810.                         <xsl:choose>
  7811.                             <!-- found one cell unit -->
  7812.                             <xsl:when test="$after-R='C' or $after-R='[' or $after-R='0' or $after-R='1' or $after-R='2' or $after-R='3' or $after-R='4' or $after-R='5' or $after-R='6' or $after-R='7' or $after-R='8' or $after-R='9'">
  7813.                                 <xsl:variable name="row-pos">
  7814.                                     <xsl:choose>
  7815.                                         <xsl:when test="$after-R='['">
  7816.                                             <xsl:value-of select="$cell-row-pos+substring-before( substring-after($current-range,'R['),']')"/>
  7817.                                         </xsl:when>
  7818.                                         <xsl:when test="$after-R='C'">
  7819.                                             <xsl:value-of select="$cell-row-pos"/>
  7820.                                         </xsl:when>
  7821.                                         <xsl:otherwise>
  7822.                                             <xsl:value-of select="substring-before(substring-after($current-range,'R'),'C')"/>
  7823.                                         </xsl:otherwise>
  7824.                                     </xsl:choose>
  7825.                                 </xsl:variable>
  7826.                                 <xsl:variable name="row-pos-style">
  7827.                                     <xsl:choose>
  7828.                                         <xsl:when test="$after-R='[' or $after-R='C'">relative</xsl:when>
  7829.                                         <xsl:otherwise>absolute</xsl:otherwise>
  7830.                                     </xsl:choose>
  7831.                                 </xsl:variable>
  7832.                                 <!-- process the column part -->
  7833.                                 <xsl:variable name="after-C">
  7834.                                     <xsl:value-of select="substring(substring-after(substring-after($current-range,'R'),'C'),1,1)"/>
  7835.                                 </xsl:variable>
  7836.                                 <xsl:variable name="column-digit-length">
  7837.                                     <xsl:choose>
  7838.                                         <xsl:when test="$after-C='0' or $after-C='1' or $after-C='2' or $after-C='3' or $after-C='4' or $after-C='5' or $after-C='6' or $after-C='7' or $after-C='8' or $after-C='9'">
  7839.                                             <xsl:call-template name="get-digit-length">
  7840.                                                 <xsl:with-param name="complexive-string" select="substring-after(substring-after($current-range,'R'),'C')"/>
  7841.                                             </xsl:call-template>
  7842.                                         </xsl:when>
  7843.                                     </xsl:choose>
  7844.                                 </xsl:variable>
  7845.                                 <xsl:variable name="column-pos">
  7846.                                     <xsl:choose>
  7847.                                         <xsl:when test="$after-C='['">
  7848.                                             <xsl:value-of select="$cell-column-pos + substring-before(substring-after(substring-after($current-range,'R'),'C['),']')"/>
  7849.                                         </xsl:when>
  7850.                                         <xsl:when test="$after-C='0' or $after-C='1' or $after-C='2' or $after-C='3' or $after-C='4' or $after-C='5' or $after-C='6' or $after-C='7' or $after-C='8' or $after-C='9'">
  7851.                                             <xsl:value-of select="substring(substring-after(substring-after($current-range,'R'),'C'),1,$column-digit-length)"/>
  7852.                                         </xsl:when>
  7853.                                         <xsl:otherwise>
  7854.                                             <xsl:value-of select="$cell-column-pos"/>
  7855.                                         </xsl:otherwise>
  7856.                                     </xsl:choose>
  7857.                                 </xsl:variable>
  7858.                                 <xsl:variable name="column-pos-style">
  7859.                                     <xsl:choose>
  7860.                                         <xsl:when test="$after-C='0' or $after-C='1' or $after-C='2' or $after-C='3' or $after-C='4' or $after-C='5' or $after-C='6' or $after-C='7' or $after-C='8' or $after-C='9'">absolute</xsl:when>
  7861.                                         <xsl:otherwise>relative</xsl:otherwise>
  7862.                                     </xsl:choose>
  7863.                                 </xsl:variable>
  7864.                                 <xsl:variable name="trans-unit">
  7865.                                     <xsl:call-template name="translate-unit">
  7866.                                         <xsl:with-param name="column-number" select="$column-pos"/>
  7867.                                         <xsl:with-param name="row-number" select="$row-pos"/>
  7868.                                         <xsl:with-param name="column-pos-style" select="$column-pos-style"/>
  7869.                                         <xsl:with-param name="row-pos-style" select="$row-pos-style"/>
  7870.                                     </xsl:call-template>
  7871.                                 </xsl:variable>
  7872.                                 <xsl:variable name="name-unit" select="concat(substring-before($expression, $current-range), $trans-unit)"/>
  7873.                                 <xsl:call-template name="translate-expression">
  7874.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  7875.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  7876.                                     <xsl:with-param name="expression" select="substring-after($expression, $current-range)"/>
  7877.                                     <xsl:with-param name="return-value">
  7878.                                         <xsl:choose>
  7879.                                             <xsl:when test="$is-range-mode = 'true'">
  7880.                                                 <xsl:value-of select="concat($return-value, $name-unit)"/>
  7881.                                             </xsl:when>
  7882.                                             <xsl:otherwise>
  7883.                                                 <xsl:value-of select="concat($return-value, '[.', $name-unit)"/>
  7884.                                             </xsl:otherwise>
  7885.                                         </xsl:choose>
  7886.                                     </xsl:with-param>
  7887.                                     <xsl:with-param name="is-range-mode" select="true()"/>
  7888.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  7889.                                 </xsl:call-template>
  7890.                             </xsl:when>
  7891.                             <xsl:otherwise>
  7892.                                 <xsl:variable name="name-unit" select="concat(substring-before($expression, $current-range), translate( substring-before(substring-after($expression, '('),'R'),',!', ';.'))"/>
  7893.                                 <xsl:call-template name="translate-expression">
  7894.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  7895.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  7896.                                     <xsl:with-param name="expression" select="substring-after($current-range,'R')"/>
  7897.                                     <xsl:with-param name="return-value">
  7898.                                         <xsl:choose>
  7899.                                             <xsl:when test="$is-range-mode = 'true'">
  7900.                                                 <xsl:value-of select="concat($return-value, $name-unit)"/>
  7901.                                             </xsl:when>
  7902.                                             <xsl:otherwise>
  7903.                                                 <xsl:value-of select="concat($return-value, '[.', $name-unit)"/>
  7904.                                             </xsl:otherwise>
  7905.                                         </xsl:choose>
  7906.                                     </xsl:with-param>
  7907.                                     <xsl:with-param name="is-range-mode" select="true()"/>
  7908.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  7909.                                 </xsl:call-template>
  7910.                             </xsl:otherwise>
  7911.                         </xsl:choose>
  7912.                     </xsl:when>
  7913.                     <xsl:when test="$handle-type = 2">
  7914.                         <!-- It's type 2, e.g. R3 -->
  7915.                         <!-- process the range only including a whole row -->
  7916.                         <xsl:variable name="after-R">
  7917.                             <xsl:value-of select="substring(substring-after($current-range,'R'),1,1)"/>
  7918.                         </xsl:variable>
  7919.                         <xsl:choose>
  7920.                             <xsl:when test="$after-R='[' or $after-R='0' or $after-R='1' or $after-R='2' or $after-R='3' or $after-R='4' or $after-R='5' or $after-R='6' or $after-R='7' or $after-R='8' or $after-R='9'">
  7921.                                 <xsl:variable name="row-number">
  7922.                                     <xsl:choose>
  7923.                                         <xsl:when test="$after-R = '['">
  7924.                                             <xsl:value-of select="substring-before(substring-after($current-range, 'R['), ']')"/>
  7925.                                         </xsl:when>
  7926.                                         <xsl:otherwise>
  7927.                                             <xsl:value-of select="substring-after($current-range, 'R')"/>
  7928.                                         </xsl:otherwise>
  7929.                                     </xsl:choose>
  7930.                                 </xsl:variable>
  7931.                                 <xsl:variable name="row-pos">
  7932.                                     <xsl:choose>
  7933.                                         <xsl:when test="$after-R='['">
  7934.                                             <xsl:value-of select="$cell-row-pos + $row-number"/>
  7935.                                         </xsl:when>
  7936.                                         <xsl:when test="$after-R='0' or $after-R='1' or $after-R='2' or $after-R='3' or $after-R='4' or $after-R='5' or $after-R='6' or $after-R='7' or $after-R='8' or $after-R='9'">
  7937.                                             <xsl:value-of select="$row-number"/>
  7938.                                         </xsl:when>
  7939.                                         <xsl:otherwise>
  7940.                                             <xsl:value-of select="$cell-row-pos"/>
  7941.                                         </xsl:otherwise>
  7942.                                     </xsl:choose>
  7943.                                 </xsl:variable>
  7944.                                 <xsl:variable name="trans-unit1">
  7945.                                     <xsl:call-template name="translate-unit">
  7946.                                         <xsl:with-param name="column-number" select="1"/>
  7947.                                         <xsl:with-param name="row-number" select="$row-pos"/>
  7948.                                         <xsl:with-param name="column-pos-style" select="'relative'"/>
  7949.                                         <xsl:with-param name="row-pos-style" select="'relative'"/>
  7950.                                     </xsl:call-template>
  7951.                                 </xsl:variable>
  7952.                                 <xsl:variable name="trans-unit2">
  7953.                                     <xsl:call-template name="translate-unit">
  7954.                                         <xsl:with-param name="column-number" select="256"/>
  7955.                                         <xsl:with-param name="row-number" select="$row-pos"/>
  7956.                                         <xsl:with-param name="column-pos-style" select="'relative'"/>
  7957.                                         <xsl:with-param name="row-pos-style" select="'relative'"/>
  7958.                                     </xsl:call-template>
  7959.                                 </xsl:variable>
  7960.                                 <xsl:variable name="name-unit" select="concat(substring-before($expression, $current-range), $trans-unit1, ':', $trans-unit2)"/>
  7961.                                 <xsl:call-template name="translate-expression">
  7962.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  7963.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  7964.                                     <xsl:with-param name="expression" select="substring-after($expression, $current-range)"/>
  7965.                                     <xsl:with-param name="return-value">
  7966.                                         <xsl:choose>
  7967.                                             <xsl:when test="$is-range-mode = 'true'">
  7968.                                                 <xsl:value-of select="concat($return-value, $name-unit)"/>
  7969.                                             </xsl:when>
  7970.                                             <xsl:otherwise>
  7971.                                                 <xsl:value-of select="concat($return-value, '[.', $name-unit)"/>
  7972.                                             </xsl:otherwise>
  7973.                                         </xsl:choose>
  7974.                                     </xsl:with-param>
  7975.                                     <xsl:with-param name="is-range-mode" select="true()"/>
  7976.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  7977.                                 </xsl:call-template>
  7978.                             </xsl:when>
  7979.                             <xsl:otherwise>
  7980.                                 <xsl:variable name="name-unit" select="concat(substring-before($expression, $current-range), translate( substring-before($current-range,'R'),',!', ';.'),'R')"/>
  7981.                                 <xsl:call-template name="translate-expression">
  7982.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  7983.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  7984.                                     <xsl:with-param name="expression" select="substring-after($current-range,'R')"/>
  7985.                                     <xsl:with-param name="return-value">
  7986.                                         <xsl:choose>
  7987.                                             <xsl:when test="$is-range-mode = 'true'">
  7988.                                                 <xsl:value-of select="concat($return-value, $name-unit)"/>
  7989.                                             </xsl:when>
  7990.                                             <xsl:otherwise>
  7991.                                                 <xsl:value-of select="concat($return-value, '[.', $name-unit)"/>
  7992.                                             </xsl:otherwise>
  7993.                                         </xsl:choose>
  7994.                                     </xsl:with-param>
  7995.                                     <xsl:with-param name="is-range-mode" select="true()"/>
  7996.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  7997.                                 </xsl:call-template>
  7998.                             </xsl:otherwise>
  7999.                         </xsl:choose>
  8000.                     </xsl:when>
  8001.                     <xsl:when test="$handle-type = 3">
  8002.                         <!-- It's type 3, e.g. C4 -->
  8003.                         <!-- process the range only including a whole column -->
  8004.                         <xsl:variable name="after-C">
  8005.                             <xsl:value-of select="substring(substring-after($current-range,'C'),1,1)"/>
  8006.                         </xsl:variable>
  8007.                         <xsl:choose>
  8008.                             <xsl:when test="$after-C='[' or $after-C='0' or $after-C='1' or $after-C='2' or $after-C='3' or $after-C='4' or $after-C='5' or $after-C='6' or $after-C='7' or $after-C='8' or $after-C='9'">
  8009.                                 <xsl:variable name="column-number">
  8010.                                     <xsl:choose>
  8011.                                         <xsl:when test="$after-C = '['">
  8012.                                             <xsl:value-of select="substring-before(substring-after($current-range, 'C['), ']')"/>
  8013.                                         </xsl:when>
  8014.                                         <xsl:otherwise>
  8015.                                             <xsl:value-of select="substring-after($current-range, 'C')"/>
  8016.                                         </xsl:otherwise>
  8017.                                     </xsl:choose>
  8018.                                 </xsl:variable>
  8019.                                 <xsl:variable name="column-pos">
  8020.                                     <xsl:choose>
  8021.                                         <xsl:when test="$after-C='['">
  8022.                                             <xsl:value-of select="$cell-column-pos + $column-number"/>
  8023.                                         </xsl:when>
  8024.                                         <xsl:when test="$after-C='0' or $after-C='1' or $after-C='2' or $after-C='3' or $after-C='4' or $after-C='5' or $after-C='6' or $after-C='7' or $after-C='8' or $after-C='9'">
  8025.                                             <xsl:value-of select="$column-number"/>
  8026.                                         </xsl:when>
  8027.                                         <xsl:otherwise>
  8028.                                             <xsl:value-of select="$cell-column-pos"/>
  8029.                                         </xsl:otherwise>
  8030.                                     </xsl:choose>
  8031.                                 </xsl:variable>
  8032.                                 <xsl:variable name="trans-unit1">
  8033.                                     <xsl:call-template name="translate-unit">
  8034.                                         <xsl:with-param name="column-number" select="$column-pos"/>
  8035.                                         <xsl:with-param name="row-number" select="1"/>
  8036.                                         <xsl:with-param name="column-pos-style" select="'relative'"/>
  8037.                                         <xsl:with-param name="row-pos-style" select="'relative'"/>
  8038.                                     </xsl:call-template>
  8039.                                 </xsl:variable>
  8040.                                 <xsl:variable name="trans-unit2">
  8041.                                     <xsl:call-template name="translate-unit">
  8042.                                         <xsl:with-param name="column-number" select="$column-pos"/>
  8043.                                         <xsl:with-param name="row-number" select="65565"/>
  8044.                                         <xsl:with-param name="column-pos-style" select="'relative'"/>
  8045.                                         <xsl:with-param name="row-pos-style" select="'relative'"/>
  8046.                                     </xsl:call-template>
  8047.                                 </xsl:variable>
  8048.                                 <xsl:variable name="name-unit" select="concat(substring-before($expression, $current-range), $trans-unit1, ':', $trans-unit2)"/>
  8049.                                 <xsl:call-template name="translate-expression">
  8050.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  8051.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  8052.                                     <xsl:with-param name="expression" select="substring-after($expression, $current-range)"/>
  8053.                                     <xsl:with-param name="return-value">
  8054.                                         <xsl:choose>
  8055.                                             <xsl:when test="$is-range-mode = 'true'">
  8056.                                                 <xsl:value-of select="concat($return-value, $name-unit)"/>
  8057.                                             </xsl:when>
  8058.                                             <xsl:otherwise>
  8059.                                                 <xsl:value-of select="concat($return-value, '[.', $name-unit)"/>
  8060.                                             </xsl:otherwise>
  8061.                                         </xsl:choose>
  8062.                                     </xsl:with-param>
  8063.                                     <xsl:with-param name="is-range-mode" select="true()"/>
  8064.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  8065.                                 </xsl:call-template>
  8066.                             </xsl:when>
  8067.                             <xsl:otherwise>
  8068.                                 <xsl:variable name="name-unit" select="concat(substring-before($expression, $current-range), translate( substring-before($current-range,'C'),',!', ';.'),'C')"/>
  8069.                                 <xsl:call-template name="translate-expression">
  8070.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  8071.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  8072.                                     <xsl:with-param name="expression" select="substring-after($current-range,'C')"/>
  8073.                                     <xsl:with-param name="return-value">
  8074.                                         <xsl:choose>
  8075.                                             <xsl:when test="$is-range-mode = 'true'">
  8076.                                                 <xsl:value-of select="concat($return-value, $name-unit)"/>
  8077.                                             </xsl:when>
  8078.                                             <xsl:otherwise>
  8079.                                                 <xsl:value-of select="concat($return-value, '[.', $name-unit)"/>
  8080.                                             </xsl:otherwise>
  8081.                                         </xsl:choose>
  8082.                                     </xsl:with-param>
  8083.                                     <xsl:with-param name="is-range-mode" select="true()"/>
  8084.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  8085.                                 </xsl:call-template>
  8086.                             </xsl:otherwise>
  8087.                         </xsl:choose>
  8088.                     </xsl:when>
  8089.                     <xsl:otherwise>
  8090.                         <!-- It's unknown, so just jump over it -->
  8091.                         <xsl:variable name="next-pit" select="substring-after($expression, $current-range)"/>
  8092.                         <xsl:choose>
  8093.                             <xsl:when test="contains($next-pit, '+') or contains($next-pit, '-') or contains($next-pit, '*') or contains($next-pit, '/') or contains($next-pit, ')') or contains($next-pit, '^') or contains($next-pit, ':') or contains($next-pit, '"') or contains($next-pit, ';') or contains($next-pit, ',') or contains($next-pit, '[')">
  8094.                                 <xsl:call-template name="translate-expression">
  8095.                                     <xsl:with-param name="cell-row-pos" select="$cell-row-pos"/>
  8096.                                     <xsl:with-param name="cell-column-pos" select="$cell-column-pos"/>
  8097.                                     <xsl:with-param name="expression" select="substring-after($expression, $current-range)"/>
  8098.                                     <xsl:with-param name="return-value" select="concat($return-value, substring-before($expression, $current-range), $current-range)"/>
  8099.                                     <xsl:with-param name="is-range-mode" select="false()"/>
  8100.                                     <xsl:with-param name="isRangeAddress" select="$isRangeAddress"/>
  8101.                                 </xsl:call-template>
  8102.                             </xsl:when>
  8103.                             <xsl:otherwise>
  8104.                                 <!-- return the final range or formula -->
  8105.                                 <xsl:choose>
  8106.                                     <!-- in case the closing bracket of the range wasn't set, do it now  -->
  8107.                                     <xsl:when test="$is-range-mode = 'true' and $current-range = ''">
  8108.                                         <xsl:value-of select="translate( concat($return-value, ']'),',!', ';.')"/>
  8109.                                     </xsl:when>
  8110.                                     <xsl:otherwise>
  8111.                                         <xsl:value-of select="translate( concat($return-value, substring-before($expression, $current-range), $current-range),',!', ';.')"/>
  8112.                                     </xsl:otherwise>
  8113.                                 </xsl:choose>
  8114.                             </xsl:otherwise>
  8115.                         </xsl:choose>
  8116.                     </xsl:otherwise>
  8117.                 </xsl:choose>
  8118.             </xsl:otherwise>
  8119.         </xsl:choose>
  8120.     </xsl:template>
  8121.     <xsl:template name="parse-range-name">
  8122.         <!-- return the string or name for next handle. the type 1 is names of function, sheet, special separated symbol, not to parse as range; type 2 is the range including R/C to be parsed -->
  8123.         <xsl:param name="expression"/>
  8124.         <xsl:param name="return-value"/>
  8125.         <xsl:variable name="first-one" select="substring($expression,1,1)"/>
  8126.         <xsl:choose>
  8127.             <xsl:when test="$first-one = '='">
  8128.                 <xsl:choose>
  8129.                     <xsl:when test="string-length(normalize-space($return-value)) > 0">
  8130.                         <xsl:value-of select="concat('2', $return-value)"/>
  8131.                     </xsl:when>
  8132.                     <xsl:otherwise>
  8133.                         <xsl:text>1=</xsl:text>
  8134.                     </xsl:otherwise>
  8135.                 </xsl:choose>
  8136.             </xsl:when>
  8137.             <xsl:when test="$first-one='(' or $first-one='!' or $first-one='&'">
  8138.                 <xsl:value-of select="concat('1', $return-value, $first-one)"/>
  8139.             </xsl:when>
  8140.             <xsl:when test="$first-one='['">
  8141.                 <xsl:choose>
  8142.                     <xsl:when test="starts-with(substring-after($expression, ']'), 'C')">
  8143.                         <xsl:call-template name="parse-range-name">
  8144.                             <xsl:with-param name="expression" select="substring-after($expression, ']')"/>
  8145.                             <xsl:with-param name="return-value" select="concat($return-value, substring-before($expression, ']'), ']')"/>
  8146.                         </xsl:call-template>
  8147.                     </xsl:when>
  8148.                     <xsl:when test="contains(substring-before($expression, ']'), '.') and contains(substring-after($expression, ']'), '!')">
  8149.                         <xsl:value-of select="concat('1', "'", substring-before(substring-after($expression, '['), ']'), "'", '#$', substring-before(substring-after($expression, ']'), '!'))"/>
  8150.                     </xsl:when>
  8151.                     <xsl:otherwise>
  8152.                         <xsl:value-of select="concat('2', $return-value, substring-before($expression, ']'), ']')"/>
  8153.                     </xsl:otherwise>
  8154.                 </xsl:choose>
  8155.             </xsl:when>
  8156.             <xsl:when test="$first-one='"'">
  8157.                 <xsl:value-of select="concat('1', $first-one, substring-before(substring-after($expression, '"'), '"'), '"')"/>
  8158.             </xsl:when>
  8159.             <xsl:when test="$first-one="'"">
  8160.                 <!-- here the string "'" represents a char '  -->
  8161.                 <xsl:variable name="str-in" select="substring-before(substring-after($expression, "'"), "'")"/>
  8162.                 <xsl:choose>
  8163.                     <!-- for file path transformation -->
  8164.                     <xsl:when test="contains($str-in, '\') and contains($str-in, '[') and contains($str-in, ']')">
  8165.                         <xsl:variable name="first-pos" select="substring-before($str-in, '[')"/>
  8166.                         <xsl:variable name="second-pos" select="substring-before(substring-after($str-in, '['), ']')"/>
  8167.                         <xsl:variable name="third-pos" select="substring-after($str-in, ']')"/>
  8168.                         <xsl:value-of select="concat('1', "'", $first-pos, $second-pos, "'", '#$', $third-pos)"/>
  8169.                     </xsl:when>
  8170.                     <xsl:otherwise>
  8171.                         <xsl:value-of select="concat('1', "'", $str-in, "'")"/>
  8172.                     </xsl:otherwise>
  8173.                 </xsl:choose>
  8174.             </xsl:when>
  8175.             <xsl:when test="$first-one='+' or $first-one='-' or $first-one='*' or $first-one='/' or $first-one=')' or $first-one='^' or $first-one=':' or $first-one='"' or $first-one=';' or $first-one=',' or $first-one='>' or $first-one='<'">
  8176.                 <xsl:choose>
  8177.                     <xsl:when test="$return-value = ''">
  8178.                         <xsl:value-of select="concat('1', $first-one)"/>
  8179.                     </xsl:when>
  8180.                     <xsl:otherwise>
  8181.                         <xsl:value-of select="concat('2', $return-value)"/>
  8182.                     </xsl:otherwise>
  8183.                 </xsl:choose>
  8184.             </xsl:when>
  8185.             <xsl:otherwise>
  8186.                 <xsl:choose>
  8187.                     <xsl:when test="$expression = ''">
  8188.                         <xsl:value-of select="concat('2', $return-value)"/>
  8189.                     </xsl:when>
  8190.                     <xsl:otherwise>
  8191.                         <xsl:call-template name="parse-range-name">
  8192.                             <xsl:with-param name="expression" select="substring($expression, 2, string-length($expression)-1)"/>
  8193.                             <xsl:with-param name="return-value" select="concat($return-value, substring($expression, 1, 1))"/>
  8194.                         </xsl:call-template>
  8195.                     </xsl:otherwise>
  8196.                 </xsl:choose>
  8197.             </xsl:otherwise>
  8198.         </xsl:choose>
  8199.     </xsl:template>
  8200.     <xsl:template name="handle-type-number">
  8201.         <!-- to handle the part between R and C, or after C in range string in translate-expression. return type: 1: number or cell range; 2: other, not for next step -->
  8202.         <xsl:param name="t-part"/>
  8203.         <xsl:choose>
  8204.             <xsl:when test="starts-with($t-part, '[')">
  8205.                 <xsl:variable name="tt-str" select="substring-before( substring-after( $t-part, '['), ']')"/>
  8206.                 <xsl:choose>
  8207.                     <xsl:when test="($tt-str < 0) or ($tt-str > 0) or ($tt-str = 0)">
  8208.                         <xsl:value-of select="1"/>
  8209.                     </xsl:when>
  8210.                     <xsl:otherwise>
  8211.                         <xsl:value-of select="2"/>
  8212.                     </xsl:otherwise>
  8213.                 </xsl:choose>
  8214.             </xsl:when>
  8215.             <xsl:when test="($t-part < 0) or ($t-part > 0) or ($t-part = 0)">
  8216.                 <xsl:value-of select="1"/>
  8217.             </xsl:when>
  8218.             <xsl:when test="$t-part = ''">
  8219.                 <xsl:value-of select="1"/>
  8220.             </xsl:when>
  8221.             <xsl:otherwise>
  8222.                 <xsl:value-of select="2"/>
  8223.             </xsl:otherwise>
  8224.         </xsl:choose>
  8225.     </xsl:template>
  8226.     <xsl:template name="translate-unit">
  8227.         <!-- convert cell position expression unit, R1C1, R3, C4 -->
  8228.         <xsl:param name="column-number"/>
  8229.         <xsl:param name="row-number"/>
  8230.         <xsl:param name="column-pos-style"/>
  8231.         <xsl:param name="row-pos-style"/>
  8232.         <xsl:variable name="column-number1">
  8233.             <xsl:value-of select="floor( $column-number div 26 )"/>
  8234.         </xsl:variable>
  8235.         <xsl:variable name="column-number2">
  8236.             <xsl:value-of select="$column-number mod 26"/>
  8237.         </xsl:variable>
  8238.         <xsl:variable name="column-character1">
  8239.             <xsl:call-template name="number-to-character">
  8240.                 <xsl:with-param name="number" select="$column-number1"/>
  8241.             </xsl:call-template>
  8242.         </xsl:variable>
  8243.         <xsl:variable name="column-character2">
  8244.             <xsl:call-template name="number-to-character">
  8245.                 <xsl:with-param name="number" select="$column-number2"/>
  8246.             </xsl:call-template>
  8247.         </xsl:variable>
  8248.         <!-- position styles are 'absolute' or 'relative', -->
  8249.         <xsl:choose>
  8250.             <xsl:when test="$column-pos-style = 'absolute'">
  8251.                 <xsl:value-of select="concat( '$', $column-character1, $column-character2)"/>
  8252.             </xsl:when>
  8253.             <xsl:otherwise>
  8254.                 <xsl:value-of select="concat( $column-character1, $column-character2)"/>
  8255.             </xsl:otherwise>
  8256.         </xsl:choose>
  8257.         <xsl:choose>
  8258.             <xsl:when test="$row-pos-style ='absolute'">
  8259.                 <xsl:value-of select="concat( '$', $row-number)"/>
  8260.             </xsl:when>
  8261.             <xsl:otherwise>
  8262.                 <xsl:value-of select="$row-number"/>
  8263.             </xsl:otherwise>
  8264.         </xsl:choose>
  8265.     </xsl:template>
  8266.     <xsl:template name="number-to-character">
  8267.         <xsl:param name="number"/>
  8268.         <xsl:choose>
  8269.             <xsl:when test="$number = 0"/>
  8270.             <xsl:when test="$number = 1">A</xsl:when>
  8271.             <xsl:when test="$number = 2">B</xsl:when>
  8272.             <xsl:when test="$number = 3">C</xsl:when>
  8273.             <xsl:when test="$number = 4">D</xsl:when>
  8274.             <xsl:when test="$number = 5">E</xsl:when>
  8275.             <xsl:when test="$number = 6">F</xsl:when>
  8276.             <xsl:when test="$number = 7">G</xsl:when>
  8277.             <xsl:when test="$number = 8">H</xsl:when>
  8278.             <xsl:when test="$number = 9">I</xsl:when>
  8279.             <xsl:when test="$number = 10">J</xsl:when>
  8280.             <xsl:when test="$number = 11">K</xsl:when>
  8281.             <xsl:when test="$number = 12">L</xsl:when>
  8282.             <xsl:when test="$number = 13">M</xsl:when>
  8283.             <xsl:when test="$number = 14">N</xsl:when>
  8284.             <xsl:when test="$number = 15">O</xsl:when>
  8285.             <xsl:when test="$number = 16">P</xsl:when>
  8286.             <xsl:when test="$number = 17">Q</xsl:when>
  8287.             <xsl:when test="$number = 18">R</xsl:when>
  8288.             <xsl:when test="$number = 19">S</xsl:when>
  8289.             <xsl:when test="$number = 20">T</xsl:when>
  8290.             <xsl:when test="$number = 21">U</xsl:when>
  8291.             <xsl:when test="$number = 22">V</xsl:when>
  8292.             <xsl:when test="$number = 23">W</xsl:when>
  8293.             <xsl:when test="$number = 24">X</xsl:when>
  8294.             <xsl:when test="$number = 25">Y</xsl:when>
  8295.             <xsl:when test="$number = 26">Z</xsl:when>
  8296.             <xsl:otherwise/>
  8297.         </xsl:choose>
  8298.     </xsl:template>
  8299.     <xsl:template name="get-digit-length">
  8300.         <xsl:param name="complexive-string"/>
  8301.         <xsl:variable name="first-char">
  8302.             <xsl:value-of select="substring( $complexive-string, 1, 1)"/>
  8303.         </xsl:variable>
  8304.         <xsl:choose>
  8305.             <xsl:when test="$first-char = '1' or $first-char = '2' or $first-char = '3' or $first-char = '4' or $first-char = '5' or $first-char = '6' or $first-char = '7' or $first-char = '8' or $first-char = '9' or $first-char = '0' ">
  8306.                 <xsl:variable name="temp">
  8307.                     <xsl:call-template name="get-digit-length">
  8308.                         <xsl:with-param name="complexive-string" select="substring( $complexive-string, 2)"/>
  8309.                     </xsl:call-template>
  8310.                 </xsl:variable>
  8311.                 <xsl:value-of select="$temp+1"/>
  8312.             </xsl:when>
  8313.             <xsl:otherwise>0</xsl:otherwise>
  8314.         </xsl:choose>
  8315.     </xsl:template>
  8316.     <xsl:template match="ss:Comment" mode="body">
  8317.         <xsl:element name="office:annotation">
  8318.             <xsl:if test="@ss:ShowAlways = '1'">
  8319.                 <xsl:attribute name="office:display">true</xsl:attribute>
  8320.             </xsl:if>
  8321.             <xsl:if test="@ss:Author">
  8322.                 <xsl:element name="dc:creator">
  8323.                     <xsl:value-of select="@ss:Author"/>
  8324.                 </xsl:element>
  8325.             </xsl:if>
  8326.             <xsl:if test="ss:Data">
  8327.                 <text:p>
  8328.                     <xsl:call-template name="create-data-content">
  8329.                         <xsl:with-param name="style-id" select="@ss:StyleID"/>
  8330.                     </xsl:call-template>
  8331.                 </text:p>
  8332.             </xsl:if>
  8333.         </xsl:element>
  8334.     </xsl:template>
  8335.     <xsl:template name="Names">
  8336.         <xsl:variable name="namedRanges" select="/ss:Workbook/ss:Worksheet/ss:Names/ss:NamedRange |
  8337.                                                  /ss:Workbook/ss:Names/ss:NamedRange" />
  8338.         <xsl:if test="$namedRanges">
  8339.             <table:named-expressions>
  8340.                 <xsl:for-each select="$namedRanges">
  8341.                     <xsl:choose>
  8342.                         <xsl:when test="contains( @ss:RefersTo, '!R')">
  8343.                             <xsl:variable name="referto">
  8344.                                 <xsl:call-template name="translate-expression">
  8345.                                     <xsl:with-param name="isRangeAddress" select="true()"/>
  8346.                                     <xsl:with-param name="cell-row-pos" select="0"/>
  8347.                                     <xsl:with-param name="cell-column-pos" select="0"/>
  8348.                                     <xsl:with-param name="expression" select="@ss:RefersTo"/>
  8349.                                     <xsl:with-param name="return-value" select="''"/>
  8350.                                 </xsl:call-template>
  8351.                             </xsl:variable>
  8352.                             <xsl:element name="table:named-range">
  8353.                                 <xsl:attribute name="table:name">
  8354.                                     <xsl:value-of select="@ss:Name"/>
  8355.                                 </xsl:attribute>
  8356.                                 <xsl:attribute name="table:base-cell-address">
  8357.                                     <xsl:variable name="worksheetName" select="translate(substring-before(@ss:RefersTo, '!'), '=', '$')" />
  8358.                                     <xsl:call-template name="encode-as-cell-address">
  8359.                                         <xsl:with-param name="string" select="concat($worksheetName,'.$A$1')"/>
  8360.                                     </xsl:call-template>
  8361.                                 </xsl:attribute>
  8362.                                 <xsl:attribute name="table:cell-range-address">
  8363.                                     <xsl:call-template name="encode-as-cell-range-address">
  8364.                                         <xsl:with-param name="string" select="translate( $referto, '=', '$')"/>
  8365.                                     </xsl:call-template>
  8366.                                 </xsl:attribute>
  8367.                                 <xsl:if test="@ss:Name = 'Print_Area'">
  8368.                                     <xsl:attribute name="table:range-usable-as">print-range</xsl:attribute>
  8369.                                 </xsl:if>
  8370.                             </xsl:element>
  8371.                         </xsl:when>
  8372.                         <xsl:otherwise>
  8373.                             <xsl:variable name="expression-name">
  8374.                                 <xsl:value-of select="@ss:Name"/>
  8375.                             </xsl:variable>
  8376.                             <xsl:element name="table:named-expression">
  8377.                                 <xsl:attribute name="table:name">
  8378.                                     <xsl:value-of select="@ss:Name"/>
  8379.                                 </xsl:attribute>
  8380.                                 <!-- just set '$Sheet1.$A$1' as named-expressions virtual base-cell-address -->
  8381.                                 <xsl:attribute name="table:base-cell-address">
  8382.                                     <xsl:variable name="worksheetName" select="following-sibling::ss:Worksheet/@ss:Name" />
  8383.                                     <xsl:call-template name="encode-as-cell-address">
  8384.                                         <xsl:with-param name="string" select="concat('$', $worksheetName,'.$A$1')"/>
  8385.                                     </xsl:call-template>
  8386.                                 </xsl:attribute>
  8387.                                 <xsl:attribute name="table:expression">
  8388.                                     <xsl:value-of select="substring( @ss:RefersTo, 2)"/>
  8389.                                 </xsl:attribute>
  8390.                             </xsl:element>
  8391.                         </xsl:otherwise>
  8392.                     </xsl:choose>
  8393.                 </xsl:for-each>
  8394.             </table:named-expressions>
  8395.         </xsl:if>
  8396.     </xsl:template>
  8397.     <xsl:template name="transform-advanced-filter">
  8398.         <!-- transform the params of Advanced Filter.it's different from AutoFilter -->
  8399.         <xsl:param name="target-value"/>
  8400.         <xsl:param name="condition-pos"/>
  8401.         <xsl:element name="table:database-range">
  8402.             <xsl:variable name="target-range">
  8403.                 <xsl:call-template name="translate-expression">
  8404.                     <xsl:with-param name="cell-row-pos" select="0"/>
  8405.                     <xsl:with-param name="cell-column-pos" select="0"/>
  8406.                     <xsl:with-param name="expression" select="$target-value"/>
  8407.                     <xsl:with-param name="return-value" select="''"/>
  8408.                 </xsl:call-template>
  8409.             </xsl:variable>
  8410.             <xsl:variable name="condition-range">
  8411.                 <xsl:call-template name="translate-expression">
  8412.                     <xsl:with-param name="cell-row-pos" select="0"/>
  8413.                     <xsl:with-param name="cell-column-pos" select="0"/>
  8414.                     <xsl:with-param name="expression" select="$condition-pos"/>
  8415.                     <xsl:with-param name="return-value" select="''"/>
  8416.                 </xsl:call-template>
  8417.             </xsl:variable>
  8418.             <xsl:attribute name="table:target-range-address">
  8419.                 <xsl:value-of select="$target-range"/>
  8420.             </xsl:attribute>
  8421.             <xsl:attribute name="table:name">
  8422.                 <xsl:value-of select="concat($target-range, '.filter')"/>
  8423.             </xsl:attribute>
  8424.             <xsl:element name="table:filter">
  8425.                 <xsl:attribute name="table:condition-source-range-address">
  8426.                     <xsl:value-of select="$condition-range"/>
  8427.                 </xsl:attribute>
  8428.                 <xsl:element name="table:filter-condition">
  8429.                     <xsl:attribute name="table:field-number">0</xsl:attribute>
  8430.                     <!-- The two attributes are recommended by OASIS -->
  8431.                     <xsl:attribute name="table:value"/>
  8432.                     <xsl:attribute name="table:operator"/>
  8433.                 </xsl:element>
  8434.             </xsl:element>
  8435.         </xsl:element>
  8436.     </xsl:template>
  8437.     <xsl:template match="x:AutoFilter">
  8438.         <!-- for AutoFilter -->
  8439.         <xsl:element name="table:database-range">
  8440.             <xsl:attribute name="table:name">
  8441.                 <xsl:value-of select="concat(../@ss:Name,'_',@x:Range)"/>
  8442.             </xsl:attribute>
  8443.             <xsl:variable name="range">
  8444.                 <xsl:call-template name="translate-expression">
  8445.                     <xsl:with-param name="cell-row-pos" select="0"/>
  8446.                     <xsl:with-param name="cell-column-pos" select="0"/>
  8447.                     <xsl:with-param name="expression" select="@x:Range"/>
  8448.                     <xsl:with-param name="return-value" select="''"/>
  8449.                 </xsl:call-template>
  8450.             </xsl:variable>
  8451.             <xsl:attribute name="table:target-range-address">
  8452.                 <xsl:value-of select="concat('$',../@ss:Name,'.',$range)"/>
  8453.             </xsl:attribute>
  8454.             <xsl:attribute name="table:display-filter-buttons">true</xsl:attribute>
  8455.             <xsl:element name="table:filter">
  8456.                 <xsl:call-template name="auto-filter-condition">
  8457.                     <xsl:with-param name="item-pos" select="1"/>
  8458.                     <xsl:with-param name="index" select="1"/>
  8459.                     <xsl:with-param name="total" select="count(./x:AutoFilterColumn)"/>
  8460.                 </xsl:call-template>
  8461.             </xsl:element>
  8462.         </xsl:element>
  8463.     </xsl:template>
  8464.     <xsl:template name="auto-filter-condition">
  8465.         <!--?? generate element of filter-condition for AutoCondition to get position of index -->
  8466.         <xsl:param name="item-pos"/>
  8467.         <xsl:param name="index"/>
  8468.         <xsl:param name="total"/>
  8469.         <xsl:if test="($index - 1 < $total) or ($index - 1 = $total)">
  8470.             <xsl:element name="table:filter-condition">
  8471.                 <xsl:attribute name="table:data-type">number</xsl:attribute>
  8472.                 <xsl:choose>
  8473.                     <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Type = 'TopPercent'">
  8474.                         <xsl:attribute name="table:operator">
  8475.                             <xsl:value-of select="'top value'"/>
  8476.                         </xsl:attribute>
  8477.                         <xsl:attribute name="table:value">
  8478.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Value"/>
  8479.                         </xsl:attribute>
  8480.                     </xsl:when>
  8481.                     <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Type = 'Top'">
  8482.                         <xsl:attribute name="table:operator">
  8483.                             <xsl:value-of select="'top values'"/>
  8484.                         </xsl:attribute>
  8485.                         <xsl:attribute name="table:value">
  8486.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Value"/>
  8487.                         </xsl:attribute>
  8488.                     </xsl:when>
  8489.                     <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Type = 'TopPercent'">
  8490.                         <xsl:attribute name="table:operator">
  8491.                             <xsl:value-of select="'top percent'"/>
  8492.                         </xsl:attribute>
  8493.                         <xsl:attribute name="table:value">
  8494.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Value"/>
  8495.                         </xsl:attribute>
  8496.                     </xsl:when>
  8497.                     <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Type = 'Bottom'">
  8498.                         <xsl:attribute name="table:operator">
  8499.                             <xsl:value-of select="'bottom values'"/>
  8500.                         </xsl:attribute>
  8501.                         <xsl:attribute name="table:value">
  8502.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Value"/>
  8503.                         </xsl:attribute>
  8504.                     </xsl:when>
  8505.                     <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Type = 'BottomPercent'">
  8506.                         <xsl:attribute name="table:operator">
  8507.                             <xsl:value-of select="'bottom percent'"/>
  8508.                         </xsl:attribute>
  8509.                         <xsl:attribute name="table:value">
  8510.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Value"/>
  8511.                         </xsl:attribute>
  8512.                     </xsl:when>
  8513.                     <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Type = 'Custom'">
  8514.                         <xsl:choose>
  8515.                             <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/x:AutoFilterOr or ./x:AutoFilterColumn[position() = $item-pos]/x:AutoFilterAnd">
  8516.                                 <xsl:attribute name="table:operator">
  8517.                                     <xsl:choose>
  8518.                                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]//@x:Operator = 'Equals'">
  8519.                                             <xsl:value-of select="'='"/>
  8520.                                         </xsl:when>
  8521.                                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]//@x:Operator = 'DoesNotEquals'">
  8522.                                             <xsl:value-of select="'!='"/>
  8523.                                         </xsl:when>
  8524.                                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]//@x:Operator = 'GreaterThan'">
  8525.                                             <xsl:value-of select="'>'"/>
  8526.                                         </xsl:when>
  8527.                                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]//@x:Operator = 'GreaterThanOrEqual'">
  8528.                                             <xsl:value-of select="'>='"/>
  8529.                                         </xsl:when>
  8530.                                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]//@x:Operator = 'LessThan'">
  8531.                                             <xsl:value-of select="'<'"/>
  8532.                                         </xsl:when>
  8533.                                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]//@x:Operator = 'LessThanOrEqual'">
  8534.                                             <xsl:value-of select="'<='"/>
  8535.                                         </xsl:when>
  8536.                                         <xsl:otherwise>
  8537.                                             <xsl:value-of select="'='"/>
  8538.                                         </xsl:otherwise>
  8539.                                     </xsl:choose>
  8540.                                 </xsl:attribute>
  8541.                                 <xsl:attribute name="table:value">
  8542.                                     <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]//@x:Value"/>
  8543.                                 </xsl:attribute>
  8544.                             </xsl:when>
  8545.                             <xsl:otherwise>
  8546.                                 <xsl:attribute name="table:operator">
  8547.                                     <xsl:value-of select="'bottom percent'"/>
  8548.                                 </xsl:attribute>
  8549.                                 <xsl:attribute name="table:value">
  8550.                                     <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]//@x:Value"/>
  8551.                                 </xsl:attribute>
  8552.                             </xsl:otherwise>
  8553.                         </xsl:choose>
  8554.                     </xsl:when>
  8555.                 </xsl:choose>
  8556.                 <xsl:attribute name="table:field-number">
  8557.                     <xsl:choose>
  8558.                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Index">
  8559.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Index - 1"/>
  8560.                         </xsl:when>
  8561.                         <xsl:otherwise>
  8562.                             <xsl:value-of select="$index - 1"/>
  8563.                         </xsl:otherwise>
  8564.                     </xsl:choose>
  8565.                 </xsl:attribute>
  8566.             </xsl:element>
  8567.             <xsl:call-template name="auto-filter-condition">
  8568.                 <xsl:with-param name="item-pos" select="$item-pos + 1"/>
  8569.                 <xsl:with-param name="index">
  8570.                     <xsl:choose>
  8571.                         <xsl:when test="./x:AutoFilterColumn[position() = $item-pos]/@x:Index">
  8572.                             <xsl:value-of select="./x:AutoFilterColumn[position() = $item-pos]/@x:Index + 1"/>
  8573.                         </xsl:when>
  8574.                         <xsl:otherwise>
  8575.                             <xsl:value-of select="$index + 1"/>
  8576.                         </xsl:otherwise>
  8577.                     </xsl:choose>
  8578.                 </xsl:with-param>
  8579.                 <xsl:with-param name="total" select="count(./x:AutoFilterColumn)"/>
  8580.             </xsl:call-template>
  8581.         </xsl:if>
  8582.     </xsl:template>
  8583.     <xsl:template match="x:Sorting">
  8584.         <!-- for Sorting don't contains header row -->
  8585.         <xsl:if test="contains(./x:Sort, 'Column')">
  8586.             <xsl:element name="table:database-range">
  8587.                 <xsl:variable name="first-sort-letter" select="normalize-space(substring-after(./x:Sort[position() = 1], 'Column'))"/>
  8588.                 <xsl:variable name="second-sort-letter" select="normalize-space(substring-after(./x:Sort[position() = 2], 'Column'))"/>
  8589.                 <xsl:variable name="third-sort-letter" select="normalize-space(substring-after(./x:Sort[position() = 3], 'Column'))"/>
  8590.                 <xsl:variable name="first-sort-num">
  8591.                     <xsl:call-template name="letter-to-number">
  8592.                         <xsl:with-param name="source-letter" select="$first-sort-letter"/>
  8593.                         <xsl:with-param name="return-value" select="0"/>
  8594.                     </xsl:call-template>
  8595.                 </xsl:variable>
  8596.                 <xsl:variable name="second-sort-num">
  8597.                     <xsl:call-template name="letter-to-number">
  8598.                         <xsl:with-param name="source-letter" select="$second-sort-letter"/>
  8599.                         <xsl:with-param name="return-value" select="0"/>
  8600.                     </xsl:call-template>
  8601.                 </xsl:variable>
  8602.                 <xsl:variable name="third-sort-num">
  8603.                     <xsl:call-template name="letter-to-number">
  8604.                         <xsl:with-param name="source-letter" select="$third-sort-letter"/>
  8605.                         <xsl:with-param name="return-value" select="0"/>
  8606.                     </xsl:call-template>
  8607.                 </xsl:variable>
  8608.                 <xsl:variable name="min-left-num">
  8609.                     <xsl:call-template name="min-of-three">
  8610.                         <xsl:with-param name="first-num" select="$first-sort-num"/>
  8611.                         <xsl:with-param name="second-num" select="$second-sort-num"/>
  8612.                         <xsl:with-param name="third-num" select="$third-sort-num"/>
  8613.                     </xsl:call-template>
  8614.                 </xsl:variable>
  8615.                 <xsl:variable name="max-right-num">
  8616.                     <xsl:call-template name="max-of-three">
  8617.                         <xsl:with-param name="first-num" select="$first-sort-num"/>
  8618.                         <xsl:with-param name="second-num" select="$second-sort-num"/>
  8619.                         <xsl:with-param name="third-num" select="$third-sort-num"/>
  8620.                     </xsl:call-template>
  8621.                 </xsl:variable>
  8622.                 <xsl:variable name="left-column">
  8623.                     <xsl:call-template name="number-to-letter">
  8624.                         <xsl:with-param name="source-number" select="$min-left-num"/>
  8625.                         <xsl:with-param name="return-value" select="''"/>
  8626.                     </xsl:call-template>
  8627.                 </xsl:variable>
  8628.                 <xsl:variable name="right-column">
  8629.                     <xsl:call-template name="number-to-letter">
  8630.                         <xsl:with-param name="source-number" select="$max-right-num"/>
  8631.                         <xsl:with-param name="return-value" select="''"/>
  8632.                     </xsl:call-template>
  8633.                 </xsl:variable>
  8634.                 <xsl:attribute name="table:target-range-address">
  8635.                     <xsl:value-of select="concat(../@ss:Name, '.', $left-column, '1:', ../@ss:Name, '.', $right-column, '32000')"/>
  8636.                 </xsl:attribute>
  8637.                 <xsl:attribute name="table:name">
  8638.                     <xsl:value-of select="concat(../@ss:Name, '.sort')"/>
  8639.                 </xsl:attribute>
  8640.                 <xsl:attribute name="table:contains-header">
  8641.                     <xsl:value-of select="'false'"/>
  8642.                 </xsl:attribute>
  8643.                 <xsl:element name="table:sort">
  8644.                     <xsl:for-each select="./x:Sort">
  8645.                         <xsl:element name="table:sort-by">
  8646.                             <xsl:attribute name="table:field-number">
  8647.                                 <xsl:value-of select="0"/>
  8648.                             </xsl:attribute>
  8649.                             <xsl:attribute name="table:data-type">
  8650.                                 <xsl:value-of select="'automatic'"/>
  8651.                             </xsl:attribute>
  8652.                             <xsl:variable name="after-sort" select="following-sibling::*"/>
  8653.                             <xsl:if test="name($after-sort[position() = 1]) = 'Descending'">
  8654.                                 <xsl:attribute name="table:order">
  8655.                                     <xsl:value-of select="'descending'"/>
  8656.                                 </xsl:attribute>
  8657.                             </xsl:if>
  8658.                             <xsl:choose>
  8659.                                 <xsl:when test="position() = 1">
  8660.                                     <xsl:attribute name="table:field-number">
  8661.                                         <xsl:value-of select="$first-sort-num - $min-left-num"/>
  8662.                                     </xsl:attribute>
  8663.                                 </xsl:when>
  8664.                                 <xsl:when test="position() = 2">
  8665.                                     <xsl:attribute name="table:field-number">
  8666.                                         <xsl:value-of select="$second-sort-num - $min-left-num"/>
  8667.                                     </xsl:attribute>
  8668.                                 </xsl:when>
  8669.                                 <xsl:when test="position() = 3">
  8670.                                     <xsl:attribute name="table:field-number">
  8671.                                         <xsl:value-of select="$third-sort-num - $min-left-num"/>
  8672.                                     </xsl:attribute>
  8673.                                 </xsl:when>
  8674.                             </xsl:choose>
  8675.                         </xsl:element>
  8676.                     </xsl:for-each>
  8677.                 </xsl:element>
  8678.             </xsl:element>
  8679.         </xsl:if>
  8680.     </xsl:template>
  8681.     <xsl:template name="letter-to-number">
  8682.         <!-- convert letter to number for sorting. the string source-letter should be normalize-space and the first return-value should be zero -->
  8683.         <xsl:param name="source-letter"/>
  8684.         <xsl:param name="return-value"/>
  8685.         <xsl:choose>
  8686.             <xsl:when test="string-length($source-letter) > 0">
  8687.                 <xsl:variable name="first-pit" select="substring($source-letter, 1, 1)"/>
  8688.                 <xsl:variable name="pit-number">
  8689.                     <xsl:choose>
  8690.                         <xsl:when test="($first-pit = 'A') or ($first-pit = 'a')">
  8691.                             <xsl:value-of select="1"/>
  8692.                         </xsl:when>
  8693.                         <xsl:when test="($first-pit = 'B') or ($first-pit = 'b')">
  8694.                             <xsl:value-of select="2"/>
  8695.                         </xsl:when>
  8696.                         <xsl:when test="($first-pit = 'C') or ($first-pit = 'c')">
  8697.                             <xsl:value-of select="3"/>
  8698.                         </xsl:when>
  8699.                         <xsl:when test="($first-pit = 'D') or ($first-pit = 'd')">
  8700.                             <xsl:value-of select="4"/>
  8701.                         </xsl:when>
  8702.                         <xsl:when test="($first-pit = 'E') or ($first-pit = 'e')">
  8703.                             <xsl:value-of select="5"/>
  8704.                         </xsl:when>
  8705.                         <xsl:when test="($first-pit = 'F') or ($first-pit = 'f')">
  8706.                             <xsl:value-of select="6"/>
  8707.                         </xsl:when>
  8708.                         <xsl:when test="($first-pit = 'G') or ($first-pit = 'g')">
  8709.                             <xsl:value-of select="7"/>
  8710.                         </xsl:when>
  8711.                         <xsl:when test="($first-pit = 'H') or ($first-pit = 'h')">
  8712.                             <xsl:value-of select="8"/>
  8713.                         </xsl:when>
  8714.                         <xsl:when test="($first-pit = 'I') or ($first-pit = 'i')">
  8715.                             <xsl:value-of select="9"/>
  8716.                         </xsl:when>
  8717.                         <xsl:when test="($first-pit = 'J') or ($first-pit = 'j')">
  8718.                             <xsl:value-of select="10"/>
  8719.                         </xsl:when>
  8720.                         <xsl:when test="($first-pit = 'K') or ($first-pit = 'k')">
  8721.                             <xsl:value-of select="11"/>
  8722.                         </xsl:when>
  8723.                         <xsl:when test="($first-pit = 'L') or ($first-pit = 'l')">
  8724.                             <xsl:value-of select="12"/>
  8725.                         </xsl:when>
  8726.                         <xsl:when test="($first-pit = 'M') or ($first-pit = 'm')">
  8727.                             <xsl:value-of select="13"/>
  8728.                         </xsl:when>
  8729.                         <xsl:when test="($first-pit = 'N') or ($first-pit = 'n')">
  8730.                             <xsl:value-of select="14"/>
  8731.                         </xsl:when>
  8732.                         <xsl:when test="($first-pit = 'O') or ($first-pit = 'o')">
  8733.                             <xsl:value-of select="15"/>
  8734.                         </xsl:when>
  8735.                         <xsl:when test="($first-pit = 'P') or ($first-pit = 'p')">
  8736.                             <xsl:value-of select="16"/>
  8737.                         </xsl:when>
  8738.                         <xsl:when test="($first-pit = 'Q') or ($first-pit = 'q')">
  8739.                             <xsl:value-of select="17"/>
  8740.                         </xsl:when>
  8741.                         <xsl:when test="($first-pit = 'R') or ($first-pit = 'r')">
  8742.                             <xsl:value-of select="18"/>
  8743.                         </xsl:when>
  8744.                         <xsl:when test="($first-pit = 'S') or ($first-pit = 's')">
  8745.                             <xsl:value-of select="19"/>
  8746.                         </xsl:when>
  8747.                         <xsl:when test="($first-pit = 'T') or ($first-pit = 't')">
  8748.                             <xsl:value-of select="20"/>
  8749.                         </xsl:when>
  8750.                         <xsl:when test="($first-pit = 'U') or ($first-pit = 'u')">
  8751.                             <xsl:value-of select="21"/>
  8752.                         </xsl:when>
  8753.                         <xsl:when test="($first-pit = 'V') or ($first-pit = 'v')">
  8754.                             <xsl:value-of select="22"/>
  8755.                         </xsl:when>
  8756.                         <xsl:when test="($first-pit = 'W') or ($first-pit = 'w')">
  8757.                             <xsl:value-of select="23"/>
  8758.                         </xsl:when>
  8759.                         <xsl:when test="($first-pit = 'X') or ($first-pit = 'x')">
  8760.                             <xsl:value-of select="24"/>
  8761.                         </xsl:when>
  8762.                         <xsl:when test="($first-pit = 'Y') or ($first-pit = 'y')">
  8763.                             <xsl:value-of select="25"/>
  8764.                         </xsl:when>
  8765.                         <xsl:when test="($first-pit = 'Z') or ($first-pit = 'z')">
  8766.                             <xsl:value-of select="26"/>
  8767.                         </xsl:when>
  8768.                         <xsl:otherwise>
  8769.                             <xsl:value-of select="1"/>
  8770.                         </xsl:otherwise>
  8771.                     </xsl:choose>
  8772.                 </xsl:variable>
  8773.                 <xsl:call-template name="letter-to-number">
  8774.                     <xsl:with-param name="source-letter" select="substring($source-letter, 2)"/>
  8775.                     <xsl:with-param name="return-value">
  8776.                         <xsl:choose>
  8777.                             <xsl:when test="string-length($source-letter) >= 2">
  8778.                                 <xsl:value-of select="$pit-number * 26 + $return-value"/>
  8779.                             </xsl:when>
  8780.                             <xsl:otherwise>
  8781.                                 <xsl:value-of select="$pit-number + $return-value"/>
  8782.                             </xsl:otherwise>
  8783.                         </xsl:choose>
  8784.                     </xsl:with-param>
  8785.                 </xsl:call-template>
  8786.             </xsl:when>
  8787.             <xsl:otherwise>
  8788.                 <xsl:value-of select="$return-value"/>
  8789.             </xsl:otherwise>
  8790.         </xsl:choose>
  8791.     </xsl:template>
  8792.     <xsl:template name="number-to-letter">
  8793.         <!--?? convert number to letter for sorting -->
  8794.         <xsl:param name="source-number"/>
  8795.         <xsl:param name="return-value"/>
  8796.         <xsl:variable name="current-value">
  8797.             <xsl:call-template name="num-conv-letter">
  8798.                 <xsl:with-param name="first-pit">
  8799.                     <xsl:choose>
  8800.                         <xsl:when test="$source-number > 26">
  8801.                             <xsl:value-of select="floor($source-number div 26)"/>
  8802.                         </xsl:when>
  8803.                         <xsl:otherwise>
  8804.                             <xsl:value-of select="$source-number"/>
  8805.                         </xsl:otherwise>
  8806.                     </xsl:choose>
  8807.                 </xsl:with-param>
  8808.             </xsl:call-template>
  8809.         </xsl:variable>
  8810.         <xsl:if test="$source-number > 26">
  8811.             <xsl:call-template name="number-to-letter">
  8812.                 <xsl:with-param name="source-number" select="$source-number mod 26"/>
  8813.                 <xsl:with-param name="return-value" select="concat($return-value,$current-value)"/>
  8814.             </xsl:call-template>
  8815.         </xsl:if>
  8816.         <xsl:if test="$source-number < 27">
  8817.             <xsl:value-of select="concat($return-value,$current-value)"/>
  8818.         </xsl:if>
  8819.     </xsl:template>
  8820.     <xsl:template name="num-conv-letter">
  8821.         <!-- convert number to number by pit of 26 -->
  8822.         <xsl:param name="first-pit"/>
  8823.         <xsl:choose>
  8824.             <xsl:when test="$first-pit = 1">
  8825.                 <xsl:value-of select="'A'"/>
  8826.             </xsl:when>
  8827.             <xsl:when test="$first-pit = 2">
  8828.                 <xsl:value-of select="'B'"/>
  8829.             </xsl:when>
  8830.             <xsl:when test="$first-pit = 3">
  8831.                 <xsl:value-of select="'C'"/>
  8832.             </xsl:when>
  8833.             <xsl:when test="$first-pit = 4">
  8834.                 <xsl:value-of select="'D'"/>
  8835.             </xsl:when>
  8836.             <xsl:when test="$first-pit = 5">
  8837.                 <xsl:value-of select="'E'"/>
  8838.             </xsl:when>
  8839.             <xsl:when test="$first-pit = 6">
  8840.                 <xsl:value-of select="'F'"/>
  8841.             </xsl:when>
  8842.             <xsl:when test="$first-pit = 7">
  8843.                 <xsl:value-of select="'G'"/>
  8844.             </xsl:when>
  8845.             <xsl:when test="$first-pit = 8">
  8846.                 <xsl:value-of select="'H'"/>
  8847.             </xsl:when>
  8848.             <xsl:when test="$first-pit = 9">
  8849.                 <xsl:value-of select="'I'"/>
  8850.             </xsl:when>
  8851.             <xsl:when test="$first-pit = 10">
  8852.                 <xsl:value-of select="'J'"/>
  8853.             </xsl:when>
  8854.             <xsl:when test="$first-pit = 11">
  8855.                 <xsl:value-of select="'K'"/>
  8856.             </xsl:when>
  8857.             <xsl:when test="$first-pit = 12">
  8858.                 <xsl:value-of select="'L'"/>
  8859.             </xsl:when>
  8860.             <xsl:when test="$first-pit = 13">
  8861.                 <xsl:value-of select="'M'"/>
  8862.             </xsl:when>
  8863.             <xsl:when test="$first-pit = 14">
  8864.                 <xsl:value-of select="'N'"/>
  8865.             </xsl:when>
  8866.             <xsl:when test="$first-pit = 15">
  8867.                 <xsl:value-of select="'O'"/>
  8868.             </xsl:when>
  8869.             <xsl:when test="$first-pit = 16">
  8870.                 <xsl:value-of select="'P'"/>
  8871.             </xsl:when>
  8872.             <xsl:when test="$first-pit = 17">
  8873.                 <xsl:value-of select="'Q'"/>
  8874.             </xsl:when>
  8875.             <xsl:when test="$first-pit = 18">
  8876.                 <xsl:value-of select="'R'"/>
  8877.             </xsl:when>
  8878.             <xsl:when test="$first-pit = 19">
  8879.                 <xsl:value-of select="'S'"/>
  8880.             </xsl:when>
  8881.             <xsl:when test="$first-pit = 20">
  8882.                 <xsl:value-of select="'T'"/>
  8883.             </xsl:when>
  8884.             <xsl:when test="$first-pit = 21">
  8885.                 <xsl:value-of select="'U'"/>
  8886.             </xsl:when>
  8887.             <xsl:when test="$first-pit = 22">
  8888.                 <xsl:value-of select="'V'"/>
  8889.             </xsl:when>
  8890.             <xsl:when test="$first-pit = 23">
  8891.                 <xsl:value-of select="'W'"/>
  8892.             </xsl:when>
  8893.             <xsl:when test="$first-pit = 24">
  8894.                 <xsl:value-of select="'X'"/>
  8895.             </xsl:when>
  8896.             <xsl:when test="$first-pit = 25">
  8897.                 <xsl:value-of select="'Y'"/>
  8898.             </xsl:when>
  8899.             <xsl:when test="$first-pit = 26">
  8900.                 <xsl:value-of select="'Z'"/>
  8901.             </xsl:when>
  8902.             <xsl:otherwise>
  8903.                 <xsl:value-of select="'A'"/>
  8904.             </xsl:otherwise>
  8905.         </xsl:choose>
  8906.     </xsl:template>
  8907.     <xsl:template name="min-of-three">
  8908.         <!-- return minest of three for sorting -->
  8909.         <xsl:param name="first-num"/>
  8910.         <xsl:param name="second-num"/>
  8911.         <xsl:param name="third-num"/>
  8912.         <xsl:variable name="first-comp">
  8913.             <xsl:choose>
  8914.                 <xsl:when test="$first-num = 0">
  8915.                     <xsl:value-of select="$second-num"/>
  8916.                 </xsl:when>
  8917.                 <xsl:when test="($first-num < $second-num) or ($second-num = 0)">
  8918.                     <xsl:value-of select="$first-num"/>
  8919.                 </xsl:when>
  8920.                 <xsl:otherwise>
  8921.                     <xsl:value-of select="$second-num"/>
  8922.                 </xsl:otherwise>
  8923.             </xsl:choose>
  8924.         </xsl:variable>
  8925.         <xsl:variable name="second-comp">
  8926.             <xsl:choose>
  8927.                 <xsl:when test="($first-comp < $third-num) or ($third-num = 0)">
  8928.                     <xsl:value-of select="$first-comp"/>
  8929.                 </xsl:when>
  8930.                 <xsl:otherwise>
  8931.                     <xsl:value-of select="$third-num"/>
  8932.                 </xsl:otherwise>
  8933.             </xsl:choose>
  8934.         </xsl:variable>
  8935.         <xsl:value-of select="$second-comp"/>
  8936.     </xsl:template>
  8937.     <xsl:template name="max-of-three">
  8938.         <!-- return maxest of three for sorting -->
  8939.         <xsl:param name="first-num"/>
  8940.         <xsl:param name="second-num"/>
  8941.         <xsl:param name="third-num"/>
  8942.         <xsl:variable name="first-comp">
  8943.             <xsl:choose>
  8944.                 <xsl:when test="$first-num > $second-num">
  8945.                     <xsl:value-of select="$first-num"/>
  8946.                 </xsl:when>
  8947.                 <xsl:otherwise>
  8948.                     <xsl:value-of select="$second-num"/>
  8949.                 </xsl:otherwise>
  8950.             </xsl:choose>
  8951.         </xsl:variable>
  8952.         <xsl:variable name="second-comp">
  8953.             <xsl:choose>
  8954.                 <xsl:when test="$first-comp > $third-num">
  8955.                     <xsl:value-of select="$first-comp"/>
  8956.                 </xsl:when>
  8957.                 <xsl:otherwise>
  8958.                     <xsl:value-of select="$third-num"/>
  8959.                 </xsl:otherwise>
  8960.             </xsl:choose>
  8961.         </xsl:variable>
  8962.         <xsl:value-of select="$second-comp"/>
  8963.     </xsl:template>
  8964.     <xsl:template name="set-calculation">
  8965.         <xsl:element name="table:calculation-settings">
  8966.             <xsl:if test="/ss:Workbook/x:ExcelWorkbook/x:PrecisionAsDisplayed">
  8967.                 <xsl:attribute name="table:precision-as-shown">true</xsl:attribute>
  8968.             </xsl:if>
  8969.             <xsl:if test="/ss:Workbook/x:ExcelWorkbook/x:Date1904">
  8970.                 <table:null-date office:date-value="1904-01-01"/>
  8971.             </xsl:if>
  8972.             <xsl:element name="table:iteration">
  8973.                 <xsl:if test="/ss:Workbook/x:ExcelWorkbook/x:Iteration">
  8974.                     <xsl:attribute name="table:status">enable</xsl:attribute>
  8975.                 </xsl:if>
  8976.                 <xsl:if test="/ss:Workbook/x:ExcelWorkbook/x:MaxIterations">
  8977.                     <xsl:attribute name="table:steps">
  8978.                         <xsl:value-of select="/ss:Workbook/x:ExcelWorkbook/x:MaxIterations"/>
  8979.                     </xsl:attribute>
  8980.                 </xsl:if>
  8981.                 <xsl:if test="/ss:Workbook/x:ExcelWorkbook/x:MaxChange">
  8982.                     <xsl:attribute name="table:maximum-difference">
  8983.                         <xsl:value-of select="/ss:Workbook/x:ExcelWorkbook/x:MaxChange"/>
  8984.                     </xsl:attribute>
  8985.                 </xsl:if>
  8986.             </xsl:element>
  8987.         </xsl:element>
  8988.     </xsl:template>
  8989.     <xsl:template match="x:DataValidation">
  8990.         <!-- for DataValidation. don't support the attribute IMEMode currently.  -->
  8991.         <xsl:element name="table:content-validation">
  8992.             <xsl:attribute name="table:name">
  8993.                 <xsl:value-of select="concat('val', position())"/>
  8994.             </xsl:attribute>
  8995.             <xsl:attribute name="table:condition"><!-- don't support two type of qualifier: List, Custom -->
  8996.                 <xsl:variable name="qualifier-content">
  8997.                     <xsl:choose>
  8998.                         <xsl:when test="./x:Qualifier = 'NotBetween'">
  8999.                             <xsl:value-of select="concat('cell-content-is-not-between(', ./x:Min, ',', ./x:Max, ')')"/>
  9000.                         </xsl:when>
  9001.                         <xsl:when test="./x:Qualifier = 'NotEqual'">
  9002.                             <xsl:value-of select="concat('!=', ./x:Value)"/>
  9003.                         </xsl:when>
  9004.                         <xsl:when test="./x:Qualifier = 'Equal'">
  9005.                             <xsl:value-of select="concat('=', ./x:Value)"/>
  9006.                         </xsl:when>
  9007.                         <xsl:when test="./x:Qualifier = 'Less'">
  9008.                             <xsl:value-of select="concat('<', ./x:Value)"/>
  9009.                         </xsl:when>
  9010.                         <xsl:when test="./x:Qualifier = 'Greater'">
  9011.                             <xsl:value-of select="concat('>', ./x:Value)"/>
  9012.                         </xsl:when>
  9013.                         <xsl:when test="./x:Qualifier = 'GreaterOrEqual'">
  9014.                             <xsl:value-of select="concat('>=', ./x:Value)"/>
  9015.                         </xsl:when>
  9016.                         <xsl:when test="./x:Qualifier = 'LessOrEqual'">
  9017.                             <xsl:value-of select="concat('<=', ./x:Value)"/>
  9018.                         </xsl:when>
  9019.                         <xsl:otherwise>
  9020.                             <xsl:value-of select="concat('cell-content-is-between(', ./x:Min, ',', ./x:Max)"/>
  9021.                         </xsl:otherwise>
  9022.                     </xsl:choose>
  9023.                 </xsl:variable>
  9024.                 <xsl:variable name="qualifier-value">
  9025.                     <xsl:choose>
  9026.                         <xsl:when test="./x:Type = 'Whole'">
  9027.                             <xsl:choose>
  9028.                                 <xsl:when test="(./x:Qualifier = 'NotBetween') or ./x:Max">
  9029.                                     <xsl:value-of select="concat('cell-content-is-whole-number() and ', $qualifier-content, ')')"/>
  9030.                                 </xsl:when>
  9031.                                 <xsl:otherwise>
  9032.                                     <xsl:value-of select="concat('cell-content-is-whole-number() and ', 'cell-content()', $qualifier-content)"/>
  9033.                                 </xsl:otherwise>
  9034.                             </xsl:choose>
  9035.                         </xsl:when>
  9036.                         <xsl:when test="./x:Type = 'Decimal'">
  9037.                             <xsl:choose>
  9038.                                 <xsl:when test="(./x:Qualifier = 'NotBetween') or ./x:Max">
  9039.                                     <xsl:value-of select="concat('cell-content-is-decimal-number() and ', $qualifier-content, ')')"/>
  9040.                                 </xsl:when>
  9041.                                 <xsl:otherwise>
  9042.                                     <xsl:value-of select="concat('cell-content-is-decimal-number() and ', 'cell-content()', $qualifier-content)"/>
  9043.                                 </xsl:otherwise>
  9044.                             </xsl:choose>
  9045.                         </xsl:when>
  9046.                         <xsl:when test="./x:Type = 'Date'">
  9047.                             <xsl:choose>
  9048.                                 <xsl:when test="(./x:Qualifier = 'NotBetween') or ./x:Max">
  9049.                                     <xsl:value-of select="concat('cell-content-is-date() and ', $qualifier-content, ')')"/>
  9050.                                 </xsl:when>
  9051.                                 <xsl:otherwise>
  9052.                                     <xsl:value-of select="concat('cell-content-is-date() and ', 'cell-content()', $qualifier-content)"/>
  9053.                                 </xsl:otherwise>
  9054.                             </xsl:choose>
  9055.                         </xsl:when>
  9056.                         <xsl:when test="./x:Type = 'Time'">
  9057.                             <xsl:choose>
  9058.                                 <xsl:when test="(./x:Qualifier = 'NotBetween') or ./x:Max">
  9059.                                     <xsl:value-of select="concat('cell-content-is-time() and ', $qualifier-content, ')')"/>
  9060.                                 </xsl:when>
  9061.                                 <xsl:otherwise>
  9062.                                     <xsl:value-of select="concat('cell-content-is-time() and ', 'cell-content()', $qualifier-content)"/>
  9063.                                 </xsl:otherwise>
  9064.                             </xsl:choose>
  9065.                         </xsl:when>
  9066.                         <xsl:when test="./x:Type = 'TextLength'">
  9067.                             <xsl:choose>
  9068.                                 <xsl:when test="./x:Qualifier = 'NotBetween'">
  9069.                                     <xsl:value-of select="concat('cell-content-text-length-is-not-between(', ./x:Min, ',', ./x:Max, ')')"/>
  9070.                                 </xsl:when>
  9071.                                 <xsl:when test="./x:Max and ./x:Min">
  9072.                                     <xsl:value-of select="concat('cell-content-text-length-is-between(', ./x:Min, ',', ./x:Max, ')')"/>
  9073.                                 </xsl:when>
  9074.                                 <xsl:otherwise>
  9075.                                     <xsl:value-of select="concat('cell-content-text-length()', $qualifier-content)"/>
  9076.                                 </xsl:otherwise>
  9077.                             </xsl:choose>
  9078.                         </xsl:when>
  9079.                         <xsl:otherwise>
  9080.                             <xsl:value-of select="./x:Type"/>
  9081.                         </xsl:otherwise>
  9082.                     </xsl:choose>
  9083.                 </xsl:variable>
  9084.                 <xsl:value-of select="$qualifier-value"/>
  9085.             </xsl:attribute>
  9086.             <xsl:attribute name="table:base-cell-address">
  9087.                 <xsl:variable name="first-range">
  9088.                     <xsl:choose>
  9089.                         <xsl:when test="contains(./x:Range, ',')">
  9090.                             <xsl:value-of select="substring-before(./x:Range, ',')"/>
  9091.                         </xsl:when>
  9092.                         <xsl:otherwise>
  9093.                             <xsl:value-of select="./x:Range"/>
  9094.                         </xsl:otherwise>
  9095.                     </xsl:choose>
  9096.                 </xsl:variable>
  9097.                 <xsl:variable name="range">
  9098.                     <xsl:call-template name="translate-expression">
  9099.                         <xsl:with-param name="cell-row-pos" select="0"/>
  9100.                         <xsl:with-param name="cell-column-pos" select="0"/>
  9101.                         <xsl:with-param name="expression" select="$first-range"/>
  9102.                         <xsl:with-param name="return-value" select="''"/>
  9103.                     </xsl:call-template>
  9104.                 </xsl:variable>
  9105.                 <xsl:call-template name="encode-as-cell-address">
  9106.                     <xsl:with-param name="string" select="concat(../../ss:Worksheet/@ss:Name, '.', $range)"/>
  9107.                 </xsl:call-template>
  9108.             </xsl:attribute>
  9109.             <xsl:element name="table:help-message">
  9110.                 <xsl:attribute name="table:title">
  9111.                     <xsl:value-of select="./x:InputTitle"/>
  9112.                 </xsl:attribute>
  9113.                 <xsl:attribute name="table:display">
  9114.                     <xsl:choose>
  9115.                         <xsl:when test="./x:InputHide">
  9116.                             <xsl:value-of select="'false'"/>
  9117.                         </xsl:when>
  9118.                         <xsl:otherwise>
  9119.                             <xsl:value-of select="'true'"/>
  9120.                         </xsl:otherwise>
  9121.                     </xsl:choose>
  9122.                 </xsl:attribute>
  9123.                 <xsl:element name="text:p">
  9124.                     <xsl:value-of select="./x:InputMessage"/>
  9125.                 </xsl:element>
  9126.             </xsl:element>
  9127.             <xsl:element name="table:error-message">
  9128.                 <xsl:attribute name="table:message-type">
  9129.                     <xsl:choose>
  9130.                         <xsl:when test="./x:ErrorStyle= 'Info'">
  9131.                             <xsl:value-of select="'information'"/>
  9132.                         </xsl:when>
  9133.                         <xsl:when test="./x:ErrorStyle= 'Warn'">
  9134.                             <xsl:value-of select="'warning'"/>
  9135.                         </xsl:when>
  9136.                         <xsl:otherwise>
  9137.                             <xsl:value-of select="'stop'"/>
  9138.                         </xsl:otherwise>
  9139.                     </xsl:choose>
  9140.                 </xsl:attribute>
  9141.                 <xsl:attribute name="table:title">
  9142.                     <xsl:value-of select="./x:ErrorTitle"/>
  9143.                 </xsl:attribute>
  9144.                 <xsl:attribute name="table:display">
  9145.                     <xsl:choose>
  9146.                         <xsl:when test="./x:ErrorHide">
  9147.                             <xsl:value-of select="'false'"/>
  9148.                         </xsl:when>
  9149.                         <xsl:otherwise>
  9150.                             <xsl:value-of select="'true'"/>
  9151.                         </xsl:otherwise>
  9152.                     </xsl:choose>
  9153.                 </xsl:attribute>
  9154.                 <xsl:element name="text:p">
  9155.                     <xsl:value-of select="./x:ErrorMessage"/>
  9156.                 </xsl:element>
  9157.             </xsl:element>
  9158.         </xsl:element>
  9159.     </xsl:template>
  9160.     <!-- Note: Move template to common section -->
  9161.     <xsl:template name="encode-as-cell-range-address">
  9162.         <xsl:param name="string"/>
  9163.         <xsl:value-of select="$string"/>
  9164.     </xsl:template>
  9165.     <xsl:template name="encode-as-cell-address">
  9166.         <xsl:param name="string"/>
  9167.         <xsl:value-of select="$string"/>
  9168.     </xsl:template>
  9169.     <xsl:template name="encode-as-nc-name">
  9170.         <xsl:param name="string"/>
  9171.         <xsl:value-of select="translate($string, '.%()/\+[]', '')"/>
  9172.     </xsl:template>
  9173. </xsl:stylesheet>
  9174.