home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / openoffice / share / xslt / common / math.xsl next >
Encoding:
Extensible Markup Language  |  2006-08-01  |  26.7 KB  |  598 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.     OpenOffice.org - a multi-platform office productivity suite
  5.  
  6.     $RCSfile: math.xsl,v $
  7.  
  8.     $Revision: 1.7 $
  9.  
  10.     last change: $Author: obo $ $Date: 2005/10/13 09:38:58 $
  11.  
  12.     The Contents of this file are made available subject to
  13.     the terms of GNU Lesser General Public License Version 2.1.
  14.  
  15.  
  16.       GNU Lesser General Public License Version 2.1
  17.       =============================================
  18.       Copyright 2005 by Sun Microsystems, Inc.
  19.       901 San Antonio Road, Palo Alto, CA 94303, USA
  20.  
  21.       This library is free software; you can redistribute it and/or
  22.       modify it under the terms of the GNU Lesser General Public
  23.       License version 2.1, as published by the Free Software Foundation.
  24.  
  25.       This library is distributed in the hope that it will be useful,
  26.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.       Lesser General Public License for more details.
  29.  
  30.       You should have received a copy of the GNU Lesser General Public
  31.       License along with this library; if not, write to the Free Software
  32.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33.       MA  02111-1307  USA
  34.  
  35.  -->
  36. <!--
  37.      xslt math lib by Wind Li
  38. Public Functions
  39.     sin(x,rounding-factor=100)
  40.     cos(x,rounding-factor=100)
  41.     tan(x,rounding-factor=100)
  42.     ctan(x,rounding-factor=100)
  43.     atan2(x, y ,rounding-factor=100)
  44.     atan(x,rounding-factor=100)
  45.     acos(x,rounding-factor=100)
  46.     asin(x,rounding-factor=100)
  47.     abs(x)
  48.     max(x1,x2)
  49.     min(x1,x2)
  50.     power(x,power(interger only), rounding-factor=100)
  51.     sqrt(x, rounding-factor=100)
  52.     convert2radian(x,rounding-factor=100)
  53.     convert2degree(x,rounding-factor=100)
  54.     convert2fd(x,rounding-factor=100)
  55.  -->
  56. <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">
  57.     <xsl:variable name="pi" select="3.1416"/>
  58.     <xsl:template name="math-test">
  59.         sin(34.8)
  60.         <xsl:call-template name="sin">
  61.             <xsl:with-param name="x" select="34.8"/>
  62.             <xsl:with-param name="rounding-factor" select="100000"/>
  63.         </xsl:call-template>
  64.         cos(34.8)
  65.         <xsl:call-template name="cos">
  66.             <xsl:with-param name="x" select="34.8"/>
  67.             <xsl:with-param name="rounding-factor" select="100000"/>
  68.         </xsl:call-template>
  69.         atan(2.74)
  70.         <xsl:call-template name="atan">
  71.             <xsl:with-param name="x" select="2.74"/>
  72.             <xsl:with-param name="rounding-factor" select="100000"/>
  73.         </xsl:call-template>
  74.         acos(0.5)
  75.         <xsl:call-template name="acos">
  76.             <xsl:with-param name="x" select="0.5"/>
  77.             <xsl:with-param name="rounding-factor" select="100000"/>
  78.         </xsl:call-template>
  79.         asin(0.5)
  80.         <xsl:call-template name="asin">
  81.             <xsl:with-param name="x" select="0.5"/>
  82.             <xsl:with-param name="rounding-factor" select="100000"/>
  83.         </xsl:call-template>
  84.         sqrt(1328.3414)
  85.         <xsl:call-template name="sqrt">
  86.             <xsl:with-param name="x" select="1328.3414"/>
  87.             <xsl:with-param name="rounding-factor" select="100000"/>
  88.         </xsl:call-template>
  89.     </xsl:template>
  90.     <!-- public functions start -->
  91.     <xsl:template name="sin">
  92.         <xsl:param name="x" select="0"/>
  93.         <xsl:param name="rounding-factor" select="100"/>
  94.         <xsl:variable name="angle" select="$x * 180 div $pi "/>
  95.         <xsl:variable name="mod-angle" select="$angle mod 360"/>
  96.         <xsl:variable name="sinx">
  97.             <xsl:call-template name="sin-private">
  98.                 <xsl:with-param name="x" select="  ( $angle mod 360 )  * $pi div 180 "/>
  99.             </xsl:call-template>
  100.         </xsl:variable>
  101.         <xsl:value-of select=" round ( number($sinx) * $rounding-factor ) div $rounding-factor"/>
  102.     </xsl:template>
  103.     <xsl:template name="cos">
  104.         <xsl:param name="x" select="0"/>
  105.         <xsl:param name="rounding-factor" select="100"/>
  106.         <xsl:variable name="angle" select="$x * 180 div $pi "/>
  107.         <xsl:variable name="mod-angle" select="$angle mod 360"/>
  108.         <xsl:variable name="cosx">
  109.             <xsl:call-template name="cos-private">
  110.                 <xsl:with-param name="x" select="  ( $angle mod 360 )  * $pi div 180 "/>
  111.             </xsl:call-template>
  112.         </xsl:variable>
  113.         <xsl:value-of select=" round ( number($cosx) * $rounding-factor ) div $rounding-factor"/>
  114.     </xsl:template>
  115.     <xsl:template name="tan">
  116.         <xsl:param name="x" select="0"/>
  117.         <xsl:param name="rounding-factor" select="100"/>
  118.         <xsl:variable name="sinx">
  119.             <xsl:call-template name="sin">
  120.                 <xsl:with-param name="x" select="$x"/>
  121.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  122.             </xsl:call-template>
  123.         </xsl:variable>
  124.         <xsl:variable name="cosx">
  125.             <xsl:call-template name="cos">
  126.                 <xsl:with-param name="x" select="$x"/>
  127.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  128.             </xsl:call-template>
  129.         </xsl:variable>
  130.         <xsl:choose>
  131.             <xsl:when test=" $cosx = 0 ">
  132.                 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
  133.                 <xsl:value-of select="63535"/>
  134.             </xsl:when>
  135.             <xsl:otherwise>
  136.                 <xsl:value-of select=" round( $sinx div $cosx * $rounding-factor) div $rounding-factor"/>
  137.             </xsl:otherwise>
  138.         </xsl:choose>
  139.     </xsl:template>
  140.     <xsl:template name="ctan">
  141.         <xsl:param name="x" select="0"/>
  142.         <xsl:param name="rounding-factor" select="100"/>
  143.         <xsl:variable name="sinx">
  144.             <xsl:call-template name="sin">
  145.                 <xsl:with-param name="x" select="$x"/>
  146.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  147.             </xsl:call-template>
  148.         </xsl:variable>
  149.         <xsl:variable name="cosx">
  150.             <xsl:call-template name="cos">
  151.                 <xsl:with-param name="x" select="$x"/>
  152.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  153.             </xsl:call-template>
  154.         </xsl:variable>
  155.         <xsl:choose>
  156.             <xsl:when test=" $sinx = 0 ">
  157.                 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
  158.                 <xsl:value-of select="63535"/>
  159.             </xsl:when>
  160.             <xsl:otherwise>
  161.                 <xsl:value-of select=" round( $cosx div $sinx * $rounding-factor) div $rounding-factor"/>
  162.             </xsl:otherwise>
  163.         </xsl:choose>
  164.     </xsl:template>
  165.     <xsl:template name="atan">
  166.         <xsl:param name="x" select="0"/>
  167.         <xsl:param name="rounding-factor" select="100"/>
  168.         <xsl:choose>
  169.             <xsl:when test="$x = 0">
  170.                 <xsl:value-of select="0"/>
  171.             </xsl:when>
  172.             <xsl:when test="$x < 0">
  173.                 <xsl:variable name="atan-x">
  174.                     <xsl:call-template name="atan">
  175.                         <xsl:with-param name="x" select=" -1 * $x"/>
  176.                         <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  177.                     </xsl:call-template>
  178.                 </xsl:variable>
  179.                 <xsl:value-of select="-1 * $atan-x"/>
  180.             </xsl:when>
  181.             <xsl:when test="$x > 1">
  182.                 <xsl:variable name="atan-div-x">
  183.                     <xsl:call-template name="atan">
  184.                         <xsl:with-param name="x" select="1 div $x "/>
  185.                         <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  186.                     </xsl:call-template>
  187.                 </xsl:variable>
  188.                 <xsl:value-of select=" $pi div 2 - $atan-div-x"/>
  189.             </xsl:when>
  190.             <xsl:otherwise>
  191.                 <xsl:variable name="arctanx">
  192.                     <xsl:call-template name="atan-private">
  193.                         <xsl:with-param name="x" select="  $x "/>
  194.                     </xsl:call-template>
  195.                 </xsl:variable>
  196.                 <xsl:value-of select=" round ( number($arctanx) * $rounding-factor ) div $rounding-factor"/>
  197.             </xsl:otherwise>
  198.         </xsl:choose>
  199.     </xsl:template>
  200.     <xsl:template name="atan2">
  201.         <xsl:param name="x"/>
  202.         <xsl:param name="y"/>
  203.         <xsl:param name="rounding-factor" select="100"/>
  204.         <xsl:choose>
  205.             <xsl:when test="$x = 0">
  206.                 <xsl:value-of select=" $pi div 2"/>
  207.             </xsl:when>
  208.             <xsl:otherwise>
  209.                 <xsl:call-template name="atan">
  210.                     <xsl:with-param name="x" select="$y div $x"/>
  211.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  212.                 </xsl:call-template>
  213.             </xsl:otherwise>
  214.         </xsl:choose>
  215.     </xsl:template>
  216.     <xsl:template name="acos">
  217.         <xsl:param name="x"/>
  218.         <xsl:param name="rounding-factor" select="100"/>
  219.         <xsl:variable name="abs-x">
  220.             <xsl:call-template name="abs">
  221.                 <xsl:with-param name="x" select="$x"/>
  222.             </xsl:call-template>
  223.         </xsl:variable>
  224.         <xsl:choose>
  225.             <xsl:when test="$abs-x  >  1">
  226.                 <xsl:message>acos error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
  227.             </xsl:when>
  228.             <xsl:otherwise>
  229.                 <xsl:call-template name="atan2">
  230.                     <xsl:with-param name="x" select="$x"/>
  231.                     <xsl:with-param name="y">
  232.                         <xsl:call-template name="sqrt">
  233.                             <xsl:with-param name="x" select="1 - $x * $x"/>
  234.                             <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
  235.                         </xsl:call-template>
  236.                     </xsl:with-param>
  237.                 </xsl:call-template>
  238.             </xsl:otherwise>
  239.         </xsl:choose>
  240.     </xsl:template>
  241.     <xsl:template name="asin">
  242.         <xsl:param name="x"/>
  243.         <xsl:param name="rounding-factor" select="100"/>
  244.         <xsl:variable name="abs-x">
  245.             <xsl:call-template name="abs">
  246.                 <xsl:with-param name="x" select="$x"/>
  247.             </xsl:call-template>
  248.         </xsl:variable>
  249.         <xsl:choose>
  250.             <xsl:when test="$abs-x  >  1">
  251.                 <xsl:message>asin error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
  252.             </xsl:when>
  253.             <xsl:otherwise>
  254.                 <xsl:call-template name="atan2">
  255.                     <xsl:with-param name="y" select="$x"/>
  256.                     <xsl:with-param name="x">
  257.                         <xsl:call-template name="sqrt">
  258.                             <xsl:with-param name="x" select="1 - $x * $x"/>
  259.                             <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
  260.                         </xsl:call-template>
  261.                     </xsl:with-param>
  262.                 </xsl:call-template>
  263.             </xsl:otherwise>
  264.         </xsl:choose>
  265.     </xsl:template>
  266.     <xsl:template name="abs">
  267.         <xsl:param name="x"/>
  268.         <xsl:choose>
  269.             <xsl:when test="$x > 0">
  270.                 <xsl:value-of select="$x"/>
  271.             </xsl:when>
  272.             <xsl:otherwise>
  273.                 <xsl:value-of select="$x * -1"/>
  274.             </xsl:otherwise>
  275.         </xsl:choose>
  276.     </xsl:template>
  277.     <xsl:template name="max">
  278.         <xsl:param name="x1"/>
  279.         <xsl:param name="x2"/>
  280.         <xsl:choose>
  281.             <xsl:when test="$x1 >  $x2">
  282.                 <xsl:value-of select="$x1"/>
  283.             </xsl:when>
  284.             <xsl:otherwise>
  285.                 <xsl:value-of select="$x2"/>
  286.             </xsl:otherwise>
  287.         </xsl:choose>
  288.     </xsl:template>
  289.     <xsl:template name="min">
  290.         <xsl:param name="x1"/>
  291.         <xsl:param name="x2"/>
  292.         <xsl:choose>
  293.             <xsl:when test="$x1 <  $x2">
  294.                 <xsl:value-of select="$x1"/>
  295.             </xsl:when>
  296.             <xsl:otherwise>
  297.                 <xsl:value-of select="$x2"/>
  298.             </xsl:otherwise>
  299.         </xsl:choose>
  300.     </xsl:template>
  301.     <xsl:template name="power">
  302.         <xsl:param name="x"/>
  303.         <xsl:param name="y" select="1"/>
  304.         <xsl:param name="rounding-factor" select="100"/>
  305.         <!--  z is a private param -->
  306.         <xsl:param name="z" select="1"/>
  307.         <xsl:choose>
  308.             <xsl:when test="$y > 0">
  309.                 <xsl:call-template name="power">
  310.                     <xsl:with-param name="x" select="$x"/>
  311.                     <xsl:with-param name="y" select="$y - 1"/>
  312.                     <xsl:with-param name="z" select="$z * $x"/>
  313.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  314.                 </xsl:call-template>
  315.             </xsl:when>
  316.             <xsl:otherwise>
  317.                 <xsl:value-of select=" round( $z * $rounding-factor) div $rounding-factor"/>
  318.             </xsl:otherwise>
  319.         </xsl:choose>
  320.     </xsl:template>
  321.     <xsl:template name="sqrt">
  322.         <xsl:param name="x"/>
  323.         <xsl:param name="rounding-factor" select="100"/>
  324.         <xsl:choose>
  325.             <xsl:when test="$x = 0">0</xsl:when>
  326.             <xsl:when test="$x < 0">
  327.                 <xsl:message>sqrt error : <xsl:value-of select="$x"/>  less then 0!</xsl:message>
  328.             </xsl:when>
  329.             <xsl:otherwise>
  330.                 <xsl:call-template name="sqrt-private">
  331.                     <xsl:with-param name="x" select="$x"/>
  332.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  333.                 </xsl:call-template>
  334.             </xsl:otherwise>
  335.         </xsl:choose>
  336.     </xsl:template>
  337.     <!-- public functions end -->
  338.     <!--
  339. Private functions:
  340. sin-private
  341. cos-private
  342. atan-private
  343. sqrt-private
  344. integer-sqrt
  345. Sqrt-GetOneDigit
  346. -->
  347.     <xsl:template name="sin-private">
  348.         <xsl:param name="x" select="0"/>
  349.         <xsl:param name="n" select="0"/>
  350.         <xsl:param name="nx" select="1"/>
  351.         <xsl:param name="sign" select="1"/>
  352.         <xsl:param name="max-n" select="20"/>
  353.         <xsl:param name="sinx" select="0"/>
  354.         <xsl:choose>
  355.             <xsl:when test="not ($max-n >  $n) or $nx = 0 ">
  356.                 <xsl:value-of select="$sinx"/>
  357.             </xsl:when>
  358.             <xsl:when test="$n = 0">
  359.                 <xsl:call-template name="sin-private">
  360.                     <xsl:with-param name="x" select="$x"/>
  361.                     <xsl:with-param name="n" select="$n + 1"/>
  362.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  363.                     <xsl:with-param name="max-n" select="$max-n"/>
  364.                     <xsl:with-param name="nx" select="$x "/>
  365.                     <xsl:with-param name="sinx" select="$sinx + $x"/>
  366.                 </xsl:call-template>
  367.             </xsl:when>
  368.             <xsl:otherwise>
  369.                 <xsl:variable name="new-nx" select="($nx * $x * $x)  div ( 2  *  $n )  div ( 2  *  $n  + 1)  "/>
  370.                 <xsl:call-template name="sin-private">
  371.                     <xsl:with-param name="x" select="$x"/>
  372.                     <xsl:with-param name="n" select="$n + 1"/>
  373.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  374.                     <xsl:with-param name="max-n" select="$max-n"/>
  375.                     <xsl:with-param name="nx" select=" $new-nx "/>
  376.                     <xsl:with-param name="sinx" select="$sinx + $new-nx  * $sign"/>
  377.                 </xsl:call-template>
  378.             </xsl:otherwise>
  379.         </xsl:choose>
  380.     </xsl:template>
  381.     <xsl:template name="cos-private">
  382.         <xsl:param name="x" select="0"/>
  383.         <xsl:param name="n" select="0"/>
  384.         <xsl:param name="nx" select="1"/>
  385.         <xsl:param name="sign" select="1"/>
  386.         <xsl:param name="max-n" select="20"/>
  387.         <xsl:param name="cosx" select="0"/>
  388.         <xsl:choose>
  389.             <xsl:when test="not ($max-n >  $n)  or $nx = 0  ">
  390.                 <xsl:value-of select="$cosx"/>
  391.             </xsl:when>
  392.             <xsl:when test="$n = 0">
  393.                 <xsl:call-template name="cos-private">
  394.                     <xsl:with-param name="x" select="$x"/>
  395.                     <xsl:with-param name="n" select="$n + 1"/>
  396.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  397.                     <xsl:with-param name="max-n" select="$max-n"/>
  398.                     <xsl:with-param name="nx" select=" 1 "/>
  399.                     <xsl:with-param name="cosx" select="1"/>
  400.                 </xsl:call-template>
  401.             </xsl:when>
  402.             <xsl:otherwise>
  403.                 <xsl:variable name="new-nx" select="($nx * $x * $x)  div ( 2  *  $n  -1 )  div ( 2  *  $n )  "/>
  404.                 <xsl:call-template name="cos-private">
  405.                     <xsl:with-param name="x" select="$x"/>
  406.                     <xsl:with-param name="n" select="$n + 1"/>
  407.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  408.                     <xsl:with-param name="max-n" select="$max-n"/>
  409.                     <xsl:with-param name="nx" select=" $new-nx "/>
  410.                     <xsl:with-param name="cosx" select="$cosx + $new-nx  * $sign"/>
  411.                 </xsl:call-template>
  412.             </xsl:otherwise>
  413.         </xsl:choose>
  414.     </xsl:template>
  415.     <xsl:template name="atan-private">
  416.         <xsl:param name="x" select="0"/>
  417.         <xsl:param name="n" select="0"/>
  418.         <xsl:param name="nx" select="1"/>
  419.         <xsl:param name="sign" select="1"/>
  420.         <xsl:param name="max-n" select="40"/>
  421.         <xsl:param name="arctanx" select="0"/>
  422.         <xsl:choose>
  423.             <xsl:when test="not ($max-n >  $n) or $nx = 0 ">
  424.                 <xsl:value-of select="$arctanx"/>
  425.             </xsl:when>
  426.             <xsl:when test="$n = 0">
  427.                 <xsl:call-template name="atan-private">
  428.                     <xsl:with-param name="x" select="$x"/>
  429.                     <xsl:with-param name="n" select="$n + 1"/>
  430.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  431.                     <xsl:with-param name="max-n" select="$max-n"/>
  432.                     <xsl:with-param name="nx" select="$x "/>
  433.                     <xsl:with-param name="arctanx" select="$arctanx + $x"/>
  434.                 </xsl:call-template>
  435.             </xsl:when>
  436.             <xsl:otherwise>
  437.                 <xsl:variable name="new-nx" select=" $nx * $x * $x "/>
  438.                 <xsl:call-template name="atan-private">
  439.                     <xsl:with-param name="x" select="$x"/>
  440.                     <xsl:with-param name="n" select="$n + 1"/>
  441.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  442.                     <xsl:with-param name="max-n" select="$max-n"/>
  443.                     <xsl:with-param name="nx" select=" $new-nx "/>
  444.                     <xsl:with-param name="arctanx" select="$arctanx + $new-nx div (2 * $n +1)  * $sign"/>
  445.                 </xsl:call-template>
  446.             </xsl:otherwise>
  447.         </xsl:choose>
  448.     </xsl:template>
  449.     <xsl:template name="sqrt-private">
  450.         <xsl:param name="x"/>
  451.         <xsl:param name="rounding-factor" select="100"/>
  452.         <xsl:variable name="shift" select="string-length( $rounding-factor)"/>
  453.         <xsl:variable name="power">
  454.             <xsl:call-template name="power">
  455.                 <xsl:with-param name="x" select="100"/>
  456.                 <xsl:with-param name="y" select="$shift"/>
  457.                 <xsl:with-param name="rounding-factor" select="1"/>
  458.             </xsl:call-template>
  459.         </xsl:variable>
  460.         <xsl:variable name="integer-x" select=" round( $power * $x )"/>
  461.         <xsl:variable name="integer-quotient">
  462.             <xsl:call-template name="integer-sqrt">
  463.                 <xsl:with-param name="x" select="$integer-x"/>
  464.                 <xsl:with-param name="length" select=" string-length( $integer-x ) "/>
  465.                 <xsl:with-param name="curr-pos" select=" 2 -  (round (string-length( $integer-x ) div 2 )  * 2 - string-length( $integer-x ) ) "/>
  466.             </xsl:call-template>
  467.         </xsl:variable>
  468.         <xsl:variable name="power-10">
  469.             <xsl:call-template name="power">
  470.                 <xsl:with-param name="x" select="10"/>
  471.                 <xsl:with-param name="y" select="$shift - 1"/>
  472.                 <xsl:with-param name="rounding-factor" select="1"/>
  473.             </xsl:call-template>
  474.         </xsl:variable>
  475.         <xsl:value-of select="  round( $integer-quotient div 10) div $power-10 "/>
  476.     </xsl:template>
  477.     <xsl:template name="integer-sqrt">
  478.         <xsl:param name="x"/>
  479.         <xsl:param name="length"/>
  480.         <xsl:param name="curr-pos"/>
  481.         <xsl:param name="last-quotient" select="0"/>
  482.         <xsl:choose>
  483.             <xsl:when test="$curr-pos > $length">
  484.                 <xsl:value-of select="$last-quotient"/>
  485.             </xsl:when>
  486.             <xsl:otherwise>
  487.                 <xsl:variable name="curr-x" select="substring( $x, 1,  $curr-pos )"/>
  488.                 <xsl:variable name="new-quotient">
  489.                     <xsl:call-template name="get-one-sqrt-digit">
  490.                         <xsl:with-param name="x" select="$curr-x"/>
  491.                         <xsl:with-param name="last-quotient" select="$last-quotient"/>
  492.                         <xsl:with-param name="n" select="5"/>
  493.                         <xsl:with-param name="direct" select="0"/>
  494.                     </xsl:call-template>
  495.                 </xsl:variable>
  496.                 <xsl:call-template name="integer-sqrt">
  497.                     <xsl:with-param name="x" select="$x"/>
  498.                     <xsl:with-param name="length" select="$length"/>
  499.                     <xsl:with-param name="curr-pos" select="$curr-pos + 2"/>
  500.                     <xsl:with-param name="last-quotient" select="number($new-quotient)"/>
  501.                 </xsl:call-template>
  502.             </xsl:otherwise>
  503.         </xsl:choose>
  504.     </xsl:template>
  505.     <xsl:template name="get-one-sqrt-digit">
  506.         <xsl:param name="x"/>
  507.         <xsl:param name="last-quotient"/>
  508.         <xsl:param name="n"/>
  509.         <xsl:param name="direct" select="1"/>
  510.         <xsl:variable name="quotient" select=" concat( $last-quotient, $n) "/>
  511.         <xsl:variable name="accumulate" select="$quotient * $quotient "/>
  512.         <xsl:choose>
  513.             <xsl:when test="$accumulate  =  $x">
  514.                 <xsl:value-of select="concat($last-quotient , $n  )"/>
  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="$direct = 0 and $accumulate  >  $x">
  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 - 1"/>
  529.                     <xsl:with-param name="direct" select="-1"/>
  530.                 </xsl:call-template>
  531.             </xsl:when>
  532.             <xsl:when test=" $accumulate * $direct  <  $x * $direct  ">
  533.                 <xsl:call-template name="get-one-sqrt-digit">
  534.                     <xsl:with-param name="x" select="$x"/>
  535.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  536.                     <xsl:with-param name="n" select="$n+ $direct"/>
  537.                     <xsl:with-param name="direct" select="$direct"/>
  538.                 </xsl:call-template>
  539.             </xsl:when>
  540.             <xsl:when test="not($n < 9)  or $n = -1">
  541.                 <xsl:value-of select="concat($last-quotient , $n - $direct) "/>
  542.             </xsl:when>
  543.             <xsl:when test="$direct = 1">
  544.                 <xsl:value-of select="concat($last-quotient , $n - 1) "/>
  545.             </xsl:when>
  546.             <xsl:otherwise>
  547.                 <xsl:value-of select="concat($last-quotient , $n) "/>
  548.             </xsl:otherwise>
  549.         </xsl:choose>
  550.     </xsl:template>
  551.     <xsl:template name="convert2redian">
  552.         <xsl:param name="x" select="'0'"/>
  553.         <xsl:param name="rounding-factor" select="100"/>
  554.         <xsl:choose>
  555.             <xsl:when test="contains($x,'deg')">
  556.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') div 180 * $pi)) div $rounding-factor"/>
  557.             </xsl:when>
  558.             <xsl:when test="contains($x,'fd')">
  559.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd') div 180 div 65536 * $pi)) div $rounding-factor"/>
  560.             </xsl:when>
  561.             <xsl:otherwise>
  562.                 <xsl:value-of select="round($rounding-factor * number($x) div 180 * $pi) div $rounding-factor"/>
  563.             </xsl:otherwise>
  564.         </xsl:choose>
  565.     </xsl:template>
  566.     <xsl:template name="convert2degree">
  567.         <xsl:param name="x" select="'0'"/>
  568.         <xsl:param name="rounding-factor" select="100"/>
  569.         <xsl:choose>
  570.             <xsl:when test="contains($x,'deg')">
  571.                 <xsl:value-of select="round($rounding-factor * substring-before($x,'deg')) div $rounding-factor"/>
  572.             </xsl:when>
  573.             <xsl:when test="contains($x,'fd')">
  574.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd')) div 65536 ) div $rounding-factor"/>
  575.             </xsl:when>
  576.             <xsl:otherwise>
  577.                 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi) div $rounding-factor"/>
  578.             </xsl:otherwise>
  579.         </xsl:choose>
  580.     </xsl:template>
  581.     <xsl:template name="convert2fd">
  582.         <xsl:param name="x" select="'0'"/>
  583.         <xsl:param name="rounding-factor" select="100"/>
  584.         <xsl:choose>
  585.             <xsl:when test="contains($x,'deg')">
  586.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') * 65535)) div $rounding-factor"/>
  587.             </xsl:when>
  588.             <xsl:when test="contains($x,'fd')">
  589.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd'))) div $rounding-factor"/>
  590.             </xsl:when>
  591.             <xsl:otherwise>
  592.                 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi * 65535) div $rounding-factor"/>
  593.             </xsl:otherwise>
  594.         </xsl:choose>
  595.     </xsl:template>
  596.  
  597. </xsl:stylesheet>
  598.