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 / math.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2010-12-01  |  26.5 KB  |  590 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. <!--
  29.      xslt math lib by Wind Li
  30. Public Functions
  31.     sin(x,rounding-factor=100)
  32.     cos(x,rounding-factor=100)
  33.     tan(x,rounding-factor=100)
  34.     ctan(x,rounding-factor=100)
  35.     atan2(x, y ,rounding-factor=100)
  36.     atan(x,rounding-factor=100)
  37.     acos(x,rounding-factor=100)
  38.     asin(x,rounding-factor=100)
  39.     abs(x)
  40.     max(x1,x2)
  41.     min(x1,x2)
  42.     power(x,power(interger only), rounding-factor=100)
  43.     sqrt(x, rounding-factor=100)
  44.     convert2radian(x,rounding-factor=100)
  45.     convert2degree(x,rounding-factor=100)
  46.     convert2fd(x,rounding-factor=100)
  47.  -->
  48. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 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:text="http://openoffice.org/2000/text" xmlns:style="http://openoffice.org/2000/style" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:office="http://openoffice.org/2000/office" exclude-result-prefixes="draw svg style office fo text">
  49.     <xsl:variable name="pi" select="3.1416"/>
  50.     <xsl:template name="math-test">
  51.         sin(34.8)
  52.         <xsl:call-template name="sin">
  53.             <xsl:with-param name="x" select="34.8"/>
  54.             <xsl:with-param name="rounding-factor" select="100000"/>
  55.         </xsl:call-template>
  56.         cos(34.8)
  57.         <xsl:call-template name="cos">
  58.             <xsl:with-param name="x" select="34.8"/>
  59.             <xsl:with-param name="rounding-factor" select="100000"/>
  60.         </xsl:call-template>
  61.         atan(2.74)
  62.         <xsl:call-template name="atan">
  63.             <xsl:with-param name="x" select="2.74"/>
  64.             <xsl:with-param name="rounding-factor" select="100000"/>
  65.         </xsl:call-template>
  66.         acos(0.5)
  67.         <xsl:call-template name="acos">
  68.             <xsl:with-param name="x" select="0.5"/>
  69.             <xsl:with-param name="rounding-factor" select="100000"/>
  70.         </xsl:call-template>
  71.         asin(0.5)
  72.         <xsl:call-template name="asin">
  73.             <xsl:with-param name="x" select="0.5"/>
  74.             <xsl:with-param name="rounding-factor" select="100000"/>
  75.         </xsl:call-template>
  76.         sqrt(1328.3414)
  77.         <xsl:call-template name="sqrt">
  78.             <xsl:with-param name="x" select="1328.3414"/>
  79.             <xsl:with-param name="rounding-factor" select="100000"/>
  80.         </xsl:call-template>
  81.     </xsl:template>
  82.     <!-- public functions start -->
  83.     <xsl:template name="sin">
  84.         <xsl:param name="x" select="0"/>
  85.         <xsl:param name="rounding-factor" select="100"/>
  86.         <xsl:variable name="angle" select="$x * 180 div $pi "/>
  87.         <xsl:variable name="mod-angle" select="$angle mod 360"/>
  88.         <xsl:variable name="sinx">
  89.             <xsl:call-template name="sin-private">
  90.                 <xsl:with-param name="x" select="  ( $angle mod 360 )  * $pi div 180 "/>
  91.             </xsl:call-template>
  92.         </xsl:variable>
  93.         <xsl:value-of select=" round ( number($sinx) * $rounding-factor ) div $rounding-factor"/>
  94.     </xsl:template>
  95.     <xsl:template name="cos">
  96.         <xsl:param name="x" select="0"/>
  97.         <xsl:param name="rounding-factor" select="100"/>
  98.         <xsl:variable name="angle" select="$x * 180 div $pi "/>
  99.         <xsl:variable name="mod-angle" select="$angle mod 360"/>
  100.         <xsl:variable name="cosx">
  101.             <xsl:call-template name="cos-private">
  102.                 <xsl:with-param name="x" select="  ( $angle mod 360 )  * $pi div 180 "/>
  103.             </xsl:call-template>
  104.         </xsl:variable>
  105.         <xsl:value-of select=" round ( number($cosx) * $rounding-factor ) div $rounding-factor"/>
  106.     </xsl:template>
  107.     <xsl:template name="tan">
  108.         <xsl:param name="x" select="0"/>
  109.         <xsl:param name="rounding-factor" select="100"/>
  110.         <xsl:variable name="sinx">
  111.             <xsl:call-template name="sin">
  112.                 <xsl:with-param name="x" select="$x"/>
  113.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  114.             </xsl:call-template>
  115.         </xsl:variable>
  116.         <xsl:variable name="cosx">
  117.             <xsl:call-template name="cos">
  118.                 <xsl:with-param name="x" select="$x"/>
  119.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  120.             </xsl:call-template>
  121.         </xsl:variable>
  122.         <xsl:choose>
  123.             <xsl:when test=" $cosx = 0 ">
  124.                 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
  125.                 <xsl:value-of select="63535"/>
  126.             </xsl:when>
  127.             <xsl:otherwise>
  128.                 <xsl:value-of select=" round( $sinx div $cosx * $rounding-factor) div $rounding-factor"/>
  129.             </xsl:otherwise>
  130.         </xsl:choose>
  131.     </xsl:template>
  132.     <xsl:template name="ctan">
  133.         <xsl:param name="x" select="0"/>
  134.         <xsl:param name="rounding-factor" select="100"/>
  135.         <xsl:variable name="sinx">
  136.             <xsl:call-template name="sin">
  137.                 <xsl:with-param name="x" select="$x"/>
  138.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  139.             </xsl:call-template>
  140.         </xsl:variable>
  141.         <xsl:variable name="cosx">
  142.             <xsl:call-template name="cos">
  143.                 <xsl:with-param name="x" select="$x"/>
  144.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  145.             </xsl:call-template>
  146.         </xsl:variable>
  147.         <xsl:choose>
  148.             <xsl:when test=" $sinx = 0 ">
  149.                 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
  150.                 <xsl:value-of select="63535"/>
  151.             </xsl:when>
  152.             <xsl:otherwise>
  153.                 <xsl:value-of select=" round( $cosx div $sinx * $rounding-factor) div $rounding-factor"/>
  154.             </xsl:otherwise>
  155.         </xsl:choose>
  156.     </xsl:template>
  157.     <xsl:template name="atan">
  158.         <xsl:param name="x" select="0"/>
  159.         <xsl:param name="rounding-factor" select="100"/>
  160.         <xsl:choose>
  161.             <xsl:when test="$x = 0">
  162.                 <xsl:value-of select="0"/>
  163.             </xsl:when>
  164.             <xsl:when test="$x < 0">
  165.                 <xsl:variable name="atan-x">
  166.                     <xsl:call-template name="atan">
  167.                         <xsl:with-param name="x" select=" -1 * $x"/>
  168.                         <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  169.                     </xsl:call-template>
  170.                 </xsl:variable>
  171.                 <xsl:value-of select="-1 * $atan-x"/>
  172.             </xsl:when>
  173.             <xsl:when test="$x > 1">
  174.                 <xsl:variable name="atan-div-x">
  175.                     <xsl:call-template name="atan">
  176.                         <xsl:with-param name="x" select="1 div $x "/>
  177.                         <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  178.                     </xsl:call-template>
  179.                 </xsl:variable>
  180.                 <xsl:value-of select=" $pi div 2 - $atan-div-x"/>
  181.             </xsl:when>
  182.             <xsl:otherwise>
  183.                 <xsl:variable name="arctanx">
  184.                     <xsl:call-template name="atan-private">
  185.                         <xsl:with-param name="x" select="  $x "/>
  186.                     </xsl:call-template>
  187.                 </xsl:variable>
  188.                 <xsl:value-of select=" round ( number($arctanx) * $rounding-factor ) div $rounding-factor"/>
  189.             </xsl:otherwise>
  190.         </xsl:choose>
  191.     </xsl:template>
  192.     <xsl:template name="atan2">
  193.         <xsl:param name="x"/>
  194.         <xsl:param name="y"/>
  195.         <xsl:param name="rounding-factor" select="100"/>
  196.         <xsl:choose>
  197.             <xsl:when test="$x = 0">
  198.                 <xsl:value-of select=" $pi div 2"/>
  199.             </xsl:when>
  200.             <xsl:otherwise>
  201.                 <xsl:call-template name="atan">
  202.                     <xsl:with-param name="x" select="$y div $x"/>
  203.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  204.                 </xsl:call-template>
  205.             </xsl:otherwise>
  206.         </xsl:choose>
  207.     </xsl:template>
  208.     <xsl:template name="acos">
  209.         <xsl:param name="x"/>
  210.         <xsl:param name="rounding-factor" select="100"/>
  211.         <xsl:variable name="abs-x">
  212.             <xsl:call-template name="abs">
  213.                 <xsl:with-param name="x" select="$x"/>
  214.             </xsl:call-template>
  215.         </xsl:variable>
  216.         <xsl:choose>
  217.             <xsl:when test="$abs-x  >  1">
  218.                 <xsl:message>acos error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
  219.             </xsl:when>
  220.             <xsl:otherwise>
  221.                 <xsl:call-template name="atan2">
  222.                     <xsl:with-param name="x" select="$x"/>
  223.                     <xsl:with-param name="y">
  224.                         <xsl:call-template name="sqrt">
  225.                             <xsl:with-param name="x" select="1 - $x * $x"/>
  226.                             <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
  227.                         </xsl:call-template>
  228.                     </xsl:with-param>
  229.                 </xsl:call-template>
  230.             </xsl:otherwise>
  231.         </xsl:choose>
  232.     </xsl:template>
  233.     <xsl:template name="asin">
  234.         <xsl:param name="x"/>
  235.         <xsl:param name="rounding-factor" select="100"/>
  236.         <xsl:variable name="abs-x">
  237.             <xsl:call-template name="abs">
  238.                 <xsl:with-param name="x" select="$x"/>
  239.             </xsl:call-template>
  240.         </xsl:variable>
  241.         <xsl:choose>
  242.             <xsl:when test="$abs-x  >  1">
  243.                 <xsl:message>asin error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
  244.             </xsl:when>
  245.             <xsl:otherwise>
  246.                 <xsl:call-template name="atan2">
  247.                     <xsl:with-param name="y" select="$x"/>
  248.                     <xsl:with-param name="x">
  249.                         <xsl:call-template name="sqrt">
  250.                             <xsl:with-param name="x" select="1 - $x * $x"/>
  251.                             <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
  252.                         </xsl:call-template>
  253.                     </xsl:with-param>
  254.                 </xsl:call-template>
  255.             </xsl:otherwise>
  256.         </xsl:choose>
  257.     </xsl:template>
  258.     <xsl:template name="abs">
  259.         <xsl:param name="x"/>
  260.         <xsl:choose>
  261.             <xsl:when test="$x > 0">
  262.                 <xsl:value-of select="$x"/>
  263.             </xsl:when>
  264.             <xsl:otherwise>
  265.                 <xsl:value-of select="$x * -1"/>
  266.             </xsl:otherwise>
  267.         </xsl:choose>
  268.     </xsl:template>
  269.     <xsl:template name="max">
  270.         <xsl:param name="x1"/>
  271.         <xsl:param name="x2"/>
  272.         <xsl:choose>
  273.             <xsl:when test="$x1 >  $x2">
  274.                 <xsl:value-of select="$x1"/>
  275.             </xsl:when>
  276.             <xsl:otherwise>
  277.                 <xsl:value-of select="$x2"/>
  278.             </xsl:otherwise>
  279.         </xsl:choose>
  280.     </xsl:template>
  281.     <xsl:template name="min">
  282.         <xsl:param name="x1"/>
  283.         <xsl:param name="x2"/>
  284.         <xsl:choose>
  285.             <xsl:when test="$x1 <  $x2">
  286.                 <xsl:value-of select="$x1"/>
  287.             </xsl:when>
  288.             <xsl:otherwise>
  289.                 <xsl:value-of select="$x2"/>
  290.             </xsl:otherwise>
  291.         </xsl:choose>
  292.     </xsl:template>
  293.     <xsl:template name="power">
  294.         <xsl:param name="x"/>
  295.         <xsl:param name="y" select="1"/>
  296.         <xsl:param name="rounding-factor" select="100"/>
  297.         <!--  z is a private param -->
  298.         <xsl:param name="z" select="1"/>
  299.         <xsl:choose>
  300.             <xsl:when test="$y > 0">
  301.                 <xsl:call-template name="power">
  302.                     <xsl:with-param name="x" select="$x"/>
  303.                     <xsl:with-param name="y" select="$y - 1"/>
  304.                     <xsl:with-param name="z" select="$z * $x"/>
  305.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  306.                 </xsl:call-template>
  307.             </xsl:when>
  308.             <xsl:otherwise>
  309.                 <xsl:value-of select=" round( $z * $rounding-factor) div $rounding-factor"/>
  310.             </xsl:otherwise>
  311.         </xsl:choose>
  312.     </xsl:template>
  313.     <xsl:template name="sqrt">
  314.         <xsl:param name="x"/>
  315.         <xsl:param name="rounding-factor" select="100"/>
  316.         <xsl:choose>
  317.             <xsl:when test="$x = 0">0</xsl:when>
  318.             <xsl:when test="$x < 0">
  319.                 <xsl:message>sqrt error : <xsl:value-of select="$x"/>  less then 0!</xsl:message>
  320.             </xsl:when>
  321.             <xsl:otherwise>
  322.                 <xsl:call-template name="sqrt-private">
  323.                     <xsl:with-param name="x" select="$x"/>
  324.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  325.                 </xsl:call-template>
  326.             </xsl:otherwise>
  327.         </xsl:choose>
  328.     </xsl:template>
  329.     <!-- public functions end -->
  330.     <!--
  331. Private functions:
  332. sin-private
  333. cos-private
  334. atan-private
  335. sqrt-private
  336. integer-sqrt
  337. Sqrt-GetOneDigit
  338. -->
  339.     <xsl:template name="sin-private">
  340.         <xsl:param name="x" select="0"/>
  341.         <xsl:param name="n" select="0"/>
  342.         <xsl:param name="nx" select="1"/>
  343.         <xsl:param name="sign" select="1"/>
  344.         <xsl:param name="max-n" select="20"/>
  345.         <xsl:param name="sinx" select="0"/>
  346.         <xsl:choose>
  347.             <xsl:when test="not ($max-n >  $n) or $nx = 0 ">
  348.                 <xsl:value-of select="$sinx"/>
  349.             </xsl:when>
  350.             <xsl:when test="$n = 0">
  351.                 <xsl:call-template name="sin-private">
  352.                     <xsl:with-param name="x" select="$x"/>
  353.                     <xsl:with-param name="n" select="$n + 1"/>
  354.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  355.                     <xsl:with-param name="max-n" select="$max-n"/>
  356.                     <xsl:with-param name="nx" select="$x "/>
  357.                     <xsl:with-param name="sinx" select="$sinx + $x"/>
  358.                 </xsl:call-template>
  359.             </xsl:when>
  360.             <xsl:otherwise>
  361.                 <xsl:variable name="new-nx" select="($nx * $x * $x)  div ( 2  *  $n )  div ( 2  *  $n  + 1)  "/>
  362.                 <xsl:call-template name="sin-private">
  363.                     <xsl:with-param name="x" select="$x"/>
  364.                     <xsl:with-param name="n" select="$n + 1"/>
  365.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  366.                     <xsl:with-param name="max-n" select="$max-n"/>
  367.                     <xsl:with-param name="nx" select=" $new-nx "/>
  368.                     <xsl:with-param name="sinx" select="$sinx + $new-nx  * $sign"/>
  369.                 </xsl:call-template>
  370.             </xsl:otherwise>
  371.         </xsl:choose>
  372.     </xsl:template>
  373.     <xsl:template name="cos-private">
  374.         <xsl:param name="x" select="0"/>
  375.         <xsl:param name="n" select="0"/>
  376.         <xsl:param name="nx" select="1"/>
  377.         <xsl:param name="sign" select="1"/>
  378.         <xsl:param name="max-n" select="20"/>
  379.         <xsl:param name="cosx" select="0"/>
  380.         <xsl:choose>
  381.             <xsl:when test="not ($max-n >  $n)  or $nx = 0  ">
  382.                 <xsl:value-of select="$cosx"/>
  383.             </xsl:when>
  384.             <xsl:when test="$n = 0">
  385.                 <xsl:call-template name="cos-private">
  386.                     <xsl:with-param name="x" select="$x"/>
  387.                     <xsl:with-param name="n" select="$n + 1"/>
  388.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  389.                     <xsl:with-param name="max-n" select="$max-n"/>
  390.                     <xsl:with-param name="nx" select=" 1 "/>
  391.                     <xsl:with-param name="cosx" select="1"/>
  392.                 </xsl:call-template>
  393.             </xsl:when>
  394.             <xsl:otherwise>
  395.                 <xsl:variable name="new-nx" select="($nx * $x * $x)  div ( 2  *  $n  -1 )  div ( 2  *  $n )  "/>
  396.                 <xsl:call-template name="cos-private">
  397.                     <xsl:with-param name="x" select="$x"/>
  398.                     <xsl:with-param name="n" select="$n + 1"/>
  399.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  400.                     <xsl:with-param name="max-n" select="$max-n"/>
  401.                     <xsl:with-param name="nx" select=" $new-nx "/>
  402.                     <xsl:with-param name="cosx" select="$cosx + $new-nx  * $sign"/>
  403.                 </xsl:call-template>
  404.             </xsl:otherwise>
  405.         </xsl:choose>
  406.     </xsl:template>
  407.     <xsl:template name="atan-private">
  408.         <xsl:param name="x" select="0"/>
  409.         <xsl:param name="n" select="0"/>
  410.         <xsl:param name="nx" select="1"/>
  411.         <xsl:param name="sign" select="1"/>
  412.         <xsl:param name="max-n" select="40"/>
  413.         <xsl:param name="arctanx" select="0"/>
  414.         <xsl:choose>
  415.             <xsl:when test="not ($max-n >  $n) or $nx = 0 ">
  416.                 <xsl:value-of select="$arctanx"/>
  417.             </xsl:when>
  418.             <xsl:when test="$n = 0">
  419.                 <xsl:call-template name="atan-private">
  420.                     <xsl:with-param name="x" select="$x"/>
  421.                     <xsl:with-param name="n" select="$n + 1"/>
  422.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  423.                     <xsl:with-param name="max-n" select="$max-n"/>
  424.                     <xsl:with-param name="nx" select="$x "/>
  425.                     <xsl:with-param name="arctanx" select="$arctanx + $x"/>
  426.                 </xsl:call-template>
  427.             </xsl:when>
  428.             <xsl:otherwise>
  429.                 <xsl:variable name="new-nx" select=" $nx * $x * $x "/>
  430.                 <xsl:call-template name="atan-private">
  431.                     <xsl:with-param name="x" select="$x"/>
  432.                     <xsl:with-param name="n" select="$n + 1"/>
  433.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  434.                     <xsl:with-param name="max-n" select="$max-n"/>
  435.                     <xsl:with-param name="nx" select=" $new-nx "/>
  436.                     <xsl:with-param name="arctanx" select="$arctanx + $new-nx div (2 * $n +1)  * $sign"/>
  437.                 </xsl:call-template>
  438.             </xsl:otherwise>
  439.         </xsl:choose>
  440.     </xsl:template>
  441.     <xsl:template name="sqrt-private">
  442.         <xsl:param name="x"/>
  443.         <xsl:param name="rounding-factor" select="100"/>
  444.         <xsl:variable name="shift" select="string-length( $rounding-factor)"/>
  445.         <xsl:variable name="power">
  446.             <xsl:call-template name="power">
  447.                 <xsl:with-param name="x" select="100"/>
  448.                 <xsl:with-param name="y" select="$shift"/>
  449.                 <xsl:with-param name="rounding-factor" select="1"/>
  450.             </xsl:call-template>
  451.         </xsl:variable>
  452.         <xsl:variable name="integer-x" select=" round( $power * $x )"/>
  453.         <xsl:variable name="integer-quotient">
  454.             <xsl:call-template name="integer-sqrt">
  455.                 <xsl:with-param name="x" select="$integer-x"/>
  456.                 <xsl:with-param name="length" select=" string-length( $integer-x ) "/>
  457.                 <xsl:with-param name="curr-pos" select=" 2 -  (round (string-length( $integer-x ) div 2 )  * 2 - string-length( $integer-x ) ) "/>
  458.             </xsl:call-template>
  459.         </xsl:variable>
  460.         <xsl:variable name="power-10">
  461.             <xsl:call-template name="power">
  462.                 <xsl:with-param name="x" select="10"/>
  463.                 <xsl:with-param name="y" select="$shift - 1"/>
  464.                 <xsl:with-param name="rounding-factor" select="1"/>
  465.             </xsl:call-template>
  466.         </xsl:variable>
  467.         <xsl:value-of select="  round( $integer-quotient div 10) div $power-10 "/>
  468.     </xsl:template>
  469.     <xsl:template name="integer-sqrt">
  470.         <xsl:param name="x"/>
  471.         <xsl:param name="length"/>
  472.         <xsl:param name="curr-pos"/>
  473.         <xsl:param name="last-quotient" select="0"/>
  474.         <xsl:choose>
  475.             <xsl:when test="$curr-pos > $length">
  476.                 <xsl:value-of select="$last-quotient"/>
  477.             </xsl:when>
  478.             <xsl:otherwise>
  479.                 <xsl:variable name="curr-x" select="substring( $x, 1,  $curr-pos )"/>
  480.                 <xsl:variable name="new-quotient">
  481.                     <xsl:call-template name="get-one-sqrt-digit">
  482.                         <xsl:with-param name="x" select="$curr-x"/>
  483.                         <xsl:with-param name="last-quotient" select="$last-quotient"/>
  484.                         <xsl:with-param name="n" select="5"/>
  485.                         <xsl:with-param name="direct" select="0"/>
  486.                     </xsl:call-template>
  487.                 </xsl:variable>
  488.                 <xsl:call-template name="integer-sqrt">
  489.                     <xsl:with-param name="x" select="$x"/>
  490.                     <xsl:with-param name="length" select="$length"/>
  491.                     <xsl:with-param name="curr-pos" select="$curr-pos + 2"/>
  492.                     <xsl:with-param name="last-quotient" select="number($new-quotient)"/>
  493.                 </xsl:call-template>
  494.             </xsl:otherwise>
  495.         </xsl:choose>
  496.     </xsl:template>
  497.     <xsl:template name="get-one-sqrt-digit">
  498.         <xsl:param name="x"/>
  499.         <xsl:param name="last-quotient"/>
  500.         <xsl:param name="n"/>
  501.         <xsl:param name="direct" select="1"/>
  502.         <xsl:variable name="quotient" select=" concat( $last-quotient, $n) "/>
  503.         <xsl:variable name="accumulate" select="$quotient * $quotient "/>
  504.         <xsl:choose>
  505.             <xsl:when test="$accumulate  =  $x">
  506.                 <xsl:value-of select="concat($last-quotient , $n  )"/>
  507.             </xsl:when>
  508.             <xsl:when test="$direct = 0 and $accumulate  <  $x">
  509.                 <xsl:call-template name="get-one-sqrt-digit">
  510.                     <xsl:with-param name="x" select="$x"/>
  511.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  512.                     <xsl:with-param name="n" select="$n + 1"/>
  513.                     <xsl:with-param name="direct" select="1"/>
  514.                 </xsl:call-template>
  515.             </xsl:when>
  516.             <xsl:when test="$direct = 0 and $accumulate  >  $x">
  517.                 <xsl:call-template name="get-one-sqrt-digit">
  518.                     <xsl:with-param name="x" select="$x"/>
  519.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  520.                     <xsl:with-param name="n" select="$n - 1"/>
  521.                     <xsl:with-param name="direct" select="-1"/>
  522.                 </xsl:call-template>
  523.             </xsl:when>
  524.             <xsl:when test=" $accumulate * $direct  <  $x * $direct  ">
  525.                 <xsl:call-template name="get-one-sqrt-digit">
  526.                     <xsl:with-param name="x" select="$x"/>
  527.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  528.                     <xsl:with-param name="n" select="$n+ $direct"/>
  529.                     <xsl:with-param name="direct" select="$direct"/>
  530.                 </xsl:call-template>
  531.             </xsl:when>
  532.             <xsl:when test="not($n < 9)  or $n = -1">
  533.                 <xsl:value-of select="concat($last-quotient , $n - $direct) "/>
  534.             </xsl:when>
  535.             <xsl:when test="$direct = 1">
  536.                 <xsl:value-of select="concat($last-quotient , $n - 1) "/>
  537.             </xsl:when>
  538.             <xsl:otherwise>
  539.                 <xsl:value-of select="concat($last-quotient , $n) "/>
  540.             </xsl:otherwise>
  541.         </xsl:choose>
  542.     </xsl:template>
  543.     <xsl:template name="convert2redian">
  544.         <xsl:param name="x" select="'0'"/>
  545.         <xsl:param name="rounding-factor" select="100"/>
  546.         <xsl:choose>
  547.             <xsl:when test="contains($x,'deg')">
  548.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') div 180 * $pi)) div $rounding-factor"/>
  549.             </xsl:when>
  550.             <xsl:when test="contains($x,'fd')">
  551.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd') div 180 div 65536 * $pi)) div $rounding-factor"/>
  552.             </xsl:when>
  553.             <xsl:otherwise>
  554.                 <xsl:value-of select="round($rounding-factor * number($x) div 180 * $pi) div $rounding-factor"/>
  555.             </xsl:otherwise>
  556.         </xsl:choose>
  557.     </xsl:template>
  558.     <xsl:template name="convert2degree">
  559.         <xsl:param name="x" select="'0'"/>
  560.         <xsl:param name="rounding-factor" select="100"/>
  561.         <xsl:choose>
  562.             <xsl:when test="contains($x,'deg')">
  563.                 <xsl:value-of select="round($rounding-factor * substring-before($x,'deg')) div $rounding-factor"/>
  564.             </xsl:when>
  565.             <xsl:when test="contains($x,'fd')">
  566.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd')) div 65536 ) div $rounding-factor"/>
  567.             </xsl:when>
  568.             <xsl:otherwise>
  569.                 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi) div $rounding-factor"/>
  570.             </xsl:otherwise>
  571.         </xsl:choose>
  572.     </xsl:template>
  573.     <xsl:template name="convert2fd">
  574.         <xsl:param name="x" select="'0'"/>
  575.         <xsl:param name="rounding-factor" select="100"/>
  576.         <xsl:choose>
  577.             <xsl:when test="contains($x,'deg')">
  578.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') * 65535)) div $rounding-factor"/>
  579.             </xsl:when>
  580.             <xsl:when test="contains($x,'fd')">
  581.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd'))) div $rounding-factor"/>
  582.             </xsl:when>
  583.             <xsl:otherwise>
  584.                 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi * 65535) div $rounding-factor"/>
  585.             </xsl:otherwise>
  586.         </xsl:choose>
  587.     </xsl:template>
  588.  
  589. </xsl:stylesheet>
  590.