<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"  version = "1.1" >
<xsl:preserve-space elements="*"/>
<xsl:output method="xml" indent="no"/> 
<xsl:variable name="vars">
<vars>
<var n="1">0</var><var n="2">0</var><var n="3">0</var><var n="4">0</var><var n="5">0</var><var n="6">0</var><var n="7">0</var><var n="8">0</var><var n="9">0</var>
</vars>
</xsl:variable>
<xsl:template match="*" >
 <xsl:copy>
  <xsl:apply-templates select="@*|*|text()" />
 </xsl:copy><xsl:value-of select="$newline"/>
</xsl:template>

<xsl:template match="@*|text()" >
 <xsl:copy>
  <xsl:apply-templates select="@*|*|text()" />
 </xsl:copy>
</xsl:template>

<xsl:template match="camp">
<camp>
 <xsl:call-template name="removevars">
  <xsl:with-param name="cmnds" select="cmnd"/>
  <xsl:with-param name="vars" select="$vars"/>
 </xsl:call-template>
</camp>
</xsl:template>


<xsl:template name="removevars">
<xsl:param name="cmnds"/>
<xsl:param name="vars"/>
<xsl:choose>
 <xsl:when test="count($cmnds) = 0"></xsl:when>
 <xsl:otherwise>
 <xsl:choose>
 
 
  <xsl:when test="$cmnds[1]/@VAR">    
  <xsl:variable name="newvars">
  <vars>
   <xsl:variable name="chgvar"><xsl:value-of select="$cmnds[1]/@VAR"/></xsl:variable>
   <xsl:copy-of select="$vars/vars/var[@n != $chgvar]"/>
   <xsl:variable name="curval"><xsl:value-of select="$vars/vars/var[@n = $chgvar]"/></xsl:variable>
   <xsl:variable name="v9"><xsl:value-of select="$vars/vars/var[@n = 9]"/></xsl:variable>
   
   <xsl:variable name="oprnd">
   <xsl:choose>
   <xsl:when test="$cmnds[1]/@OPRND > 900">
      <xsl:variable name="varn2"><xsl:value-of select="round($cmnds[1]/@OPRND - 900)"/></xsl:variable>
      <xsl:variable name="curval2"><xsl:value-of select="$vars/vars/var[@n = $varn2]"/></xsl:variable>
      <xsl:value-of select="$curval2"/>
   </xsl:when>
   <xsl:otherwise><xsl:value-of select="$cmnds[1]/@OPRND"/></xsl:otherwise>
   </xsl:choose>
   </xsl:variable>

   <xsl:variable name="bgin">
   <xsl:choose>
   <xsl:when test="$cmnds[1]/@BGIN > 900">
      <xsl:variable name="varn2"><xsl:value-of select="round($cmnds[1]/@BGIN - 900)"/></xsl:variable>
      <xsl:variable name="curval2"><xsl:value-of select="$vars/vars/var[@n = $varn2]"/></xsl:variable>
      <xsl:value-of select="$curval2"/>
   </xsl:when>
   <xsl:otherwise><xsl:value-of select="$cmnds[1]/@BGIN"/></xsl:otherwise>
   </xsl:choose>
   </xsl:variable>

   <xsl:variable name="end">
   <xsl:choose>
   <xsl:when test="$cmnds[1]/@END > 900">
      <xsl:variable name="varn2"><xsl:value-of select="round($cmnds[1]/@END - 900)"/></xsl:variable>
      <xsl:variable name="curval2"><xsl:value-of select="$vars/vars/var[@n = $varn2]"/></xsl:variable>
      <xsl:value-of select="$curval2"/>
   </xsl:when>
   <xsl:otherwise><xsl:value-of select="$cmnds[1]/@END"/></xsl:otherwise>
   </xsl:choose>
   </xsl:variable>

   <xsl:choose>
    <xsl:when test="$cmnds[1]/@name = 'MULTV'">
     <var n="{$chgvar}"><xsl:value-of select="$curval * $oprnd"/></var>
    </xsl:when>
    
    <xsl:when test="$cmnds[1]/@name = 'ADDV'">
    <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}"><xsl:value-of select="$curval + $oprnd"/></var>
     </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    
    
    
     <xsl:when test="$cmnds[1]/@name = 'SUBV'">
         <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}"><xsl:value-of select="$curval - $oprnd"/></var>
          </xsl:otherwise>
     </xsl:choose>

    </xsl:when>
    
    
    
     <xsl:when test="$cmnds[1]/@name = 'DIVV'">
         <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}"><xsl:value-of select="$curval div $oprnd"/></var>
          </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    
    
    
     <xsl:when test="$cmnds[1]/@name = 'SQRTV'">
         <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}">
      <xsl:call-template name="sqrt">
      <xsl:with-param name="n" select="$oprnd"/>
      </xsl:call-template>
     </var>
     </xsl:otherwise>
     </xsl:choose>

    </xsl:when>
    
    
    
     <xsl:when test="$cmnds[1]/@name = 'SINV'">
         <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}">
      <xsl:call-template name="sine">
      <xsl:with-param name="deg" select="$oprnd"/>
      </xsl:call-template>
     </var>
          </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    
    
    
     <xsl:when test="$cmnds[1]/@name = 'COSV'">
         <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}">
      <xsl:call-template name="cosine">
      <xsl:with-param name="deg" select="$oprnd"/>
      </xsl:call-template>
     </var>
     </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    
    
    
     <xsl:when test="$cmnds[1]/@name = 'EXPV'">
         <xsl:choose>
    <xsl:when test="$v9 &lt; $bgin" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
    <xsl:when test="$end != 0 and $v9 >= $end" ><var n="{$chgvar}"><xsl:value-of select="$curval"/></var></xsl:when>
     <xsl:otherwise>
     <var n="{$chgvar}">
      <xsl:call-template name="exp">
      <xsl:with-param name="n" select="$oprnd"/>
      </xsl:call-template>
     </var>
     </xsl:otherwise>
     </xsl:choose>
    </xsl:when>

   </xsl:choose>
  </vars>
  </xsl:variable>
   <xsl:call-template name="removevars">
     <xsl:with-param name="cmnds" select="$cmnds[position() != 1]"/>
     <xsl:with-param name="vars" select="$newvars"/>
   </xsl:call-template>
  </xsl:when>
  
  
  <xsl:when test="$cmnds[1]/@* > 900">               
   <cmnd>
    <xsl:for-each select="$cmnds[1]/@*">
     <xsl:choose>
      <xsl:when test=". > 900">
      <xsl:variable name="varn"><xsl:value-of select="round(. - 900)"/></xsl:variable>
      <xsl:variable name="varname"><xsl:value-of select="name()"/></xsl:variable>
      <xsl:variable name="curval"><xsl:value-of select="$vars/vars/var[@n = $varn]"/></xsl:variable>
      <xsl:attribute name="{$varname}"><xsl:value-of select="$curval"/></xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
       <xsl:copy><xsl:value-of select="."/></xsl:copy>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:for-each>
  </cmnd><xsl:text>
