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 / formular.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2010-12-01  |  30.2 KB  |  641 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"
  29.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  30.     xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  31.     xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
  32.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  33.     xmlns:dom="http://www.w3.org/2001/xml-events"
  34.     xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  35.     xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  36.     xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  37.     xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  38.     xmlns:math="http://www.w3.org/1998/Math/MathML"
  39.     xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  40.     xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  41.     xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  42.     xmlns:ooo="http://openoffice.org/2004/office"
  43.     xmlns:oooc="http://openoffice.org/2004/calc"
  44.     xmlns:ooow="http://openoffice.org/2004/writer"
  45.     xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  46.     xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  47.     xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  48.     xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  49.     xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  50.     xmlns:xlink="http://www.w3.org/1999/xlink"
  51.     xmlns:xt="http://www.jclark.com/xt"
  52.     xmlns:common="http://exslt.org/common"
  53.     xmlns:xalan="http://xml.apache.org/xalan"
  54.     xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  55.     exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xlink xt common xalan">
  56.  
  57.  
  58.     <!-- Mapping @table:formula to @ss:Formula translating the expression syntax -->
  59.     <xsl:template match="@table:formula">
  60.         <xsl:param name="calculatedCellPosition" />
  61.         <xsl:param name="calculatedRowPosition" />
  62.  
  63.         <xsl:attribute name="ss:Formula">
  64.             <xsl:call-template name="translate-formular-expression">
  65.                 <xsl:with-param name="rowPos"    select="$calculatedRowPosition" />
  66.                 <xsl:with-param name="columnPos" select="$calculatedCellPosition" />
  67.                 <xsl:with-param name="expression" select="." />
  68.             </xsl:call-template>
  69.         </xsl:attribute>
  70.     </xsl:template>
  71.  
  72.  
  73.     <!-- Translate OOOC formula expressions of table cells to spreadsheetml expression
  74.  
  75.         For example:
  76.             "oooc:=ROUNDDOWN(123.321;2)"
  77.                 to "=ROUNDDOWN(123.321,2)"
  78.             "oooc:=([.B2]-[.C2])"
  79.                 to  "=(RC[-2]-RC[-1])"
  80.             "oooc:=DCOUNTA([.E14:.F21];[.F14];[.H14:.I15])"
  81.                 to  "=DCOUNTA(R[-17]C[3]:R[-10]C[4],R[-17]C[4],R[-17]C[6]:R[-16]C[7])"   -->
  82.     <xsl:template name="translate-formular-expression">
  83.         <!--  return position or range for formula or other -->
  84.         <xsl:param name="rowPos" /> <!-- the position in row (vertical) of cell -->
  85.         <xsl:param name="columnPos" /> <!-- the position in column (horizontal of cell) -->
  86.         <xsl:param name="expression" /> <!-- the expression string to be converted  -->
  87.  
  88.         <xsl:choose>
  89.             <xsl:when test="$expression != ''">
  90.                 <xsl:choose>
  91.                     <!-- OASIS Open Document XML formular expressions  -->
  92.                     <xsl:when test="starts-with($expression,'oooc:')">
  93.                         <!-- giving out the '=', which will be removed with 'oooc:=' to enable recursive string parsing  -->
  94.                         <xsl:text>=</xsl:text>
  95.                         <xsl:call-template name="function-parameter-mapping">
  96.                             <xsl:with-param name="rowPos" select="$rowPos" />
  97.                             <xsl:with-param name="columnPos" select="$columnPos" />
  98.                             <!-- 1) remove 'oooc:=' prefix and exchange ';' with ',' -->
  99.                             <xsl:with-param name="expression" select="translate(substring($expression,7),';',',')"/>
  100.                         </xsl:call-template>
  101.                     </xsl:when>
  102.                     <xsl:otherwise>
  103.                         <xsl:value-of select="$expression" />
  104.                     </xsl:otherwise>
  105.                 </xsl:choose>
  106.             </xsl:when>
  107.             <xsl:otherwise>
  108.                 <xsl:value-of select="$expression" />
  109.             </xsl:otherwise>
  110.         </xsl:choose>
  111.     </xsl:template>
  112.  
  113.     <!-- As the function API of our Office and MS Office show differences in the argumentlists,
  114.             -    sometimes the last parameter have to be neglected
  115.             -    sometimes a default have to be added
  116.         these exchanges have to be done as well -->
  117.     <xsl:template name="function-parameter-mapping">
  118.         <xsl:param name="rowPos" /> <!-- the position in row (vertical of cell) -->
  119.         <xsl:param name="columnPos" /> <!-- the position in column (horizontal of cell) -->
  120.         <xsl:param name="expression" /> <!-- expression to be exchanged -->
  121.  
  122.         <!-- Choose if the expression contains one of the function, which might need changes -->
  123.         <xsl:choose>
  124.             <!-- if not contain one of the functions, which need parameter mapping -->
  125.             <xsl:when test="not(contains($expression, 'ADDRESS(') or
  126.                                 contains($expression, 'CEILING(') or
  127.                                 contains($expression, 'FLOOR(') or
  128.                                 contains($expression, 'IF(') or
  129.                                 contains($expression, 'ROUND('))">
  130.                 <!-- simply translate possily exisiting column & row references -->
  131.                 <xsl:call-template name="translate-oooc-expression">
  132.                     <xsl:with-param name="rowPos" select="$rowPos" />
  133.                     <xsl:with-param name="columnPos" select="$columnPos" />
  134.                     <xsl:with-param name="expression" select="$expression"/>
  135.                 </xsl:call-template>
  136.             </xsl:when>
  137.             <!-- functions to be mapped -->
  138.             <xsl:otherwise>
  139.                 <xsl:variable name="functionPrefix" select="substring-before($expression, '(')" />
  140.                 <xsl:variable name="expressionSuffix" select="substring-after($expression, '(')" />
  141.  
  142.                 <!-- translate in case the expression contains row/cell references aside of the function name -->
  143.                 <xsl:call-template name="translate-oooc-expression">
  144.                     <xsl:with-param name="rowPos" select="$rowPos" />
  145.                     <xsl:with-param name="columnPos" select="$columnPos" />
  146.                     <xsl:with-param name="expression" select="$functionPrefix"/>
  147.                 </xsl:call-template>
  148.                 <!-- Prefix do not include the bracket -->
  149.                 <xsl:text>(</xsl:text>
  150.                 <xsl:choose>
  151.                     <xsl:when test="not(contains($functionPrefix, 'ADDRESS') or
  152.                                         contains($functionPrefix, 'CEILING') or
  153.                                         contains($functionPrefix, 'FLOOR') or
  154.                                         (contains($functionPrefix, 'IF') and not(
  155.                                             contains($functionPrefix, 'COUNTIF') or
  156.                                             contains($functionPrefix, 'SUMIF'))) or
  157.                                         contains($functionPrefix, 'ROUND'))">
  158.                         <xsl:call-template name="function-parameter-mapping">
  159.                             <xsl:with-param name="rowPos" select="$rowPos" />
  160.                             <xsl:with-param name="columnPos" select="$columnPos" />
  161.                             <xsl:with-param name="expression" select="$expressionSuffix"/>
  162.                         </xsl:call-template>
  163.                     </xsl:when>
  164.                     <xsl:otherwise>
  165.                         <xsl:choose>
  166.                             <xsl:when test="contains($functionPrefix, 'ADDRESS')">
  167.                                 <xsl:call-template name="find-parameters">
  168.                                     <xsl:with-param name="rowPos" select="$rowPos" />
  169.                                     <xsl:with-param name="columnPos" select="$columnPos" />
  170.                                     <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  171.                                     <xsl:with-param name="parameterRemoval" select="4" />
  172.                                 </xsl:call-template>
  173.                             </xsl:when>
  174.                             <xsl:when test="contains($functionPrefix, 'CEILING') or
  175.                                             contains($functionPrefix, 'FLOOR')">
  176.                                 <xsl:call-template name="find-parameters">
  177.                                     <xsl:with-param name="rowPos" select="$rowPos" />
  178.                                     <xsl:with-param name="columnPos" select="$columnPos" />
  179.                                     <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  180.                                     <xsl:with-param name="parameterRemoval" select="3" />
  181.                                 </xsl:call-template>
  182.                             </xsl:when>
  183.                             <xsl:when test="contains($functionPrefix, 'IF')">
  184.                                 <xsl:if test="not(contains($functionPrefix, 'COUNTIF') or
  185.                                                   contains($functionPrefix, 'SUMIF'))">
  186.                                     <xsl:call-template name="find-parameters">
  187.                                         <xsl:with-param name="rowPos" select="$rowPos" />
  188.                                         <xsl:with-param name="columnPos" select="$columnPos" />
  189.                                         <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  190.                                         <xsl:with-param name="parameterAddition" select="'true'" />
  191.                                         <xsl:with-param name="additonAfterLastParameter" select="2" />
  192.                                     </xsl:call-template>
  193.                                 </xsl:if>
  194.                             </xsl:when>
  195.                             <xsl:when test="contains($functionPrefix, 'ROUND')">
  196.                                 <xsl:call-template name="find-parameters">
  197.                                     <xsl:with-param name="rowPos" select="$rowPos" />
  198.                                     <xsl:with-param name="columnPos" select="$columnPos" />
  199.                                     <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  200.                                     <xsl:with-param name="parameterAddition" select="'null'" />
  201.                                     <xsl:with-param name="additonAfterLastParameter" select="1" />
  202.                                 </xsl:call-template>
  203.                             </xsl:when>
  204.                         </xsl:choose>
  205.                     </xsl:otherwise>
  206.                 </xsl:choose>
  207.             </xsl:otherwise>
  208.         </xsl:choose>
  209.     </xsl:template>
  210.  
  211.     <!-- Each parameter of the argumentlist have to be determined.
  212.     Due to the low level string functionlity in XSLT it becomes a clumsy task -->
  213.     <xsl:template name="find-parameters">
  214.         <!-- used for mapping of row/column reference  -->
  215.         <xsl:param name="rowPos" /> <!-- the position in row (vertical of cell) -->
  216.         <xsl:param name="columnPos" /> <!-- the position in column (horizontal of cell) -->
  217.         <!-- used for mapping of parameter  -->
  218.         <xsl:param name="parameterRemoval" />
  219.         <xsl:param name="parameterAddition" />
  220.         <xsl:param name="additonAfterLastParameter" />
  221.         <!-- used as helper to find a parameter  -->
  222.         <xsl:param name="expressionSuffix" />
  223.         <xsl:param name="parameterNumber" select="1" />
  224.  
  225.         <xsl:variable name="parameter">
  226.             <xsl:call-template name="getParameter">
  227.                 <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  228.             </xsl:call-template>
  229.         </xsl:variable>
  230.  
  231.         <xsl:choose>
  232.             <!-- if it is not the last parameter -->
  233.             <xsl:when test="starts-with(substring-after($expressionSuffix, $parameter), ',')">
  234.                 <!-- searches the argument for functions to be mapped -->
  235.                 <xsl:if test="not($parameterRemoval = $parameterNumber)">
  236.                     <xsl:call-template name="function-parameter-mapping">
  237.                         <xsl:with-param name="rowPos" select="$rowPos" />
  238.                         <xsl:with-param name="columnPos" select="$columnPos" />
  239.                         <xsl:with-param name="expression">
  240.                             <xsl:choose>
  241.                                 <!-- in case a character will be removed the preceding won't make a comma -->
  242.                                 <xsl:when test="$parameterRemoval = ($parameterNumber + 1)">
  243.                                     <xsl:value-of select="$parameter" />
  244.                                 </xsl:when>
  245.                                 <xsl:otherwise>
  246.                                     <xsl:value-of select="concat($parameter, ',')" />
  247.                                 </xsl:otherwise>
  248.                             </xsl:choose>
  249.                         </xsl:with-param>
  250.                     </xsl:call-template>
  251.                 </xsl:if>
  252.                 <!-- searches for the next parameter -->
  253.                 <xsl:call-template name="find-parameters">
  254.                     <xsl:with-param name="rowPos" select="$rowPos" />
  255.                     <xsl:with-param name="columnPos" select="$columnPos" />
  256.                     <xsl:with-param name="expressionSuffix" select="substring-after(substring-after($expressionSuffix, $parameter),',')"/>
  257.                     <xsl:with-param name="parameterAddition" select="$parameterAddition" />
  258.                     <xsl:with-param name="parameterRemoval" select="$parameterRemoval" />
  259.                     <xsl:with-param name="additonAfterLastParameter" select="$additonAfterLastParameter" />
  260.                     <xsl:with-param name="parameterNumber" select="$parameterNumber + 1" />
  261.                 </xsl:call-template>
  262.             </xsl:when>
  263.             <xsl:otherwise>
  264.                 <!-- the last parameter -->
  265.                 <xsl:choose>
  266.                     <xsl:when test="$parameterRemoval = $parameterNumber">
  267.                         <!-- searches the rest of the expression for functions to be mapped -->
  268.                         <xsl:call-template name="function-parameter-mapping">
  269.                             <xsl:with-param name="rowPos" select="$rowPos" />
  270.                             <xsl:with-param name="columnPos" select="$columnPos" />
  271.                             <xsl:with-param name="expression" select="substring-after($expressionSuffix, $parameter)"/>
  272.                         </xsl:call-template>
  273.                     </xsl:when>
  274.                     <xsl:when test="$parameterAddition and ($parameterNumber  = $additonAfterLastParameter)">
  275.                         <!-- searches the rest of the expression for functions to be mapped -->
  276.                         <xsl:call-template name="function-parameter-mapping">
  277.                             <xsl:with-param name="rowPos" select="$rowPos" />
  278.                             <xsl:with-param name="columnPos" select="$columnPos" />
  279.                             <xsl:with-param name="expression" select="$parameter" />
  280.                         </xsl:call-template>
  281.                         <!-- searches last parameter and additional parameters for functions to be mapped -->
  282.                         <xsl:call-template name="function-parameter-mapping">
  283.                             <xsl:with-param name="rowPos" select="$rowPos" />
  284.                             <xsl:with-param name="columnPos" select="$columnPos" />
  285.                             <!-- for the final parameter the latter substring is the ')' -->
  286.                             <xsl:with-param name="expression" select="concat(',', $parameterAddition, substring-after($expressionSuffix, $parameter))"/>
  287.                         </xsl:call-template>
  288.                     </xsl:when>
  289.                     <xsl:otherwise>
  290.                         <!-- searches the argument for functions to be mapped -->
  291.                         <xsl:call-template name="function-parameter-mapping">
  292.                             <xsl:with-param name="rowPos" select="$rowPos" />
  293.                             <xsl:with-param name="columnPos" select="$columnPos" />
  294.                             <xsl:with-param name="expression" select="$parameter" />
  295.                         </xsl:call-template>
  296.                         <!-- searches the rest of the expression for functions to be mapped -->
  297.                         <xsl:call-template name="function-parameter-mapping">
  298.                             <xsl:with-param name="rowPos" select="$rowPos" />
  299.                             <xsl:with-param name="columnPos" select="$columnPos" />
  300.                             <xsl:with-param name="expression" select="substring-after($expressionSuffix, $parameter)"/>
  301.                         </xsl:call-template>
  302.                     </xsl:otherwise>
  303.                 </xsl:choose>
  304.             </xsl:otherwise>
  305.         </xsl:choose>
  306.     </xsl:template>
  307.  
  308.     <xsl:template name="getParameter">
  309.         <xsl:param name="closingBracketCount" select="0" />
  310.         <xsl:param name="openingBracketCount" select="0" />
  311.         <xsl:param name="expressionSuffix" />
  312.         <xsl:param name="parameterCandidate">
  313.             <xsl:choose>
  314.                 <!-- if there are multiple parameter -->
  315.                 <xsl:when test="contains(substring-before($expressionSuffix, ')'), ',')">
  316.                     <xsl:value-of select="substring-before($expressionSuffix, ',')"/>
  317.                 </xsl:when>
  318.                 <xsl:otherwise>
  319.                     <xsl:value-of select="substring-before($expressionSuffix, ')')"/>
  320.                 </xsl:otherwise>
  321.             </xsl:choose>
  322.         </xsl:param>
  323.         <xsl:param name="earlierCandidate" select="$parameterCandidate" />
  324.  
  325.         <xsl:choose>
  326.             <xsl:when test="contains($parameterCandidate, '(') or contains($parameterCandidate, ')')">
  327.                 <xsl:choose>
  328.                     <!-- contains only closing bracket(s) -->
  329.                     <xsl:when test="contains($parameterCandidate, '(') and not(contains($parameterCandidate, ')'))">
  330.                         <xsl:call-template name="getParameter">
  331.                             <xsl:with-param name="openingBracketCount" select="$openingBracketCount + 1" />
  332.                             <xsl:with-param name="closingBracketCount" select="$closingBracketCount" />
  333.                             <xsl:with-param name="parameterCandidate" select="substring-after($parameterCandidate, '(')" />
  334.                             <xsl:with-param name="earlierCandidate" select="$earlierCandidate" />
  335.                             <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  336.                         </xsl:call-template>
  337.                     </xsl:when>
  338.                     <!-- contains only opening bracket(s) -->
  339.                     <xsl:when test="not(contains($parameterCandidate, '(')) and contains($parameterCandidate, ')')">
  340.                         <xsl:call-template name="getParameter">
  341.                             <xsl:with-param name="openingBracketCount" select="$openingBracketCount" />
  342.                             <xsl:with-param name="closingBracketCount" select="$closingBracketCount + 1" />
  343.                             <xsl:with-param name="parameterCandidate" select="substring-after($parameterCandidate, ')')" />
  344.                             <xsl:with-param name="earlierCandidate" select="$earlierCandidate" />
  345.                             <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  346.                         </xsl:call-template>
  347.                     </xsl:when>
  348.                     <xsl:otherwise>
  349.                         <xsl:choose>
  350.                             <xsl:when test="string-length(substring-before($parameterCandidate, '(')) <
  351.                                             string-length(substring-before($parameterCandidate, ')'))">
  352.                                 <xsl:call-template name="getParameter">
  353.                                     <xsl:with-param name="openingBracketCount" select="$openingBracketCount + 1" />
  354.                                     <xsl:with-param name="closingBracketCount" select="$closingBracketCount" />
  355.                                     <xsl:with-param name="parameterCandidate" select="substring-after($parameterCandidate, '(')" />
  356.                                     <xsl:with-param name="earlierCandidate" select="$earlierCandidate" />
  357.                                     <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  358.                                 </xsl:call-template>
  359.                             </xsl:when>
  360.                             <xsl:otherwise>
  361.                                 <xsl:call-template name="getParameter">
  362.                                     <xsl:with-param name="openingBracketCount" select="$openingBracketCount" />
  363.                                     <xsl:with-param name="closingBracketCount" select="$closingBracketCount + 1" />
  364.                                     <xsl:with-param name="parameterCandidate" select="substring-after($parameterCandidate, ')')" />
  365.                                     <xsl:with-param name="earlierCandidate" select="$earlierCandidate" />
  366.                                     <xsl:with-param name="expressionSuffix" select="$expressionSuffix"/>
  367.                                 </xsl:call-template>
  368.                             </xsl:otherwise>
  369.                         </xsl:choose>
  370.                     </xsl:otherwise>
  371.                 </xsl:choose>
  372.             </xsl:when>
  373.             <xsl:otherwise>
  374.                 <xsl:choose>
  375.                     <xsl:when test="$openingBracketCount = $closingBracketCount">
  376.                         <xsl:value-of select="$earlierCandidate" />
  377.                     </xsl:when>
  378.                     <xsl:otherwise>
  379.                         <xsl:value-of select="$earlierCandidate" />
  380.                         <xsl:variable name="parameterCandidate2">
  381.                             <xsl:variable name="formularAfterCandidate" select="substring-after($expressionSuffix, $earlierCandidate)" />
  382.                             <xsl:variable name="parameterTillBracket" select="concat(substring-before($formularAfterCandidate,')'),')')" />
  383.                             <xsl:variable name="parameterTillComma" select="substring-before(substring-after($expressionSuffix, $parameterTillBracket),',')" />
  384.                             <xsl:choose>
  385.                                 <xsl:when test="string-length($parameterTillComma) > 0 and
  386.                                                 not(contains($parameterTillComma, '('))">
  387.                                     <xsl:choose>
  388.                                         <xsl:when test="starts-with($formularAfterCandidate, ',')">
  389.                                             <xsl:value-of select="concat(',',substring-before(substring-after($formularAfterCandidate,','),','))"/>
  390.                                         </xsl:when>
  391.                                         <xsl:otherwise>
  392.                                             <xsl:value-of select="substring-before($formularAfterCandidate,',')"/>
  393.                                         </xsl:otherwise>
  394.                                     </xsl:choose>
  395.                                 </xsl:when>
  396.                                 <xsl:otherwise>
  397.                                     <xsl:value-of select="$parameterTillBracket"/>
  398.                                 </xsl:otherwise>
  399.                             </xsl:choose>
  400.                         </xsl:variable>
  401.                         <xsl:call-template name="getParameter">
  402.                             <xsl:with-param name="closingBracketCount" select="$closingBracketCount" />
  403.                             <xsl:with-param name="openingBracketCount" select="$openingBracketCount" />
  404.                             <xsl:with-param name="parameterCandidate" select="$parameterCandidate2" />
  405.                             <xsl:with-param name="earlierCandidate" select="$parameterCandidate2" />
  406.                             <xsl:with-param name="expressionSuffix" select="$expressionSuffix" />
  407.                         </xsl:call-template>
  408.                     </xsl:otherwise>
  409.                 </xsl:choose>
  410.             </xsl:otherwise>
  411.         </xsl:choose>
  412.     </xsl:template>
  413.  
  414.     <!-- Mapping table-cell definitions by exchangomg all table cell definitions:
  415.         a) a pair of cells e.g. "[.E14:.F21]" to "R[-17]C[3]:R[-10]C[4]"
  416.         b) a single cell e.g. "[.F14]" to "R[-17]"-->
  417.     <xsl:template name="translate-oooc-expression">
  418.         <xsl:param name="rowPos" /> <!-- the position in row (vertical of cell) -->
  419.         <xsl:param name="columnPos" /> <!-- the position in column (horizontal of cell) -->
  420.         <xsl:param name="expression" /> <!-- expression to be exchanged -->
  421.  
  422.         <xsl:choose>
  423.             <xsl:when test="contains($expression, '[')">
  424.  
  425.                 <!-- Giving out the part before '[.' -->
  426.                 <xsl:value-of select="substring-before($expression, '[')" />
  427.  
  428.                 <!-- Mapping cell definitions
  429.                 1) a pair of cells e.g. "[.E14:.F21]" to "R[-17]C[3]:R[-10]C[4]"
  430.                 2) a single cell e.g. "[.F14]" to "R[-17]"-->
  431.                 <xsl:variable name="remainingExpression" select="substring-after($expression, '[')"/>
  432.                 <xsl:choose>
  433.                     <xsl:when test="contains(substring-before($remainingExpression, ']'), ':')">
  434.                         <xsl:call-template name="translate-cell-expression">
  435.                             <xsl:with-param name="rowPos" select="$rowPos" />
  436.                             <xsl:with-param name="columnPos" select="$columnPos" />
  437.                             <xsl:with-param name="expression" select="substring-before($remainingExpression, ':')" />
  438.                         </xsl:call-template>
  439.                         <xsl:value-of select="':'" />
  440.                         <xsl:call-template name="translate-cell-expression">
  441.                             <xsl:with-param name="rowPos" select="$rowPos" />
  442.                             <xsl:with-param name="columnPos" select="$columnPos" />
  443.                             <xsl:with-param name="expression" select="substring-after(substring-before($remainingExpression, ']'), ':')" />
  444.                         </xsl:call-template>
  445.                     </xsl:when>
  446.                     <xsl:otherwise>
  447.                         <xsl:call-template name="translate-cell-expression">
  448.                             <xsl:with-param name="rowPos" select="$rowPos" />
  449.                             <xsl:with-param name="columnPos" select="$columnPos" />
  450.                             <xsl:with-param name="expression" select="substring-before($remainingExpression, ']')" />
  451.                         </xsl:call-template>
  452.                     </xsl:otherwise>
  453.                 </xsl:choose>
  454.                 <xsl:call-template name="translate-oooc-expression">
  455.                     <xsl:with-param name="rowPos" select="$rowPos" />
  456.                     <xsl:with-param name="columnPos" select="$columnPos" />
  457.                     <xsl:with-param name="expression" select="substring-after($remainingExpression,']')"/>
  458.                 </xsl:call-template>
  459.             </xsl:when>
  460.             <xsl:otherwise>
  461.                 <!-- Giving out the remaining part -->
  462.                 <xsl:value-of select="$expression" />
  463.             </xsl:otherwise>
  464.         </xsl:choose>
  465.     </xsl:template>
  466.  
  467.  
  468.     <!-- A cell expression has usually starts with a '.' otherwise it references to a sheet  -->
  469.     <xsl:template name="translate-cell-expression">
  470.         <xsl:param name="rowPos" /> <!-- the vertical position of the current cell -->
  471.         <xsl:param name="columnPos" /> <!-- the horizontal position of the current cell -->
  472.         <xsl:param name="targetRowPos" select="0"/> <!-- the vertical position of the target cell -->
  473.         <xsl:param name="targetColumnPos" select="0"/> <!-- the horizontal position of the target cell -->
  474.         <xsl:param name="charPos" select="0"/> <!-- current column position (needed for multiplying) -->
  475.         <xsl:param name="digitPos" select="0"/>  <!-- current row position (needed for multiplying) -->
  476.         <xsl:param name="expression" /> <!-- expression to be parsed by character -->
  477.         <xsl:param name="isRow" select="true()"/> <!-- the string (e.g. $D39 is parsed character per character from the back,
  478.                                                        first the row, later the column is parsed -->
  479.  
  480.         <xsl:choose>
  481.             <xsl:when test="starts-with($expression, '.')">
  482.                 <xsl:variable name="expLength" select="string-length($expression)" />
  483.                 <xsl:choose>
  484.                     <!-- parsing from the end, till only the '.' remains -->
  485.                     <xsl:when test="$expLength != 1">
  486.                         <xsl:variable name="token" select="substring($expression, $expLength)" />
  487.                         <xsl:choose>
  488.                             <xsl:when test="$token='0' or $token='1' or $token='2' or $token='3' or $token='4' or $token='5' or $token='6' or $token='7' or $token='8' or $token='9'">
  489.                                 <xsl:variable name="multiplier">
  490.                                     <xsl:call-template name="calculate-square-numbers">
  491.                                         <xsl:with-param name="base" select="10" />
  492.                                         <xsl:with-param name="exponent" select="$digitPos"/>
  493.                                     </xsl:call-template>
  494.                                 </xsl:variable>
  495.                                 <xsl:call-template name="translate-cell-expression">
  496.                                     <xsl:with-param name="columnPos" select="$columnPos" />
  497.                                     <xsl:with-param name="rowPos" select="$rowPos" />
  498.                                     <xsl:with-param name="targetColumnPos" select="$targetColumnPos" />
  499.                                     <xsl:with-param name="targetRowPos" select="$targetRowPos + $multiplier * $token" />
  500.                                     <xsl:with-param name="digitPos" select="$digitPos + 1" />
  501.                                     <xsl:with-param name="charPos" select="$charPos" />
  502.                                     <!-- removing the last character-->
  503.                                     <xsl:with-param name="expression" select="substring($expression, 1, $expLength - 1)" />
  504.                                     <xsl:with-param name="isRow" select="true()" />
  505.                                 </xsl:call-template>
  506.                             </xsl:when>
  507.                             <xsl:when test="$token = '$'">
  508.                                 <xsl:choose>
  509.                                     <!-- if this is the first '$' after '.' (column-->
  510.                                     <xsl:when test="$expLength = 2">
  511.                                         <xsl:text>C</xsl:text><xsl:value-of select="$targetColumnPos"/>
  512.                                     </xsl:when>
  513.                                     <xsl:otherwise>
  514.                                         <xsl:text>R</xsl:text><xsl:value-of select="$targetRowPos"/>
  515.                                         <xsl:call-template name="translate-cell-expression">
  516.                                             <xsl:with-param name="columnPos" select="$columnPos" />
  517.                                             <xsl:with-param name="rowPos" select="$rowPos" />
  518.                                             <xsl:with-param name="targetColumnPos" select="$targetColumnPos" />
  519.                                             <xsl:with-param name="targetRowPos" select="$targetRowPos" />
  520.                                             <xsl:with-param name="charPos" select="$charPos" />
  521.                                             <!-- removing the last character-->
  522.                                             <xsl:with-param name="expression" select="substring($expression, 1, $expLength - 1)" />
  523.                                             <xsl:with-param name="isRow" select="false()" />
  524.                                         </xsl:call-template>
  525.                                     </xsl:otherwise>
  526.                                 </xsl:choose>
  527.                             </xsl:when>
  528.                             <!-- in case of a letter -->
  529.                             <xsl:otherwise>
  530.                                 <xsl:if test="$isRow">
  531.                                     <xsl:text>R</xsl:text>
  532.                                     <xsl:if test="$targetRowPos != $rowPos">
  533.                                         <xsl:text>[</xsl:text><xsl:value-of select="$targetRowPos - $rowPos"/><xsl:text>]</xsl:text>
  534.                                     </xsl:if>
  535.                                 </xsl:if>
  536.                                 <xsl:variable name="multiplier">
  537.                                     <xsl:call-template name="calculate-square-numbers">
  538.                                         <xsl:with-param name="base" select="26" />
  539.                                         <xsl:with-param name="exponent" select="$charPos"/>
  540.                                     </xsl:call-template>
  541.                                 </xsl:variable>
  542.                                 <xsl:variable name="tokenNumber">
  543.                                     <xsl:call-template name="character-to-number">
  544.                                         <xsl:with-param name="character" select="$token" />
  545.                                     </xsl:call-template>
  546.                                 </xsl:variable>
  547.  
  548.                                 <xsl:call-template name="translate-cell-expression">
  549.                                     <xsl:with-param name="columnPos" select="$columnPos" />
  550.                                     <xsl:with-param name="rowPos" select="$rowPos" />
  551.                                     <xsl:with-param name="targetColumnPos" select="$targetColumnPos + $multiplier * $tokenNumber" />
  552.                                     <xsl:with-param name="targetRowPos" select="$targetRowPos" />
  553.                                     <xsl:with-param name="digitPos" select="$digitPos" />
  554.                                     <xsl:with-param name="charPos" select="$charPos + 1" />
  555.                                     <!-- removing the last character-->
  556.                                     <xsl:with-param name="expression" select="substring($expression, 1, $expLength - 1)" />
  557.                                     <xsl:with-param name="isRow" select="false()" />
  558.                                 </xsl:call-template>
  559.                             </xsl:otherwise>
  560.                         </xsl:choose>
  561.                     </xsl:when>
  562.                     <xsl:otherwise>
  563.                         <xsl:text>C</xsl:text>
  564.                         <xsl:if test="$targetColumnPos != $columnPos">
  565.                             <xsl:text>[</xsl:text><xsl:value-of select="$targetColumnPos - $columnPos"/><xsl:text>]</xsl:text>
  566.                         </xsl:if>
  567.                     </xsl:otherwise>
  568.                 </xsl:choose>
  569.             </xsl:when>
  570.             <xsl:otherwise>
  571.                 <xsl:variable name="sheetName" select="substring-before($expression, '.')" />
  572.                 <xsl:value-of select="$sheetName"/><xsl:text>!</xsl:text>
  573.                 <xsl:call-template name="translate-cell-expression">
  574.                     <xsl:with-param name="rowPos" select="$rowPos" />
  575.                     <xsl:with-param name="columnPos" select="$columnPos" />
  576.                     <xsl:with-param name="expression" select="substring-after($expression, $sheetName)" />
  577.                 </xsl:call-template>
  578.             </xsl:otherwise>
  579.         </xsl:choose>
  580.     </xsl:template>
  581.  
  582.  
  583.     <xsl:template name="calculate-square-numbers">
  584.         <xsl:param name="base" />
  585.         <xsl:param name="exponent" />
  586.         <xsl:param name="return" select="1" />
  587.  
  588.         <xsl:choose>
  589.             <xsl:when test="$exponent > '1'">
  590.                 <xsl:call-template name="calculate-square-numbers">
  591.                     <xsl:with-param name="base" select="$base" />
  592.                     <xsl:with-param name="exponent" select="$exponent - 1"/>
  593.                     <xsl:with-param name="return" select="$return * $base" />
  594.                 </xsl:call-template>
  595.             </xsl:when>
  596.             <xsl:when test="$exponent = '1'">
  597.                 <xsl:value-of select="$return * $base"/>
  598.             </xsl:when>
  599.             <!-- if exponent is equal '0' -->
  600.             <xsl:otherwise>
  601.                 <xsl:value-of select="1"/>
  602.             </xsl:otherwise>
  603.         </xsl:choose>
  604.     </xsl:template>
  605.  
  606.  
  607.     <xsl:template name="character-to-number">
  608.         <xsl:param name="character" />
  609.         <xsl:choose>
  610.             <xsl:when test="$character = 'A'">1</xsl:when>
  611.             <xsl:when test="$character = 'B'">2</xsl:when>
  612.             <xsl:when test="$character = 'C'">3</xsl:when>
  613.             <xsl:when test="$character = 'D'">4</xsl:when>
  614.             <xsl:when test="$character = 'E'">5</xsl:when>
  615.             <xsl:when test="$character = 'F'">6</xsl:when>
  616.             <xsl:when test="$character = 'G'">7</xsl:when>
  617.             <xsl:when test="$character = 'H'">8</xsl:when>
  618.             <xsl:when test="$character = 'I'">9</xsl:when>
  619.             <xsl:when test="$character = 'J'">10</xsl:when>
  620.             <xsl:when test="$character = 'K'">11</xsl:when>
  621.             <xsl:when test="$character = 'L'">12</xsl:when>
  622.             <xsl:when test="$character = 'M'">13</xsl:when>
  623.             <xsl:when test="$character = 'N'">14</xsl:when>
  624.             <xsl:when test="$character = 'O'">15</xsl:when>
  625.             <xsl:when test="$character = 'P'">16</xsl:when>
  626.             <xsl:when test="$character = 'Q'">17</xsl:when>
  627.             <xsl:when test="$character = 'R'">18</xsl:when>
  628.             <xsl:when test="$character = 'S'">19</xsl:when>
  629.             <xsl:when test="$character = 'T'">20</xsl:when>
  630.             <xsl:when test="$character = 'U'">21</xsl:when>
  631.             <xsl:when test="$character = 'V'">22</xsl:when>
  632.             <xsl:when test="$character = 'W'">23</xsl:when>
  633.             <xsl:when test="$character = 'X'">24</xsl:when>
  634.             <xsl:when test="$character = 'Y'">25</xsl:when>
  635.             <xsl:when test="$character = 'Z'">26</xsl:when>
  636.             <xsl:otherwise/>
  637.         </xsl:choose>
  638.     </xsl:template>
  639.  
  640. </xsl:stylesheet>
  641.