</xsl:text>
    
    <xsl:call-template name="removevars">
    <xsl:with-param name="cmnds" select="$cmnds[position() != 1]"/>
    <xsl:with-param name="vars" select="$vars"/>
  </xsl:call-template>
  </xsl:when>
  
  
  <xsl:otherwise>                     
  <xsl:copy-of select="$cmnds[1]"/><xsl:text>
</xsl:text>
    <xsl:call-template name="removevars">
    <xsl:with-param name="cmnds" select="$cmnds[position() != 1]"/>
    <xsl:with-param name="vars" select="$vars"/>
  </xsl:call-template>
  </xsl:otherwise>
  
  
 </xsl:choose>
 
 
  
  
 </xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- ******************************************************** -->
<!-- ********************* sqrt (n) ************************* -->
<!-- ******************************************************** -->
<xsl:template name="sqrt">
  <xsl:param name="n" />
  <xsl:call-template name="squrt" >
    <xsl:with-param name="n" select="number($n)" />
    <xsl:with-param name="guess" select="number($n) div 2" />
    <xsl:with-param name="eps" select="number(0.000000001)" />
  </xsl:call-template>
</xsl:template>

<xsl:template name="squrt">
  <xsl:param name="n" />
  <xsl:param name="guess" />
  <xsl:param name="eps" />
  <xsl:choose>
    <xsl:when test="number(($n - $guess * $guess) * ($n - $guess * $guess) ) > $eps">
    <xsl:call-template name="squrt">
      <xsl:with-param name="n" select="$n" />
      <xsl:with-param name="guess" select="number( ( ($n div $guess) + $guess) div 2)" />
      <xsl:with-param name="eps" select="$eps" />
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$guess" />
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- ******************************************************** -->
<!-- **************** cosine (deg)       ******************** -->
<!-- ******************************************************** -->
<xsl:template name="cosine">
  <xsl:param name="deg" />
  <xsl:variable name="deg360">
    <xsl:value-of select="$deg - floor($deg div 360) * 360" />
  </xsl:variable>
  <xsl:variable name="zone">
    <xsl:value-of select="floor($deg360 div 90)" />
   </xsl:variable>
  <xsl:variable name="cosinparts">
    <xsl:choose>
    <xsl:when test="$zone = 0"><sign>1</sign><val><xsl:value-of select="$deg360" /></val></xsl:when>
    <xsl:when test="$zone = 1"><sign>-1</sign><val><xsl:value-of select="180 - $deg360" /></val></xsl:when>
    <xsl:when test="$zone = 2"><sign>-1</sign><val><xsl:value-of select="$deg360 - 180" /></val></xsl:when>
    <xsl:when test="$zone = 3"><sign>1</sign><val><xsl:value-of select="360 - $deg360" /></val></xsl:when>
    <xsl:otherwise />
    </xsl:choose>
  </xsl:variable>
  <xsl:call-template name="cos90" >
    <xsl:with-param name="sign" select="$cosinparts/sign"/>
    <xsl:with-param name="val" select="$cosinparts/val"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="cos90">
  <xsl:param name="sign" />
  <xsl:param name="val" />
    <xsl:variable name="t" select="3.14159265358979323846 * $val div 180" />
    <xsl:variable name="t2" select="$t * $t" />
    <xsl:value-of select="$sign * ( 1 - $t2 div 2 * ( 1 - $t2 div 12 * ( 1- $t2 div 30 * (1 - $t2 div 56 * ( 1 - $t2 div 90 * ( 1 - $t2 div 132 * ( 1 - $t2 div 182 * (1 - $t2 div 240 ))))))))       " />
</xsl:template>

<!-- ************************************************************ -->
<!-- ************************ sine (deg) ************************ -->
<!-- ************************************************************ -->

<xsl:template name="sine">
  <xsl:param name="deg" />
  <xsl:variable name="deg360">
    <xsl:value-of select="$deg - floor($deg div 360) * 360" />
  </xsl:variable>
  <xsl:variable name="zone">
    <xsl:value-of select="floor($deg360 div 90)" />
  </xsl:variable>
  <xsl:variable name="sinparts">
    <xsl:choose>
    <xsl:when test="$zone = 0"><sign>1</sign><val><xsl:value-of select="$deg360" /></val></xsl:when>
    <xsl:when test="$zone = 1"><sign>1</sign><val><xsl:value-of select="180 - $deg360" /></val></xsl:when>
    <xsl:when test="$zone = 2"><sign>-1</sign><val><xsl:value-of select="$deg360 - 180" /></val></xsl:when>
    <xsl:when test="$zone = 3"><sign>-1</sign><val><xsl:value-of select="360 - $deg360" /></val></xsl:when>
    <xsl:otherwise />
   </xsl:choose>
  </xsl:variable>
<xsl:call-template name="sin90" >
  <xsl:with-param name="sign" select="$sinparts/sign"/>
  <xsl:with-param name="val" select="$sinparts/val"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="sin90">
  <xsl:param name="sign" />
  <xsl:param name="val" />
    <xsl:variable name="t" select="3.14159265358979323846 * $val div 180" />
    <xsl:variable name="t2" select="$t * $t" />
    <xsl:value-of select="$sign * ($t * (1 - $t2 div 6 * ( 1 - $t2 div 20 * ( 1- $t2 div 42 * (1 - $t2 div 72 * ( 1 - $t2 div 110 * ( 1 - $t2 div 156 * ( 1 - $t2 div 210 * (1 - $t2 div 272 )))))))))       " />
</xsl:template>


<!-- ************************************************************ -->
<!-- ************************ exp (n) ************************ -->
<!-- ************************************************************ -->

<xsl:template name="exp">
  <xsl:param name="n" />
    <xsl:value-of select="1 + n * (1 + (n div 2) * (1 + (n div 3) * (1 + (n div 4) * (1 + (n div 5) * (1 + (n div 6) * (1 + (n div 7) *( 1 + (n div 8))))))))       " />
</xsl:template>






</xsl:stylesheet>