<?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="trans">
          <trans>
          <cv ch="A" ps="1"/>
          <cv ch="B" ps="2"/>
          <cv ch="C" ps="3"/>
          <cv ch="D" ps="4"/>
          <cv ch="E" ps="5"/>
          <cv ch="F" ps="6"/>
          <cv ch="G" ps="7"/>
          <cv ch="H" ps="8"/>
          <cv ch="I" ps="9"/>
          <cv ch="J" ps="10"/>
          <cv ch="K" ps="11"/>
          <cv ch="L" ps="12"/>
          <cv ch="M" ps="13"/>
          <cv ch="N" ps="14"/>
          <cv ch="O" ps="15"/>
          <cv ch="P" ps="16"/>
          <cv ch="Q" ps="17"/>
          <cv ch="R" ps="18"/>
          <cv ch="S" ps="19"/>
          <cv ch="T" ps="20"/>
          <cv ch="U" ps="21"/>
          <cv ch="V" ps="22"/>
          <cv ch="W" ps="23"/>
          <cv ch="X" ps="24"/>
          <cv ch="Y" ps="25"/>
          <cv ch="Z" ps="26"/>
          <cv ch="0" ps="30"/>
          <cv ch="1" ps="31"/>
          <cv ch="2" ps="32"/>
          <cv ch="3" ps="33"/>
          <cv ch="4" ps="34"/>
          <cv ch="5" ps="35"/>
          <cv ch="6" ps="36"/>
          <cv ch="7" ps="37"/>
          <cv ch="8" ps="38"/>
          <cv ch="9" ps="39"/>
          <cv ch="+" ps="40"/>
          <cv ch="-" ps="29"/>
          <cv ch="*" ps="41"/>
          <cv ch="/" ps="42"/>
          <cv ch="=" ps="43"/>
          <cv ch="(" ps="44"/>
          <cv ch=")" ps="45"/>
          <cv ch="," ps="27"/>
          <cv ch="." ps="28"/>
          <cv ch="'" ps="46"/>
          <cv ch="?" ps="47"/>
          <cv ch="_" ps="40"/>
          </trans>
          </xsl:variable>

<xsl:variable name="stacks">
<stacks>
<stack n="1"></stack>
<stack n="2"></stack>
<stack n="3"></stack>
<stack n="4"></stack>
<stack n="5"></stack>
<stack n="6"></stack>
<stack n="7">
<array ARR="1">
<setln X1="0." Y1="0." X2=".25" Y2="1."/>
<expar X1=".25" Y1="1." X2=".417" Y2="1."/>
<expar X1=".417" Y1="1." X2=".667" Y2="0."/>
<expar X1=".125" Y1=".5" X2=".541" Y2=".5"/>
</array>
<array ARR="2">
<setcv X1="0." Y1=".5" X2=".417" Y2=".5"/>
<expar X1=".583" Y1=".667" X2=".583" Y2=".833"/>
<expar X1=".417" Y1="1." X2="0." Y2="1."/>
<expar X1="0." Y1="0." X2=".5" Y2="0."/>
<expar X1=".667" Y1=".167" X2=".667" Y2=".417"/>
<expar X1=".5" Y1=".5" X2=".5" Y2=".5"/>
</array>
<array ARR="3">
<setcv X1=".667" Y1=".833" X2=".5" Y2="1."/>
<expar X1=".167" Y1="1." X2="0." Y2=".833"/>
<expar X1="0." Y1=".167" X2=".167" Y2="0."/>
<expar X1=".5" Y1="0." X2=".667" Y2=".167"/>
</array>
<array ARR="4">
<setcv X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1="0.17" X2=".5" Y2="0."/>
<expar X1="0." Y1="0." X2="0." Y2="0."/>
</array>
<array ARR="5">
<setln X1="0." Y1=".5" X2=".417" Y2=".5"/>
<expar X1=".583" Y1="1." X2="0." Y2="1."/>
<expar X1="0." Y1="1." X2="0." Y2="0."/>
<expar X1="0." Y1="0." X2=".667" Y2="0."/>
</array>
<array ARR="6">
<setln X1="0." Y1=".5" X2=".417" Y2=".5"/>
<expar X1=".583" Y1="1." X2="0." Y2="1."/>
<expar X1="0." Y1="1." X2="0." Y2="0."/>
</array>
<array ARR="7">
<setcv X1=".667" Y1=".833" X2=".5" Y2="1."/>
<expar X1=".167" Y1="1." X2="0." Y2=".833"/>
<expar X1="0." Y1=".167" X2=".167" Y2="0."/>
<expar X1=".5" Y1="0." X2=".667" Y2=".167"/>
<expar X1=".667" Y1=".417" X2=".417" Y2=".417"/>
</array>
<array ARR="8">
<setln X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1="0." Y1=".5" X2=".667" Y2=".5"/>
<expar X1=".667" Y1="1." X2=".667" Y2="0."/>
</array>
<array ARR="9">
<setln X1=".25" Y1="1." X2=".417" Y2="1."/>
<expar X1=".333" Y1="1." X2=".333" Y2="0."/>
<expar X1=".25" Y1="0." X2=".417" Y2="0."/>
</array>
<array ARR="10">
<setln X1="0." Y1=".333" X2="0." Y2=".167"/>
<expar X1="0." Y1=".167" X2=".167" Y2="0."/>
<expar X1=".167" Y1="0." X2=".417" Y2="0."/>
<expar X1=".417" Y1="0." X2=".583" Y2=".167"/>
<expar X1=".583" Y1=".167" X2=".583" Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2="1."/>
</array>
<array ARR="11">
<setln X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1=".583" Y1="1." X2="0." Y2=".417"/>
<expar X1=".25" Y1=".583" X2=".667" Y2="0."/>
</array>
<array ARR="12">
<setcv X1="0." Y1="1." X2="0." Y2="0."/>
<expar X1=".667" Y1="0." X2=".667" Y2="0."/>
</array>
<array ARR="13">
<setcv X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1=".333" Y1=".5" X2=".667" Y2="1."/>
<expar X1=".667" Y1="0." X2=".667" Y2="0."/>
</array>
<array ARR="14">
<setcv X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1=".667" Y1="0." X2=".667" Y2="1."/>
</array>
<array ARR="15">
<setcv X1="0." Y1=".167" X2="0." Y2=".833"/>
<expar X1=".167" Y1="1." X2=".5" Y2="1."/>
<expar X1=".667" Y1=".833" X2=".667" Y2=".167"/>
<expar X1=".5" Y1="0." X2=".167" Y2="0."/>
<expar X1="0." Y1=".167" X2="0." Y2=".167"/>
</array>
<array ARR="16">
<setcv X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".667" X2=".5" Y2=".5"/>
<expar X1="0." Y1=".5" X2="0." Y2=".5"/>
</array>
<array ARR="17">
<setcv X1=".417" Y1=".25" X2=".583" Y2=".083"/>
<expar X1=".5" Y1="0." X2=".167" Y2="0."/>
<expar X1="0." Y1=".167" X2="0." Y2=".833"/>
<expar X1=".167" Y1="1." X2=".5" Y2="1."/>
<expar X1=".667" Y1=".833" X2=".667" Y2=".167"/>
<expar X1=".583" Y1=".083" X2=".667" Y2="0."/>
</array>
<array ARR="18">
<setln X1="0." Y1="0." X2="0." Y2="1."/>
<expar X1="0." Y1="1." X2=".5" Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".833" X2=".667" Y2=".667"/>
<expar X1=".667" Y1=".667" X2=".5" Y2=".5"/>
<expar X1=".5" Y1=".5" X2="0." Y2=".5"/>
<expar X1=".5" Y1=".5" X2=".667" Y2="0."/>
</array>
<array ARR="19">
<setcv X1="0." Y1=".333" X2="0." Y2=".167"/>
<expar X1=".167" Y1="0." X2=".5" Y2="0."/>
<expar X1=".667" Y1=".167" X2=".667" Y2=".333"/>
<expar X1=".5" Y1=".5" X2=".167" Y2=".5"/>
<expar X1="0." Y1=".667" X2="0." Y2=".833"/>
<expar X1=".167" Y1="1." X2=".417" Y2="1."/>
<expar X1=".583" Y1=".833" X2=".583" Y2=".833"/>
</array>
<array ARR="20">
<setln X1="0." Y1="1." X2=".667" Y2="1."/>
<expar X1=".333" Y1="1." X2=".333" Y2="0."/>
</array>
<array ARR="21">
<setcv X1="0." Y1="1." X2="0." Y2=".167"/>
<expar X1=".167" Y1="0." X2=".5" Y2="0."/>
<expar X1=".667" Y1=".167" X2=".667" Y2="1."/>
</array>
<array ARR="22">
<setcv X1="0." Y1="1." X2=".333" Y2="0."/>
<expar X1=".667" Y1="0.17" X2=".667" Y2="1."/>
</array>
<array ARR="23">
<setcv X1="0." Y1="1." X2=".167" Y2="0."/>
<expar X1=".333" Y1=".667" X2=".5" Y2="0."/>
<expar X1=".667" Y1="1." X2=".667" Y2="1."/>
</array>
<array ARR="24">
<setln X1="0." Y1="1." X2=".667" Y2="0."/>
<expar X1="0." Y1="0." X2=".667" Y2="1."/>
</array>
<array ARR="25">
<setln X1="0." Y1="1." X2=".333" Y2=".5"/>
<expar X1=".667" Y1="1." X2=".333" Y2=".5"/>
<expar X1=".333" Y1=".5" X2=".333" Y2="0."/>
</array>
<array ARR="26">
<setcv X1="0." Y1="1." X2=".667" Y2="1."/>
<expar X1="0." Y1="0." X2=".667" Y2="0."/>
</array>
<array ARR="27">
<setcv X1=".333" Y1="-.167" X2=".416" Y2="0."/>
<expar X1=".416" Y1=".167" X2=".25" Y2=".167"/>
<expar X1=".25" Y1="0." X2=".416" Y2="0."/>
</array>
<array ARR="28">
<setcv X1=".25" Y1="0." X2=".417" Y2="0."/>
<expar X1=".417" Y1=".167" X2=".25" Y2=".167"/>
<expar X1=".25" Y1="0." X2=".25" Y2="0."/>
</array>
<array ARR="29">
<setcv X1="0." Y1=".5" X2=".667" Y2=".5"/>
</array>
<array ARR="30">
<setcv X1="0." Y1=".167" X2="0." Y2=".833"/>
<expar X1=".167" Y1="1." X2=".5" Y2="1."/>
<expar X1=".667" Y1=".833" X2=".667" Y2=".167"/>
<expar X1=".5" Y1="0." X2=".167" Y2="0."/>
<expar X1="0." Y1=".167" X2="0." Y2=".167"/>
</array>
<array ARR="31">
<setln X1=".167" Y1=".667" X2=".333" Y2="1."/>
<expar X1=".333" Y1="1." X2=".333" Y2="0."/>
<expar X1=".167" Y1="0." X2=".5" Y2="0."/>
</array>
<array ARR="32">
<setcv X1="0." Y1=".833" X2=".167" Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".667" X2="0." Y2="0."/>
<expar X1=".667" Y1="0." X2=".667" Y2="0."/>
</array>
<array ARR="33">
<setcv X1="0." Y1=".833" X2=".167" Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".667" X2=".5" Y2=".5"/>
<expar X1=".167" Y1=".5" X2=".5" Y2=".5"/>
<expar X1=".667" Y1=".333" X2=".667" Y2=".167"/>
<expar X1=".5" Y1="0." X2=".167" Y2="0."/>
<expar X1="0." Y1=".167" X2="0." Y2=".167"/>
</array>
<array ARR="34">
<setcv X1=".667" Y1=".25" X2="0." Y2=".25"/>
<expar X1=".333" Y1="1." X2=".5" Y2="1."/>
<expar X1=".5" Y1="0." X2=".5" Y2="0."/>
</array>
<array ARR="35">
<setcv X1="0." Y1=".167" X2=".167" Y2="0."/>
<expar X1=".5" Y1="0." X2=".667" Y2=".167"/>
<expar X1=".667" Y1=".417" X2=".5" Y2=".583"/>
<expar X1=".083" Y1=".583" X2=".083" Y2="1."/>
<expar X1=".667" Y1="1." X2=".667" Y2="1."/>
</array>
<array ARR="36">
<setcv X1="0." Y1=".5" X2=".5" Y2=".5"/>
<expar X1=".667" Y1=".333" X2=".667" Y2=".167"/>
<expar X1=".5" Y1="0." X2=".167" Y2="0."/>
<expar X1="0." Y1=".167" X2="0." Y2=".833"/>
<expar X1=".167" Y1="1." X2=".5" Y2="1."/>
<expar X1=".67" Y1=".833" X2=".67" Y2=".833"/>
</array>
<array ARR="37">
<setcv X1="0." Y1="1." X2=".667" Y2="1."/>
<expar X1=".167" Y1="0." X2=".167" Y2="0."/>
</array>
<array ARR="38">
<setcv X1=".167" Y1=".5" X2="0." Y2=".667"/>
<expar X1="0." Y1=".833" X2=".167" Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".667" X2=".5" Y2=".5"/>
<expar X1=".167" Y1=".5" X2="0." Y2=".333"/>
<expar X1="0." Y1=".167" X2=".167" Y2="0."/>
<expar X1=".5" Y1="0." X2=".667" Y2=".167"/>
<expar X1=".667" Y1=".333" X2=".5" Y2=".5"/>
</array>
<array ARR="39">
<setcv X1=".167" Y1="0." X2=".167" Y2="0."/>
<expar X1=".5" Y1="0." X2=".667" Y2=".167"/>
<expar X1=".667" Y1=".833" X2=".5" Y2="1."/>
<expar X1=".167" Y1="1." X2="0." Y2=".833"/>
<expar X1="0." Y1=".667" X2=".167" Y2=".5"/>
<expar X1=".5" Y1=".5" X2=".667" Y2=".667"/>
</array>
<array ARR="40">
<setcv X1="0." Y1="0." X2="0." Y2="0."/>
</array>
<array ARR="41">
<setln X1="0." Y1=".5" X2=".667" Y2=".5"/>
<expar X1=".333" Y1=".167" X2=".333" Y2=".833"/>
</array>
<array ARR="42">
<setln X1="0." Y1=".5" X2=".667" Y2=".5"/>
<expar X1=".333" Y1=".167" X2=".333" Y2=".833"/>
<expar X1=".111" Y1=".811" X2=".555" Y2=".189"/>
<expar X1=".555" Y1=".811" X2=".111" Y2=".189"/>
</array>
<array ARR="43">
<setln X1=".111" Y1=".111" X2=".889" Y2=".889"/>
</array>
<array ARR="44">
<setln X1="0." Y1=".633" X2=".667" Y2=".633"/>
<expar X1="0." Y1=".367" X2=".667" Y2=".333"/>
</array>
<array ARR="45">
<setcv X1=".167" Y1="0." X2="0." Y2=".167"/>
<expar X1="0." Y1=".833" X2=".167" Y2="1."/>
<setcv X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".167" X2=".5" Y2="0."/>
</array>
<array ARR="46">
<setcv X1=".68" Y1="1." X2=".83" Y2="1."/>
<expar X1=".75" Y1=".75" X2=".68" Y2=".75"/>
<expar X1=".68" Y1="1." X2=".68" Y2="1."/>
</array>
<array ARR="47">
<setcv X1="0." Y1=".833" X2=".167" Y2="1."/>
<expar X1=".5" Y1="1." X2=".667" Y2=".833"/>
<expar X1=".667" Y1=".667" X2=".5" Y2=".5"/>
<expar X1=".333" Y1=".5" X2=".333" Y2=".333"/>
<setcv X1=".333" Y1="0." X2=".4" Y2=".1"/>
<expar X1=".333" Y1=".2" X2=".266" Y2=".1"/>
<expar X1=".333" Y1="0." X2=".333" Y2="0."/>
</array>
</stack>
<stack n="8"></stack>
<stack n="9"></stack>
</stacks>
</xsl:variable>
<xsl:variable name="restofcmnds">
</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="create_arrays">
   <xsl:with-param name="cmnds" select="cmnd"/>
   <xsl:with-param name="stacks" select="$stacks"/>
   <xsl:with-param name="restofcmnds" select="$restofcmnds"/>
  </xsl:call-template>
</camp>
</xsl:template>


<xsl:template name="create_arrays">
<xsl:param name="cmnds"/>
<xsl:param name="stacks"/>
<xsl:param name="restofcmnds"/>
<xsl:choose>
  <xsl:when test="count($cmnds) = 0">
   <xsl:copy-of select="$restofcmnds"/>
   <xsl:copy-of select="$stacks"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:choose>
      <xsl:when test="$cmnds[1]/@class > 2">    
          <xsl:variable name="name"><xsl:value-of select="$cmnds[1]/@name"/></xsl:variable>
          <xsl:variable name="S"><xsl:value-of select="$cmnds[1]/@S"/></xsl:variable>
          <xsl:variable name="ARR"><xsl:value-of select="$cmnds[1]/@ARR"/></xsl:variable>
        <xsl:variable name="newrestofcmnds">
          <xsl:copy-of select="$restofcmnds"/>
          <xsl:choose>
          <xsl:when test="$name = 'DRAW'">
          <cmnd>
          <xsl:copy-of select="$cmnds[1]/@*"/>
           <xsl:choose>
            <xsl:when test="$ARR = 0">
             <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR = $ARR]"/> 
            </xsl:otherwise>
          </xsl:choose>
          </cmnd>
          </xsl:when>
          <xsl:otherwise>
          <xsl:copy-of select="$cmnds[1]"/>
          </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:call-template name="create_arrays">
          <xsl:with-param name="cmnds" select="$cmnds[position() != 1]"/>
          <xsl:with-param name="stacks" select="$stacks"/>
          <xsl:with-param name="restofcmnds" select="$newrestofcmnds"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$cmnds[1]/@class = 2">    
        <xsl:variable name="newstacks">
        <stacks>
          <xsl:variable name="name"><xsl:value-of select="$cmnds[1]/@name"/></xsl:variable>
          <xsl:variable name="S"><xsl:value-of select="$cmnds[1]/@S"/></xsl:variable>
          <xsl:variable name="ARR"><xsl:value-of select="$cmnds[1]/@ARR"/></xsl:variable>
        <xsl:choose>
        
        <xsl:when test="$name = 'ERASE'">
          <xsl:copy-of select="$stacks/stacks/stack[@n != $S]"/> 
          <xsl:choose>
            <xsl:when test="$ARR = 0">
               <stack n="{$S}">
               </stack>
            </xsl:when>
            <xsl:otherwise>
               <stack n="{$S}">
                 <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR != $ARR]"/> 
               </stack>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>

        <xsl:when test="$name = 'ROTAT'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="ang"><xsl:value-of select="$cmnds[1]/@ANG"/></xsl:variable>
          <xsl:variable name="cosarr">
          <xsl:call-template name="cosine">
          <xsl:with-param name="deg"><xsl:value-of select="$ang"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="sinarr">
          <xsl:call-template name="sine">
          <xsl:with-param name="deg"><xsl:value-of select="$ang"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>

          <xsl:copy-of select="$stacks/stacks/stack[@n != $S]"/> 
          <xsl:for-each select="$stacks/stacks/stack[@n = $S]">
            <stack n="{$S}">
              <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR != $ARR]"/> 
              <array ARR="{$ARR}">
              <xsl:for-each select="$stacks/stacks/stack[@n = $S]/array[@ARR = $ARR]/*" >
                <xsl:copy>
                  <xsl:attribute name="X1"><xsl:value-of select="$x + (@X1 - $x) * $cosarr - (@Y1 - $y) * $sinarr"/></xsl:attribute>
                  <xsl:attribute name="X2"><xsl:value-of select="$x + (@X2 - $x) * $cosarr - (@Y2 - $y) * $sinarr"/></xsl:attribute>
                  <xsl:attribute name="Y1"><xsl:value-of select="$y + (@Y1 - $y) * $cosarr + (@X1 - $x) * $sinarr"/></xsl:attribute>
                  <xsl:attribute name="Y2"><xsl:value-of select="$y + (@Y2 - $y) * $cosarr + (@X2 - $x) * $sinarr"/></xsl:attribute>
                </xsl:copy>
              </xsl:for-each>
            </array>
          </stack>
          </xsl:for-each>
        </xsl:when>
        <xsl:when test="$name = 'OFSET'">
          <xsl:variable name="dx"><xsl:value-of select="$cmnds[1]/@DX"/></xsl:variable>
          <xsl:variable name="dy"><xsl:value-of select="$cmnds[1]/@DY"/></xsl:variable>
          <xsl:copy-of select="$stacks/stacks/stack[@n != $S]"/> 
          <xsl:for-each select="$stacks/stacks/stack[@n = $S]">
            <stack n="{$S}">
            
            <xsl:choose>
            <xsl:when test="$ARR = 0">
            <xsl:for-each select="$stacks/stacks/stack[@n = $S]/array">
            <array ARR="{@ARR}">
            <xsl:for-each select="*" >
                <xsl:copy>
                  <xsl:attribute name="X1"><xsl:value-of select="@X1 + $dx"/></xsl:attribute>
                  <xsl:attribute name="X2"><xsl:value-of select="@X2 + $dx"/></xsl:attribute>
                  <xsl:attribute name="Y1"><xsl:value-of select="@Y1 + $dy"/></xsl:attribute>
                  <xsl:attribute name="Y2"><xsl:value-of select="@Y2 + $dy"/></xsl:attribute>
                </xsl:copy>
              </xsl:for-each>

            </array>
            </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR != $ARR]"/> 
              <array ARR="{$ARR}">
              <xsl:for-each select="$stacks/stacks/stack[@n = $S]/array[@ARR = $ARR]/*" >
                <xsl:copy>
                  <xsl:attribute name="X1"><xsl:value-of select="@X1 + $dx"/></xsl:attribute>
                  <xsl:attribute name="X2"><xsl:value-of select="@X2 + $dx"/></xsl:attribute>
                  <xsl:attribute name="Y1"><xsl:value-of select="@Y1 + $dy"/></xsl:attribute>
                  <xsl:attribute name="Y2"><xsl:value-of select="@Y2 + $dy"/></xsl:attribute>
                </xsl:copy>
              </xsl:for-each>
            </array>
            </xsl:otherwise>
            </xsl:choose>
          </stack>
          </xsl:for-each>
        </xsl:when>

        <xsl:when test="$name = 'SIZE'">
          <xsl:variable name="xref"><xsl:value-of select="$cmnds[1]/@XREF"/></xsl:variable>
          <xsl:variable name="yref"><xsl:value-of select="$cmnds[1]/@YREF"/></xsl:variable>
          <xsl:variable name="xmag"><xsl:value-of select="$cmnds[1]/@XMAG"/></xsl:variable>
          <xsl:variable name="ymag"><xsl:value-of select="$cmnds[1]/@YMAG"/></xsl:variable>

          <xsl:copy-of select="$stacks/stacks/stack[@n != $S]"/> 
          <xsl:for-each select="$stacks/stacks/stack[@n = $S]">
            <stack n="{$S}">
            
            <xsl:choose>
            <xsl:when test="$ARR = 0">
            <xsl:for-each select="$stacks/stacks/stack[@n = $S]/array">
            <array ARR="{@ARR}">
            <xsl:for-each select="*" >
                <xsl:copy>
                  <xsl:attribute name="X1"><xsl:value-of select="(@X1 - $xref) * $xmag + $xref"/></xsl:attribute>
                  <xsl:attribute name="X2"><xsl:value-of select="(@X2 - $xref) * $xmag + $xref"/></xsl:attribute>
                  <xsl:attribute name="Y1"><xsl:value-of select="(@Y1 - $yref) * $ymag + $yref"/></xsl:attribute>
                  <xsl:attribute name="Y2"><xsl:value-of select="(@Y2 - $yref) * $ymag + $yref"/></xsl:attribute>
                </xsl:copy>
              </xsl:for-each>

            </array>
            </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>



              <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR != $ARR]"/> 
              <array ARR="{$ARR}">
              <xsl:for-each select="$stacks/stacks/stack[@n = $S]/array[@ARR = $ARR]/*" >
                <xsl:copy>
                  <xsl:attribute name="X1"><xsl:value-of select="(@X1 - $xref) * $xmag + $xref"/></xsl:attribute>
                  <xsl:attribute name="X2"><xsl:value-of select="(@X2 - $xref) * $xmag + $xref"/></xsl:attribute>
                  <xsl:attribute name="Y1"><xsl:value-of select="(@Y1 - $yref) * $ymag + $yref"/></xsl:attribute>
                  <xsl:attribute name="Y2"><xsl:value-of select="(@Y2 - $yref) * $ymag + $yref"/></xsl:attribute>
                </xsl:copy>
              </xsl:for-each>
            </array>
            </xsl:otherwise>
            </xsl:choose>
          </stack>
          </xsl:for-each>
        </xsl:when>

        <xsl:when test="$name = 'TNSFR'">
          <xsl:variable name="sb"><xsl:value-of select="$cmnds[1]/@SB"/></xsl:variable>
          <xsl:variable name="arrb"><xsl:value-of select="$cmnds[1]/@ARRB"/></xsl:variable>
          <xsl:variable name="p"><xsl:value-of select="$cmnds[1]/@P"/></xsl:variable>
          <xsl:variable name="p1"><xsl:value-of select="round($cmnds[1]/@P1)"/></xsl:variable>
          <xsl:variable name="p2"><xsl:value-of select="round($cmnds[1]/@P2)"/></xsl:variable>
          <xsl:variable name="sa"><xsl:value-of select="round($cmnds[1]/@SA)"/></xsl:variable>
          <xsl:variable name="arra"><xsl:value-of select="round($cmnds[1]/@ARRA)"/></xsl:variable>
          <xsl:variable name="bpt1"><xsl:value-of select="round($cmnds[1]/@BPT1)"/></xsl:variable>
          <xsl:variable name="st"><xsl:value-of select="floor($p1 div 2) + ($p1 mod 2)"/></xsl:variable>
          <xsl:variable name="fi"><xsl:value-of select="floor($p2 div 2) + ($p2 mod 2)"/></xsl:variable>
          <xsl:variable name="bst"><xsl:choose><xsl:when test="$bpt1 = 0">1</xsl:when><xsl:otherwise><xsl:value-of select=" floor($bpt1 div 2) + ($bpt1 mod 2)"/></xsl:otherwise></xsl:choose></xsl:variable>
            <xsl:if test="$p = 0 and not($stacks/stacks/stack[@n = $sb]/array[@ARR = $arrb])">
            <!--ARRB does not exist and all X and Y copied-->
            <!--None of the other options are used very much so not implemented-->
              <xsl:copy-of select="$stacks/stacks/stack[@n != $sb]"/> 
              <xsl:for-each select="$stacks/stacks/stack[@n = $sb]">
                <stack n="{$sb}">
                  <xsl:copy-of select="$stacks/stacks/stack[@n = $sb]/array[@ARR != $arrb]"/> 
                  <array ARR="{$arrb}">

                  <xsl:for-each select="$stacks/stacks/stack[@n = $sa]/array[@ARR = $arra]/*" ><!-- Simple case copying whole over-->
                     <xsl:if test="(position() >= $st) and  (position() &lt;= $fi)">
                      <xsl:copy>
                      <xsl:copy-of select="@*"/>
                      </xsl:copy>
                    </xsl:if>
                  </xsl:for-each>
                </array>
              </stack>
              </xsl:for-each>
          </xsl:if>
        </xsl:when>
            
        <xsl:when test="$name = 'LETER'">
          <xsl:variable name="s"><xsl:value-of select="$cmnds[1]/@S"/></xsl:variable>
          <xsl:variable name="arr"><xsl:value-of select="$cmnds[1]/@ARR"/></xsl:variable>
          <xsl:variable name="text">
          <xsl:choose>
          <xsl:when test="contains($cmnds[1]/@TEXT, '>')"><xsl:value-of select="substring-before($cmnds[1]/@TEXT, '>')"/></xsl:when>
          <xsl:otherwise><xsl:value-of select="$cmnds[1]/@TEXT"/></xsl:otherwise></xsl:choose></xsl:variable>
          <xsl:variable name="txtar">
          <txtar>
          <xsl:call-template name="split">
          <xsl:with-param name="string"><xsl:value-of select="$text"/></xsl:with-param>
          </xsl:call-template>
          </txtar>
          </xsl:variable>
          <xsl:copy-of select="$stacks/stacks/stack[@n != $s]"/> 
          <xsl:for-each select="$stacks/stacks/stack[@n = $s]">
            <stack n="{$s}">
            <xsl:copy-of select="$stacks/stacks/stack[@n = $s]/array[@ARR &lt; $arr]"/> 
            <xsl:for-each select="$txtar/txtar/ch">
            <xsl:variable name="nextchar"><xsl:value-of select="."/></xsl:variable>
              <xsl:variable name="pos"><xsl:value-of select="position()"/></xsl:variable>
              <xsl:variable name="chrarr"><xsl:value-of select="$pos + $arr - 1"/></xsl:variable>
              <array ARR="{$chrarr}">
               <xsl:variable name="fontpos"><xsl:value-of select="$trans/trans/cv[@ch = $nextchar]/@ps"/></xsl:variable>
               <xsl:for-each select="$stacks/stacks/stack[@n = 7]/array[@ARR = $fontpos]/*">

                 <xsl:copy>
                 <xsl:attribute name="X1"><xsl:value-of select="@X1 + $pos + $arr - 1"/></xsl:attribute>
                   <xsl:copy-of select="@Y1"/>
                 <xsl:attribute name="X2"><xsl:value-of select="@X2 + $pos + $arr - 1"/></xsl:attribute>
                   <xsl:copy-of select="@Y2"/>
                 </xsl:copy>
               </xsl:for-each>
             </array>
           </xsl:for-each>
           </stack>
         </xsl:for-each>
       </xsl:when>

        <xsl:otherwise>
           <xsl:copy-of select="$stacks/stacks/stack"/> 
        </xsl:otherwise>
        </xsl:choose>
        </stacks>
        </xsl:variable>
        <xsl:call-template name="create_arrays">
          <xsl:with-param name="cmnds" select="$cmnds[position() != 1]"/>
          <xsl:with-param name="stacks" select="$newstacks"/>
          <xsl:with-param name="restofcmnds" select="$restofcmnds"/>
        </xsl:call-template>
        
        
      </xsl:when>

      <xsl:otherwise>
        <xsl:variable name="newstacks">
        <stacks>
          <xsl:variable name="name"><xsl:value-of select="$cmnds[1]/@name"/></xsl:variable>
          <xsl:variable name="S"><xsl:value-of select="$cmnds[1]/@S"/></xsl:variable>
          <xsl:variable name="ARR"><xsl:value-of select="$cmnds[1]/@ARR"/></xsl:variable>
          
          
          <xsl:variable name="X1"><xsl:value-of select="$cmnds[1]/@X1"/></xsl:variable>
          <xsl:variable name="Y1"><xsl:value-of select="$cmnds[1]/@Y1"/></xsl:variable>
          <xsl:variable name="X2"><xsl:value-of select="$cmnds[1]/@X2"/></xsl:variable>
          <xsl:variable name="Y2"><xsl:value-of select="$cmnds[1]/@Y2"/></xsl:variable>
          <xsl:copy-of select="$stacks/stacks/stack[@n != $S]"/> 
          <xsl:for-each select="$stacks/stacks/stack[@n = $S]">
          <stack n="{$S}">
           <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR != $ARR]"/> 
          <array ARR="{$ARR}">
           <xsl:copy-of select="$stacks/stacks/stack[@n = $S]/array[@ARR = $ARR]/*" />
          <xsl:choose>
          <xsl:when test="$name = 'SETCV'">
           <setcv X1="{$X1}" Y1="{$Y1}" X2="{$X2}" Y2="{$Y2}" />
          </xsl:when>
          <xsl:when test="$name = 'RECT'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="lngth"><xsl:value-of select="$cmnds[1]/@LNGTH"/></xsl:variable>
          <xsl:variable name="hgt"><xsl:value-of select="$cmnds[1]/@HGT"/></xsl:variable>
          <setcv X1="{$x}" Y1="{$y}" X2="{$x + $lngth}" Y2="{$y}" />
          <expar X1="{$x + $lngth}" Y1="{$y + $hgt}" X2="{$x}" Y2="{$y + $hgt}" />
          <expar X1="{$x}" Y1="{$y}" X2="{$x}" Y2="{$y}" />
          </xsl:when>

          <xsl:when test="$name = 'TRNGL'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="base"><xsl:value-of select="$cmnds[1]/@BASE"/></xsl:variable>
          <xsl:variable name="hgt"><xsl:value-of select="$cmnds[1]/@HGT"/></xsl:variable>
          <setcv X1="{$x}" Y1="{$y}" X2="{$x + $base}" Y2="{$y}" />
          <expar X1="{$x + 0.5* $base}" Y1="{$y + $hgt}" X2="{$x}" Y2="{$y}" />
          </xsl:when>

          <xsl:when test="$name = 'CROSS'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="side"><xsl:value-of select="$cmnds[1]/@SIDE"/></xsl:variable>
          <setln X1="{$x + $side}" Y1="{$y}" X2="{$x}" Y2="{$y + $side}" />
          <expar X1="{$x + $side}" Y1="{$y + $side}" X2="{$x}" Y2="{$y}" />
          </xsl:when>


          <xsl:when test="$name = 'GRID'">
          <xsl:variable name="xdiv"><xsl:value-of select="$cmnds[1]/@XDIV"/></xsl:variable>
          <xsl:variable name="ydiv"><xsl:value-of select="$cmnds[1]/@YDIV"/></xsl:variable>
          <xsl:variable name="incx"><xsl:value-of select="12.0 div $xdiv  "/></xsl:variable>
          <xsl:variable name="incy"><xsl:value-of select="9.0 div $ydiv  "/></xsl:variable>
          <xsl:call-template name="drawygrid">
          <xsl:with-param name="xval"><xsl:value-of select="$incx"/></xsl:with-param>
          <xsl:with-param name="incx"><xsl:value-of select="$incx"/></xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="drawxgrid">
          <xsl:with-param name="yval"><xsl:value-of select="$incy"/></xsl:with-param>
          <xsl:with-param name="incy"><xsl:value-of select="$incy"/></xsl:with-param>
          </xsl:call-template>
          </xsl:when>
          
          <xsl:when test="$name = 'SETLN'">
          <setln X1="{$X1}" Y1="{$Y1}" X2="{$X2}" Y2="{$Y2}" />
          </xsl:when>
          <xsl:when test="$name = 'EXPAR'">
          <expar X1="{$X1}" Y1="{$Y1}" X2="{$X2}" Y2="{$Y2}" />
          </xsl:when>
          <xsl:when test="$name = 'CIRCL'">
          <xsl:variable name="d"><xsl:value-of select="$cmnds[1]/@D"/></xsl:variable>
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="rad"><xsl:value-of select="$cmnds[1]/@RAD"/></xsl:variable>

          <xsl:choose>
          <xsl:when test="$d = 0">
          <setcv X1="{$x + $rad}"        Y1="{$y}"             X2="{$x + $rad*0.985}" Y2="{$y + $rad*0.174}" />
          <expar X1="{$x + $rad*0.94}"   Y1="{$y + $rad*0.342}"  X2="{$x + $rad*0.866}" Y2="{$y + $rad*0.5}" />
          <expar X1="{$x + $rad*0.766}"  Y1="{$y + $rad*0.643}"  X2="{$x + $rad*0.643}" Y2="{$y + $rad*0.766}" />
          <expar X1="{$x + $rad*0.5}"    Y1="{$y + $rad*0.866}"  X2="{$x + $rad*0.342}" Y2="{$y + $rad*0.94}" />
          <expar X1="{$x + $rad*0.174}"  Y1="{$y + $rad*0.985}"  X2="{$x + $rad*0}"     Y2="{$y + $rad*1}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y + $rad*0.985}"   X2="{$x - $rad*0.342}" Y2="{$y + $rad*0.94}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y + $rad*0.866}"   X2="{$x - $rad*0.643}" Y2="{$y + $rad*0.766}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y + $rad*0.643}"   X2="{$x - $rad*0.866}" Y2="{$y + $rad*0.5}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y + $rad*0.342}"   X2="{$x - $rad*0.985}" Y2="{$y + $rad*0.174}" />
          <expar X1="{$x - $rad*1}"     Y1="{$y + $rad*0}"       X2="{$x - $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y - $rad*0.342}"   X2="{$x - $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y - $rad*0.643}"   X2="{$x - $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y - $rad*0.866}"   X2="{$x - $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y - $rad*0.985}"   X2="{$x + $rad*0}"     Y2="{$y - $rad*1}" />
          <expar X1="{$x  +  $rad*0.174}"  Y1="{$y - $rad*0.985}"  X2="{$x + $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x + $rad*0.5}"    Y1="{$y - $rad*0.866}"  X2="{$x + $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x  +  $rad*0.766}"  Y1="{$y - $rad*0.643}"  X2="{$x + $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x + $rad*0.94}"   Y1="{$y - $rad*0.342}"  X2="{$x + $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x + $rad*1}"      Y1="{$y - $rad*0}"      X2="{$x + $rad*1}"     Y2="{$y - $rad*0}" />
          </xsl:when>
          <xsl:when test="$d = 1">
          <setln X1="{$x+$rad}"        Y1="{$y}"             X2="{$x+$rad*0.985}" Y2="{$y+$rad*0.174}" />
          <expar X1="{$x+$rad*0.94}"   Y1="{$y+$rad*0.342}"  X2="{$x+$rad*0.866}" Y2="{$y+$rad*0.5}" />
          <expar X1="{$x+$rad*0.766}"  Y1="{$y+$rad*0.643}"  X2="{$x+$rad*0.643}" Y2="{$y+$rad*0.766}" />
          <expar X1="{$x+$rad*0.5}"    Y1="{$y+$rad*0.866}"  X2="{$x+$rad*0.342}" Y2="{$y+$rad*0.94}" />
          <expar X1="{$x+$rad*0.174}"  Y1="{$y+$rad*0.985}"  X2="{$x+$rad*0}"     Y2="{$y+$rad*1}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y+$rad*0.985}"   X2="{$x - $rad*0.342}" Y2="{$y+$rad*0.94}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y+$rad*0.866}"   X2="{$x - $rad*0.643}" Y2="{$y+$rad*0.766}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y+$rad*0.643}"   X2="{$x - $rad*0.866}" Y2="{$y+$rad*0.5}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y+$rad*0.342}"   X2="{$x - $rad*0.985}" Y2="{$y+$rad*0.174}" />
          <expar X1="{$x - $rad*1}"     Y1="{$y+$rad*0}"       X2="{$x - $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y - $rad*0.342}"   X2="{$x - $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y - $rad*0.643}"   X2="{$x - $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y - $rad*0.866}"   X2="{$x - $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y - $rad*0.985}"   X2="{$x+$rad*0}"     Y2="{$y - $rad*1}" />
          <expar X1="{$x+$rad*0.174}"  Y1="{$y - $rad*0.985}"  X2="{$x+$rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x+$rad*0.5}"    Y1="{$y - $rad*0.866}"  X2="{$x+$rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x+$rad*0.766}"  Y1="{$y - $rad*0.643}"  X2="{$x+$rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x+$rad*0.94}"   Y1="{$y - $rad*0.342}"  X2="{$x+$rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x+$rad*1}"      Y1="{$y - $rad*0}"      X2="{$x+$rad*1}"     Y2="{$y - $rad*0}" />
          </xsl:when>
          </xsl:choose>
          </xsl:when>
          
          
          <xsl:when test="$name = 'ARROW'">
          <xsl:variable name="x1"><xsl:value-of select="$cmnds[1]/@X1"/></xsl:variable>
          <xsl:variable name="y1"><xsl:value-of select="$cmnds[1]/@Y1"/></xsl:variable>
          <xsl:variable name="x2"><xsl:value-of select="$cmnds[1]/@X2"/></xsl:variable>
          <xsl:variable name="y2"><xsl:value-of select="$cmnds[1]/@Y2"/></xsl:variable>
          <xsl:variable name="p"><xsl:value-of select="$cmnds[1]/@P"/></xsl:variable>
          <xsl:variable name="head"><xsl:value-of select="$cmnds[1]/@HEAD"/></xsl:variable>
          <xsl:variable name="dx"><xsl:value-of select="$x2 - $x1"/></xsl:variable>
          <xsl:variable name="dy"><xsl:value-of select="$y2 - $y1"/></xsl:variable>
          <xsl:variable name="length">
          <xsl:call-template name="sqrt">
          <xsl:with-param name="n"><xsl:value-of select="$dx * $dx + $dy * $dy"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="adx"><xsl:value-of select="($dx div $length) * $head"/></xsl:variable>
          <xsl:variable name="ady"><xsl:value-of select="($dy div $length) * $head"/></xsl:variable>
          <xsl:variable name="x3"><xsl:value-of select="$x2 - $adx - $ady"/></xsl:variable>
          <xsl:variable name="y3"><xsl:value-of select="$y2 + $adx - $ady"/></xsl:variable>
          <xsl:variable name="x4"><xsl:value-of select="$x2 - $adx + $ady"/></xsl:variable>
          <xsl:variable name="y4"><xsl:value-of select="$y2 - $adx - $ady"/></xsl:variable>
          <xsl:variable name="dshx"><xsl:value-of select="($x2 - $x1) div 11"/></xsl:variable>
          <xsl:variable name="dshy"><xsl:value-of select="($y2 - $y1) div 11"/></xsl:variable>

          <xsl:choose>
          <xsl:when test="$p = 0">
          <setln X1="{$x1}" Y1="{$y1}" X2="{$x2}" Y2="{$y2}" />
          <setcv X1="{$x3}" Y1="{$y3}" X2="{$x2}" Y2="{$y2}" />
          <expar X1="{$x4}" Y1="{$y4}" X2="{$x4}" Y2="{$y4}" />
          </xsl:when>
          <xsl:when test="$p = 1">
          <setln X1="{$x1}" Y1="{$y1}" X2="{$x2}" Y2="{$y2}" />
          <setcv X1="{$x3}" Y1="{$y3}" X2="{$x2}" Y2="{$y2}" />
          <expar X1="{$x4}" Y1="{$y4}" X2="{$x3}" Y2="{$y3}" />
          </xsl:when>
          <xsl:when test="$p = 2">
          <setln X1="{$x1}" Y1="{$y1}" X2="{$x1 + $dshx}" Y2="{$y1 + $dshy}" />
          <expar X1="{$x1 + 2 * $dshx}" Y1="{$y1 + 2 * $dshy}" X2="{$x1 + 3 * $dshx}" Y2="{$y1 + 3 * $dshy}" />
          <expar X1="{$x1 + 4 * $dshx}" Y1="{$y1 + 4 * $dshy}" X2="{$x1 + 5 * $dshx}" Y2="{$y1 + 5 * $dshy}" />
          <expar X1="{$x1 + 6 * $dshx}" Y1="{$y1 + 6 * $dshy}" X2="{$x1 + 7 * $dshx}" Y2="{$y1 + 7 * $dshy}" />
          <expar X1="{$x1 + 8 * $dshx}" Y1="{$y1 + 8 * $dshy}" X2="{$x1 + 9 * $dshx}" Y2="{$y1 + 9 * $dshy}" />
          <expar X1="{$x1 + 10 * $dshx}" Y1="{$y1 + 10 * $dshy}" X2="{$x2}" Y2="{$y2}" />
          <setcv X1="{$x3}" Y1="{$y3}" X2="{$x2}" Y2="{$y2}" />
          <expar X1="{$x4}" Y1="{$y4}" X2="{$x4}" Y2="{$y4}" />
          </xsl:when>

          <xsl:when test="$p = 3">
          <setln X1="{$x1}" Y1="{$y1}" X2="{$x1 + $dshx}" Y2="{$y1 + $dshy}" />
          <expar X1="{$x1 + 2 * $dshx}" Y1="{$y1 + 2 * $dshy}" X2="{$x1 + 3 * $dshx}" Y2="{$y1 + 3 * $dshy}" />
          <expar X1="{$x1 + 4 * $dshx}" Y1="{$y1 + 4 * $dshy}" X2="{$x1 + 5 * $dshx}" Y2="{$y1 + 5 * $dshy}" />
          <expar X1="{$x1 + 6 * $dshx}" Y1="{$y1 + 6 * $dshy}" X2="{$x1 + 7 * $dshx}" Y2="{$y1 + 7 * $dshy}" />
          <expar X1="{$x1 + 8 * $dshx}" Y1="{$y1 + 8 * $dshy}" X2="{$x1 + 9 * $dshx}" Y2="{$y1 + 9 * $dshy}" />
          <expar X1="{$x1 + 10 * $dshx}" Y1="{$y1 + 10 * $dshy}" X2="{$x2}" Y2="{$y2}" />
          <setcv X1="{$x3}" Y1="{$y3}" X2="{$x2}" Y2="{$y2}" />
          <expar X1="{$x4}" Y1="{$y4}" X2="{$x3}" Y2="{$y3}" />
          </xsl:when>
          </xsl:choose>
          </xsl:when>
          
          <xsl:when test="$name = 'CLOCK'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="rad"><xsl:value-of select="$cmnds[1]/@RAD"/></xsl:variable>
          <xsl:variable name="head"><xsl:value-of select="0.15 * $cmnds[1]/@RAD"/></xsl:variable>

          <xsl:variable name="time"><xsl:value-of select="$cmnds[1]/@TIME"/></xsl:variable>
          <xsl:variable name="floor"><xsl:value-of select="floor($time)"/></xsl:variable>
          <xsl:variable name="min"><xsl:value-of select="$time - $floor"/></xsl:variable>
          <xsl:variable name="hr"><xsl:value-of select="$time div 12"/></xsl:variable>

          <xsl:variable name="cosmin">
          <xsl:call-template name="cosine">
          <xsl:with-param name="deg"><xsl:value-of select="$min * 360"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="sinmin">
          <xsl:call-template name="sine">
          <xsl:with-param name="deg"><xsl:value-of select="$min * 360"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="coshr">
          <xsl:call-template name="cosine">
          <xsl:with-param name="deg"><xsl:value-of select="$hr  * 360"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="sinhr">
          <xsl:call-template name="sine">
          <xsl:with-param name="deg"><xsl:value-of select="$hr  * 360"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="minx"><xsl:value-of select="$x + 0.88 * $sinmin * $rad"/></xsl:variable>
          <xsl:variable name="miny"><xsl:value-of select="$y + 0.88 * $cosmin * $rad"/></xsl:variable>
          <xsl:variable name="hrx"><xsl:value-of select="$x + 0.6 * $sinhr * $rad"/></xsl:variable>
          <xsl:variable name="hry"><xsl:value-of select="$y + 0.6 * $coshr * $rad"/></xsl:variable>

          <setcv X1="{$x + $rad}"       Y1="{$y}"                X2="{$x + $rad*0.985}" Y2="{$y + $rad*0.174}" />
          <expar X1="{$x + $rad*0.94}"  Y1="{$y + $rad*0.342}"   X2="{$x + $rad*0.866}" Y2="{$y + $rad*0.5}" />
          <expar X1="{$x + $rad*0.766}" Y1="{$y + $rad*0.643}"   X2="{$x + $rad*0.643}" Y2="{$y + $rad*0.766}" />
          <expar X1="{$x + $rad*0.5}"   Y1="{$y + $rad*0.866}"   X2="{$x + $rad*0.342}" Y2="{$y + $rad*0.94}" />
          <expar X1="{$x + $rad*0.174}" Y1="{$y + $rad*0.985}"   X2="{$x + $rad*0}"     Y2="{$y + $rad*1}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y + $rad*0.985}"   X2="{$x - $rad*0.342}" Y2="{$y + $rad*0.94}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y + $rad*0.866}"   X2="{$x - $rad*0.643}" Y2="{$y + $rad*0.766}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y + $rad*0.643}"   X2="{$x - $rad*0.866}" Y2="{$y + $rad*0.5}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y + $rad*0.342}"   X2="{$x - $rad*0.985}" Y2="{$y + $rad*0.174}" />
          <expar X1="{$x - $rad*1}"     Y1="{$y + $rad*0}"       X2="{$x - $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y - $rad*0.342}"   X2="{$x - $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y - $rad*0.643}"   X2="{$x - $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y - $rad*0.866}"   X2="{$x - $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y - $rad*0.985}"   X2="{$x + $rad*0}"     Y2="{$y - $rad*1}" />
          <expar X1="{$x + $rad*0.174}" Y1="{$y - $rad*0.985}"   X2="{$x + $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x + $rad*0.5}"   Y1="{$y - $rad*0.866}"   X2="{$x + $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x + $rad*0.766}" Y1="{$y - $rad*0.643}"   X2="{$x + $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x + $rad*0.94}"  Y1="{$y - $rad*0.342}"   X2="{$x + $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x + $rad*1}"     Y1="{$y - $rad*0}"       X2="{$x + $rad*1}"     Y2="{$y - $rad*0}" />
          
          <xsl:variable name="mindx"><xsl:value-of select="$minx - $x"/></xsl:variable>
          <xsl:variable name="mindy"><xsl:value-of select="$miny - $y"/></xsl:variable>
          <xsl:variable name="minlength">
          <xsl:call-template name="sqrt">
          <xsl:with-param name="n"><xsl:value-of select="$mindx * $mindx + $mindy * $mindy"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="minadx"><xsl:value-of select="($mindx div $minlength) * $head"/></xsl:variable>
          <xsl:variable name="minady"><xsl:value-of select="($mindy div $minlength) * $head"/></xsl:variable>
          <xsl:variable name="minx3"><xsl:value-of select="$minx - $minadx - $minady"/></xsl:variable>
          <xsl:variable name="miny3"><xsl:value-of select="$miny + $minadx - $minady"/></xsl:variable>
          <xsl:variable name="minx4"><xsl:value-of select="$minx - $minadx + $minady"/></xsl:variable>
          <xsl:variable name="miny4"><xsl:value-of select="$miny - $minadx - $minady"/></xsl:variable>
          <setln X1="{$x}" Y1="{$y}" X2="{$minx}" Y2="{$miny}" />
          <setcv X1="{$minx3}" Y1="{$miny3}" X2="{$minx}" Y2="{$miny}" />
          <expar X1="{$minx4}" Y1="{$miny4}" X2="{$minx3}" Y2="{$miny3}" />

          <xsl:variable name="hrdx"><xsl:value-of select="0.7 * ($hrx - $x)"/></xsl:variable>
          <xsl:variable name="hrdy"><xsl:value-of select="0.7 * ($hry - $y)"/></xsl:variable>
          <xsl:variable name="hrlength">
          <xsl:call-template name="sqrt">
          <xsl:with-param name="n"><xsl:value-of select="$hrdx * $hrdx + $hrdy * $hrdy"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="hradx"><xsl:value-of select="($hrdx div $hrlength) * $head"/></xsl:variable>
          <xsl:variable name="hrady"><xsl:value-of select="($hrdy div $hrlength) * $head"/></xsl:variable>
          <xsl:variable name="hrx3"><xsl:value-of select="$hrx - $hradx - $hrady"/></xsl:variable>
          <xsl:variable name="hry3"><xsl:value-of select="$hry + $hradx - $hrady"/></xsl:variable>
          <xsl:variable name="hrx4"><xsl:value-of select="$hrx - $hradx + $hrady"/></xsl:variable>
          <xsl:variable name="hry4"><xsl:value-of select="$hry - $hradx - $hrady"/></xsl:variable>
          <setln X1="{$x}" Y1="{$y}" X2="{$hrx}" Y2="{$hry}" />
          <setcv X1="{$hrx3}" Y1="{$hry3}" X2="{$hrx}" Y2="{$hry}" />
          <expar X1="{$hrx4}" Y1="{$hry4}" X2="{$hrx4}" Y2="{$hry4}" />

          <setln X1="{$x + 0.9 * $rad}"         Y1="{$y}"                      X2="{$x + 1.1 * $rad}"         Y2="{$y}" />
          <setln X1="{$x + 0.9 * $rad * 0.866}" Y1="{$y + 0.9 * $rad * 0.5}"   X2="{$x + 1.1 * $rad * 0.866}" Y2="{$y + 1.1 * $rad * 0.5}" />
          <setln X1="{$x + 0.9 * $rad * 0.5}"   Y1="{$y + 0.9 * $rad * 0.866}" X2="{$x + 1.1 * $rad * 0.5}"   Y2="{$y + 1.1 * $rad * 0.866}" />
          <setln X1="{$x + 0.9 * $rad * 0.0}"   Y1="{$y + 0.9 * $rad * 1.0}"   X2="{$x + 1.1 * $rad * 0.0}"   Y2="{$y + 1.1 * $rad * 1.0}" />
          <setln X1="{$x - 0.9 * $rad * 0.5}"   Y1="{$y + 0.9 * $rad * 0.866}" X2="{$x - 1.1 * $rad * 0.5}"   Y2="{$y + 1.1 * $rad * 0.866}" />
          <setln X1="{$x - 0.9 * $rad * 0.866}" Y1="{$y + 0.9 * $rad * 0.5}"   X2="{$x - 1.1 * $rad * 0.866}" Y2="{$y + 1.1 * $rad * 0.5}" />
          <setln X1="{$x - 0.9 * $rad * 1.0}"   Y1="{$y + 0.9 * $rad * 0.0}"   X2="{$x - 1.1 * $rad * 1.0}"   Y2="{$y + 1.1 * $rad * 0.0}" />
          <setln X1="{$x - 0.9 * $rad * 0.866}" Y1="{$y - 0.9 * $rad * 0.5}"   X2="{$x - 1.1 * $rad * 0.866}" Y2="{$y - 1.1 * $rad * 0.5}" />
          <setln X1="{$x - 0.9 * $rad * 0.5}"   Y1="{$y - 0.9 * $rad * 0.866}" X2="{$x - 1.1 * $rad * 0.5}"   Y2="{$y - 1.1 * $rad * 0.866}" />
          <setln X1="{$x + 0.9 * $rad * 0.0}"   Y1="{$y - 0.9 * $rad * 1.0}"   X2="{$x + 1.1 * $rad * 0.0}"   Y2="{$y - 1.1 * $rad * 1.0}" />
          <setln X1="{$x + 0.9 * $rad * 0.5}"   Y1="{$y - 0.9 * $rad * 0.866}" X2="{$x + 1.1 * $rad * 0.5}"   Y2="{$y - 1.1 * $rad * 0.866}" />
          <setln X1="{$x + 0.9 * $rad * 0.866}" Y1="{$y - 0.9 * $rad * 0.5}"   X2="{$x + 1.1 * $rad * 0.866}" Y2="{$y - 1.1 * $rad * 0.5}" />
          </xsl:when>
          
          
          <xsl:when test="$name = 'SINWV'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="amp"><xsl:value-of select="$cmnds[1]/@AMP"/></xsl:variable>
          <xsl:variable name="deg"><xsl:value-of select="$cmnds[1]/@DEG"/></xsl:variable>
          <xsl:variable name="dlngth"><xsl:value-of select="$cmnds[1]/@LNGTH div 36"/></xsl:variable>
          <xsl:variable name="s2"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="1 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s3"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="2 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s4"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="3 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s5"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="4 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s6"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="5 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s7"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="6 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s8"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="7 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s9"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="8 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s10"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="9 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s11"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="10 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s12"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="11 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s13"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="12 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s14"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="13 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s15"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="14 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s16"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="15 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s17"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="16 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s18"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="17 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s19"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="18 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s20"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="19 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s21"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="20 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s22"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="21 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s23"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="22 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s24"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="23 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s25"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="24 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s26"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="25 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s27"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="26 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s28"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="27 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s29"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="28 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s30"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="29 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s31"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="30 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s32"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="31 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s33"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="32 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s34"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="33 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s35"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="34 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s36"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="35 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>
          <xsl:variable name="s37"><xsl:call-template name="sine"><xsl:with-param name="deg"><xsl:value-of select="36 * ($deg div 36)"/></xsl:with-param></xsl:call-template></xsl:variable>

          <setcv X1="{$x}" Y1="{$y}" X2="{$x + 1 * $dlngth}" Y2="{$y + $amp * $s2}" />
          <expar X1="{$x +  2 * $dlngth}" Y1="{$y + $amp * $s3}"  X2="{$x + 3 * $dlngth}"  Y2="{$y + $amp * $s4}" />
          <expar X1="{$x +  4 * $dlngth}" Y1="{$y + $amp * $s5}"  X2="{$x + 5 * $dlngth}"  Y2="{$y + $amp * $s6}" />
          <expar X1="{$x +  6 * $dlngth}" Y1="{$y + $amp * $s7}"  X2="{$x + 7 * $dlngth}"  Y2="{$y + $amp * $s8}" />
          <expar X1="{$x +  8 * $dlngth}" Y1="{$y + $amp * $s9}"  X2="{$x + 9 * $dlngth}"  Y2="{$y + $amp * $s10}" />
          <expar X1="{$x + 10 * $dlngth}" Y1="{$y + $amp * $s11}" X2="{$x + 11 * $dlngth}" Y2="{$y + $amp * $s12}" />
          <expar X1="{$x + 12 * $dlngth}" Y1="{$y + $amp * $s13}" X2="{$x + 13 * $dlngth}" Y2="{$y + $amp * $s14}" />
          <expar X1="{$x + 14 * $dlngth}" Y1="{$y + $amp * $s15}" X2="{$x + 15 * $dlngth}" Y2="{$y + $amp * $s16}" />
          <expar X1="{$x + 16 * $dlngth}" Y1="{$y + $amp * $s17}" X2="{$x + 17 * $dlngth}" Y2="{$y + $amp * $s18}" />
          <expar X1="{$x + 18 * $dlngth}" Y1="{$y + $amp * $s19}" X2="{$x + 19 * $dlngth}" Y2="{$y + $amp * $s20}" />
          <expar X1="{$x + 20 * $dlngth}" Y1="{$y + $amp * $s21}" X2="{$x + 21 * $dlngth}" Y2="{$y + $amp * $s22}" />
          <expar X1="{$x + 22 * $dlngth}" Y1="{$y + $amp * $s23}" X2="{$x + 23 * $dlngth}" Y2="{$y + $amp * $s24}" />
          <expar X1="{$x + 24 * $dlngth}" Y1="{$y + $amp * $s25}" X2="{$x + 25 * $dlngth}" Y2="{$y + $amp * $s26}" />
          <expar X1="{$x + 26 * $dlngth}" Y1="{$y + $amp * $s27}" X2="{$x + 27 * $dlngth}" Y2="{$y + $amp * $s28}" />
          <expar X1="{$x + 28 * $dlngth}" Y1="{$y + $amp * $s29}" X2="{$x + 29 * $dlngth}" Y2="{$y + $amp * $s30}" />
          <expar X1="{$x + 30 * $dlngth}" Y1="{$y + $amp * $s31}" X2="{$x + 31 * $dlngth}" Y2="{$y + $amp * $s32}" />
          <expar X1="{$x + 32 * $dlngth}" Y1="{$y + $amp * $s33}" X2="{$x + 33 * $dlngth}" Y2="{$y + $amp * $s34}" />
          <expar X1="{$x + 34 * $dlngth}" Y1="{$y + $amp * $s35}" X2="{$x + 35 * $dlngth}" Y2="{$y + $amp * $s36}" />
          <expar X1="{$x + 36 * $dlngth}" Y1="{$y + $amp * $s37}" X2="{$x + 36 * $dlngth}" Y2="{$y + $amp * $s37}" />
          </xsl:when>

          <xsl:when test="$name = 'TRANS'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="p"><xsl:value-of select="$cmnds[1]/@P"/></xsl:variable>
          <xsl:variable name="dist"><xsl:value-of select="$cmnds[1]/@DIST"/></xsl:variable>
          <xsl:variable name="r"><xsl:value-of select="$dist div (2 * 0.7986)"/></xsl:variable>
          <xsl:variable name="cx"><xsl:value-of select="$x + ($dist div 2) "/></xsl:variable>
          <xsl:variable name="cy"><xsl:value-of select="$y - 0.6018 * $r"/></xsl:variable>
          <xsl:variable name="bx"><xsl:value-of select="$cx"/></xsl:variable>
          <xsl:variable name="by"><xsl:value-of select="$cy - $r"/></xsl:variable>
          <xsl:variable name="px"><xsl:value-of select="$cx"/></xsl:variable>
          <xsl:variable name="py"><xsl:value-of select="$cy - $r * 0.5"/></xsl:variable>
          <xsl:variable name="lpx"><xsl:value-of select="$px - 0.5 * $r"/></xsl:variable>
          <xsl:variable name="lpy"><xsl:value-of select="$py"/></xsl:variable>
          <xsl:variable name="rpx"><xsl:value-of select="$px + 0.5 * $r"/></xsl:variable>
          <xsl:variable name="rpy"><xsl:value-of select="$py"/></xsl:variable>
          <xsl:variable name="larx"><xsl:value-of select="$cx - 0.2 * $r"/></xsl:variable>
          <xsl:variable name="rarx"><xsl:value-of select="$cx + 0.2 * $r"/></xsl:variable>
          <xsl:variable name="rx"><xsl:value-of select="$x + $dist"/></xsl:variable>
          <xsl:variable name="ry"><xsl:value-of select="$y"/></xsl:variable>


          <xsl:variable name="head"><xsl:value-of select="$r * 0.35"/></xsl:variable>
          <xsl:variable name="dx"><xsl:value-of select="$larx - $x"/></xsl:variable>
          <xsl:variable name="dy"><xsl:value-of select="$py - $y"/></xsl:variable>
          <xsl:variable name="length">
          <xsl:call-template name="sqrt">
          <xsl:with-param name="n"><xsl:value-of select="$dx * $dx + $dy * $dy"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="adx"><xsl:value-of select="($dx div $length) * $head"/></xsl:variable>
          <xsl:variable name="ady"><xsl:value-of select="($dy div $length) * $head"/></xsl:variable>

<xsl:choose>
<xsl:when test="$p = 0">
          <xsl:variable name="x3"><xsl:value-of select="$larx - $adx - $ady"/></xsl:variable>
          <xsl:variable name="y3"><xsl:value-of select="$py + $adx - $ady"/></xsl:variable>
          <xsl:variable name="x4"><xsl:value-of select="$larx - $adx + $ady"/></xsl:variable>
          <xsl:variable name="y4"><xsl:value-of select="$py - $adx - $ady"/></xsl:variable>

          
          <setln X1="{$x}" Y1="{$y}"   X2="{$larx}" Y2="{$py}" />
          <setcv X1="{$x3}" Y1="{$y3}"   X2="{$larx}" Y2="{$py}" />
          <expar X1="{$x4}" Y1="{$y4}"   X2="{$x3}" Y2="{$y3}" />
          <setln X1="{$rx}" Y1="{$ry}"   X2="{$rarx}" Y2="{$py}" />

          
</xsl:when>
<xsl:when test="$p = 1">
          <xsl:variable name="x3"><xsl:value-of select="$rarx + $adx - $ady"/></xsl:variable>
          <xsl:variable name="y3"><xsl:value-of select="$py - $adx - $ady"/></xsl:variable>
          <xsl:variable name="x4"><xsl:value-of select="$rarx + $adx + $ady"/></xsl:variable>
          <xsl:variable name="y4"><xsl:value-of select="$py + $adx - $ady"/></xsl:variable>
          <setln X1="{$x}" Y1="{$y}"   X2="{$larx}" Y2="{$py}" />
          <setln X1="{$rx}" Y1="{$ry}"   X2="{$rarx}" Y2="{$py}" />
          <setcv X1="{$x3}" Y1="{$y3}"   X2="{$rarx}" Y2="{$py}" />
          <expar X1="{$x4}" Y1="{$y4}"   X2="{$x3}" Y2="{$y3}" />
</xsl:when>

<xsl:when test="$p = 2">
          <xsl:variable name="x3"><xsl:value-of select="$x + $adx + $ady"/></xsl:variable>
          <xsl:variable name="y3"><xsl:value-of select="$y - $adx + $ady"/></xsl:variable>
          <xsl:variable name="x4"><xsl:value-of select="$x + $adx - $ady"/></xsl:variable>
          <xsl:variable name="y4"><xsl:value-of select="$y + $adx + $ady"/></xsl:variable>

          <setln X1="{$larx}" Y1="{$py}" X2="{$x}" Y2="{$y}" />
          <setln X1="{$rx}" Y1="{$ry}"   X2="{$rarx}" Y2="{$py}" />
          <setcv X1="{$x3}" Y1="{$y3}"   X2="{$x}" Y2="{$y}" />
          <expar X1="{$x4}" Y1="{$y4}"   X2="{$x3}" Y2="{$y3}" />

</xsl:when>

<xsl:when test="$p = 3">
          <xsl:variable name="x3"><xsl:value-of select="$rx - $adx + $ady"/></xsl:variable>
          <xsl:variable name="y3"><xsl:value-of select="$ry + $adx + $ady"/></xsl:variable>
          <xsl:variable name="x4"><xsl:value-of select="$rx - $adx - $ady"/></xsl:variable>
          <xsl:variable name="y4"><xsl:value-of select="$ry - $adx + $ady"/></xsl:variable>

          <setln X1="{$x}" Y1="{$y}"   X2="{$larx}" Y2="{$py}" />
          <setln X1="{$rarx}" Y1="{$py}" X2="{$rx}" Y2="{$ry}" />
          <setcv X1="{$x3}" Y1="{$y3}"   X2="{$rx}" Y2="{$ry}" />
          <expar X1="{$x4}" Y1="{$y4}"   X2="{$x3}" Y2="{$y3}" />

</xsl:when>
</xsl:choose>

          <setln X1="{$rpx}" Y1="{$rpy}"  X2="{$lpx}"  Y2="{$lpy}" />
          <expar X1="{$px}" Y1="{$py}"  X2="{$bx}"  Y2="{$by}" />

          <setcv X1="{$cx + $r}"        Y1="{$cy}"             X2="{$cx + $r*0.985}" Y2="{$cy + $r*0.174}" />
          <expar X1="{$cx + $r*0.94}"   Y1="{$cy + $r*0.342}"  X2="{$cx + $r*0.866}" Y2="{$cy + $r*0.5}" />
          <expar X1="{$cx + $r*0.766}"  Y1="{$cy + $r*0.643}"  X2="{$cx + $r*0.643}" Y2="{$cy + $r*0.766}" />
          <expar X1="{$cx + $r*0.5}"    Y1="{$cy + $r*0.866}"  X2="{$cx + $r*0.342}" Y2="{$cy + $r*0.94}" />
          <expar X1="{$cx + $r*0.174}"  Y1="{$cy + $r*0.985}"  X2="{$cx + $r*0}"     Y2="{$cy + $r*1}" />
          <expar X1="{$cx - $r*0.174}" Y1="{$cy + $r*0.985}"   X2="{$cx - $r*0.342}" Y2="{$cy + $r*0.94}" />
          <expar X1="{$cx - $r*0.5}"   Y1="{$cy + $r*0.866}"   X2="{$cx - $r*0.643}" Y2="{$cy + $r*0.766}" />
          <expar X1="{$cx - $r*0.766}" Y1="{$cy + $r*0.643}"   X2="{$cx - $r*0.866}" Y2="{$cy + $r*0.5}" />
          <expar X1="{$cx - $r*0.94}"  Y1="{$cy + $r*0.342}"   X2="{$cx - $r*0.985}" Y2="{$cy + $r*0.174}" />
          <expar X1="{$cx - $r*1}"     Y1="{$cy + $r*0}"       X2="{$cx - $r*0.985}" Y2="{$cy - $r*0.174}" />
          <expar X1="{$cx - $r*0.94}"  Y1="{$cy - $r*0.342}"   X2="{$cx - $r*0.866}" Y2="{$cy - $r*0.5}" />
          <expar X1="{$cx - $r*0.766}" Y1="{$cy - $r*0.643}"   X2="{$cx - $r*0.643}" Y2="{$cy - $r*0.766}" />
          <expar X1="{$cx - $r*0.5}"   Y1="{$cy - $r*0.866}"   X2="{$cx - $r*0.342}" Y2="{$cy - $r*0.94}" />
          <expar X1="{$cx - $r*0.174}" Y1="{$cy - $r*0.985}"   X2="{$cx + $r*0}"     Y2="{$cy - $r*1}" />
          <expar X1="{$cx  +  $r*0.174}"  Y1="{$cy - $r*0.985}"  X2="{$cx + $r*0.342}" Y2="{$cy - $r*0.94}" />
          <expar X1="{$cx + $r*0.5}"    Y1="{$cy - $r*0.866}"  X2="{$cx + $r*0.643}" Y2="{$cy - $r*0.766}" />
          <expar X1="{$cx  +  $r*0.766}"  Y1="{$cy - $r*0.643}"  X2="{$cx + $r*0.866}" Y2="{$cy - $r*0.5}" />
          <expar X1="{$cx + $r*0.94}"   Y1="{$cy - $r*0.342}"  X2="{$cx + $r*0.985}" Y2="{$cy - $r*0.174}" />
          <expar X1="{$cx + $r*1}"      Y1="{$cy - $r*0}"      X2="{$cx + $r*1}"     Y2="{$cy - $r*0}" />
          </xsl:when>
          
          
          <xsl:when test="$name = 'CAP'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="dist"><xsl:value-of select="$cmnds[1]/@DIST"/></xsl:variable>
          <xsl:variable name="lngth"><xsl:value-of select="$cmnds[1]/@DIST * 2"/></xsl:variable>
          <setln X1="{$x}"             Y1="{$y + $dist * 2}"    X2="{$x}" Y2="{$y - $dist * 2}" />
          
          <setcv X1="{$x + $dist * 2}" Y1="{$y + $dist * 2}"    X2="{$x + $dist * 1.7}" Y2="{$y + $dist * 1.6}" />
          <expar X1="{$x + $dist * 1.45}" Y1="{$y + $dist * 1.2}"  X2="{$x + $dist * 1.25}" Y2="{$y + $dist * 0.8}" />
          <expar X1="{$x + $dist * 1.1}" Y1="{$y + $dist * 0.4}"  X2="{$x + $dist * 1.0}" Y2="{$y + $dist * 0}" />
          <expar X1="{$x + $dist * 1.1}" Y1="{$y - $dist * 0.4}"  X2="{$x + $dist * 1.25}" Y2="{$y - $dist * 0.8}" />
          <expar X1="{$x + $dist * 1.45}" Y1="{$y - $dist * 1.2}"  X2="{$x + $dist * 1.7}" Y2="{$y - $dist * 1.6}" />
          <expar X1="{$x + $dist * 2}" Y1="{$y - $dist * 2}"    X2="{$x + $dist * 2}" Y2="{$y - $dist * 2}" />
          </xsl:when>

          <xsl:when test="$name = 'RESIS'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="lngth"><xsl:value-of select="$cmnds[1]/@LNGTH"/></xsl:variable>
          <xsl:variable name="hght"><xsl:value-of select="$lngth * 0.2"/></xsl:variable>
          <xsl:variable name="inc"><xsl:value-of select="$lngth div 12"/></xsl:variable>
          <setcv X1="{$x}"            Y1="{$y}"          X2="{$x + $inc}"     Y2="{$y + $hght}" />
          <expar X1="{$x + 3 * $inc}" Y1="{$y - $hght}"  X2="{$x + 5 * $inc}" Y2="{$y + $hght}" />
          <expar X1="{$x + 7 * $inc}" Y1="{$y - $hght}"  X2="{$x + 9 * $inc}" Y2="{$y + $hght}" />
          <expar X1="{$x + 11 * $inc}" Y1="{$y - $hght}"  X2="{$x + 12 * $inc}" Y2="{$y}" />
          </xsl:when>

          <xsl:when test="$name = 'GRND'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="dist"><xsl:value-of select="$cmnds[1]/@DIST"/></xsl:variable>
          <xsl:variable name="dist2"><xsl:value-of select="$dist div 2"/></xsl:variable>
          <xsl:variable name="dist4"><xsl:value-of select="$dist div 4"/></xsl:variable>
          <xsl:variable name="dist8"><xsl:value-of select="$dist div 8"/></xsl:variable>
          <setln X1="{$x}"            Y1="{$y}"          X2="{$x}"     Y2="{$y - $dist2}" />
          <expar X1="{$x - $dist2}" Y1="{$y - $dist2}"  X2="{$x + $dist2}" Y2="{$y - $dist2}" />
          <expar X1="{$x - $dist4}" Y1="{$y - $dist2 - $dist4}"  X2="{$x +  $dist4}" Y2="{$y - $dist2 - $dist4}" />
          <expar X1="{$x - $dist8}" Y1="{$y - $dist}"  X2="{$x + $dist8}" Y2="{$y - $dist}" />
          </xsl:when>


          <xsl:when test="$name = 'METER'">
          <xsl:variable name="x"><xsl:value-of select="$cmnds[1]/@X"/></xsl:variable>
          <xsl:variable name="y"><xsl:value-of select="$cmnds[1]/@Y"/></xsl:variable>
          <xsl:variable name="rad"><xsl:value-of select="$cmnds[1]/@RAD"/></xsl:variable>
          <xsl:variable name="pict"><xsl:value-of select="$cmnds[1]/@PICT"/></xsl:variable>
          <xsl:variable name="rad2"><xsl:value-of select="$rad * 0.8"/></xsl:variable>
          <xsl:variable name="head"><xsl:value-of select="$rad * 0.2"/></xsl:variable>
          <xsl:variable name="inc"><xsl:value-of select="$rad * 0.2"/></xsl:variable>

          <setcv X1="{$x + $rad2}"        Y1="{$y}"             X2="{$x + $rad2*0.985}" Y2="{$y + $rad2*0.174}" />
          <expar X1="{$x + $rad2*0.94}"   Y1="{$y + $rad2*0.342}"  X2="{$x + $rad2*0.866}" Y2="{$y + $rad2*0.5}" />
          <expar X1="{$x + $rad2*0.766}"  Y1="{$y + $rad2*0.643}"  X2="{$x + $rad2*0.643}" Y2="{$y + $rad2*0.766}" />
          <expar X1="{$x + $rad2*0.5}"    Y1="{$y + $rad2*0.866}"  X2="{$x + $rad2*0.342}" Y2="{$y + $rad2*0.94}" />
          <expar X1="{$x + $rad2*0.174}"  Y1="{$y + $rad2*0.985}"  X2="{$x + $rad2*0}"     Y2="{$y + $rad2*1}" />
          <expar X1="{$x - $rad2*0.174}" Y1="{$y + $rad2*0.985}"   X2="{$x - $rad2*0.342}" Y2="{$y + $rad2*0.94}" />
          <expar X1="{$x - $rad2*0.5}"   Y1="{$y + $rad2*0.866}"   X2="{$x - $rad2*0.643}" Y2="{$y + $rad2*0.766}" />
          <expar X1="{$x - $rad2*0.766}" Y1="{$y + $rad2*0.643}"   X2="{$x - $rad2*0.866}" Y2="{$y + $rad2*0.5}" />
          <expar X1="{$x - $rad2*0.94}"  Y1="{$y + $rad2*0.342}"   X2="{$x - $rad2*0.985}" Y2="{$y + $rad2*0.174}" />
          <expar X1="{$x - $rad2*1}"     Y1="{$y + $rad2*0}"       X2="{$x - $rad2*1}" Y2="{$y + $rad2*0}" />


          <setcv X1="{$x + $rad}"        Y1="{$y}"             X2="{$x + $rad*0.985}" Y2="{$y + $rad*0.174}" />
          <expar X1="{$x + $rad*0.94}"   Y1="{$y + $rad*0.342}"  X2="{$x + $rad*0.866}" Y2="{$y + $rad*0.5}" />
          <expar X1="{$x + $rad*0.766}"  Y1="{$y + $rad*0.643}"  X2="{$x + $rad*0.643}" Y2="{$y + $rad*0.766}" />
          <expar X1="{$x + $rad*0.5}"    Y1="{$y + $rad*0.866}"  X2="{$x + $rad*0.342}" Y2="{$y + $rad*0.94}" />
          <expar X1="{$x + $rad*0.174}"  Y1="{$y + $rad*0.985}"  X2="{$x + $rad*0}"     Y2="{$y + $rad*1}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y + $rad*0.985}"   X2="{$x - $rad*0.342}" Y2="{$y + $rad*0.94}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y + $rad*0.866}"   X2="{$x - $rad*0.643}" Y2="{$y + $rad*0.766}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y + $rad*0.643}"   X2="{$x - $rad*0.866}" Y2="{$y + $rad*0.5}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y + $rad*0.342}"   X2="{$x - $rad*0.985}" Y2="{$y + $rad*0.174}" />
          <expar X1="{$x - $rad*1}"     Y1="{$y + $rad*0}"       X2="{$x - $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x - $rad*0.94}"  Y1="{$y - $rad*0.342}"   X2="{$x - $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x - $rad*0.766}" Y1="{$y - $rad*0.643}"   X2="{$x - $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x - $rad*0.5}"   Y1="{$y - $rad*0.866}"   X2="{$x - $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x - $rad*0.174}" Y1="{$y - $rad*0.985}"   X2="{$x + $rad*0}"     Y2="{$y - $rad*1}" />
          <expar X1="{$x  +  $rad*0.174}"  Y1="{$y - $rad*0.985}"  X2="{$x + $rad*0.342}" Y2="{$y - $rad*0.94}" />
          <expar X1="{$x + $rad*0.5}"    Y1="{$y - $rad*0.866}"  X2="{$x + $rad*0.643}" Y2="{$y - $rad*0.766}" />
          <expar X1="{$x  +  $rad*0.766}"  Y1="{$y - $rad*0.643}"  X2="{$x + $rad*0.866}" Y2="{$y - $rad*0.5}" />
          <expar X1="{$x + $rad*0.94}"   Y1="{$y - $rad*0.342}"  X2="{$x + $rad*0.985}" Y2="{$y - $rad*0.174}" />
          <expar X1="{$x + $rad*1}"      Y1="{$y - $rad*0}"      X2="{$x + $rad*1}"     Y2="{$y - $rad*0}" />

          <xsl:variable name="x1"><xsl:value-of select="$x"/></xsl:variable>
          <xsl:variable name="y1"><xsl:value-of select="$y"/></xsl:variable>
          <xsl:variable name="sin">
          <xsl:call-template name="sine">
          <xsl:with-param name="deg"><xsl:value-of select="180 * $pict"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="cos">
          <xsl:call-template name="cosine">
          <xsl:with-param name="deg"><xsl:value-of select="180 * $pict"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>

          <xsl:variable name="x2"><xsl:value-of select="$x1 + $cos * $rad2"/></xsl:variable>
          <xsl:variable name="y2"><xsl:value-of select="$y1 + $sin * $rad2"/></xsl:variable>
          <xsl:variable name="dx"><xsl:value-of select="$x2 - $x1"/></xsl:variable>
          <xsl:variable name="dy"><xsl:value-of select="$y2 - $y1"/></xsl:variable>
          <xsl:variable name="length">
          <xsl:call-template name="sqrt">
          <xsl:with-param name="n"><xsl:value-of select="$dx * $dx + $dy * $dy"/></xsl:with-param>
          </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="adx"><xsl:value-of select="($dx div $length) * $head"/></xsl:variable>
          <xsl:variable name="ady"><xsl:value-of select="($dy div $length) * $head"/></xsl:variable>
          <xsl:variable name="x3"><xsl:value-of select="$x2 - $adx - $ady"/></xsl:variable>
          <xsl:variable name="y3"><xsl:value-of select="$y2 + $adx - $ady"/></xsl:variable>
          <xsl:variable name="x4"><xsl:value-of select="$x2 - $adx + $ady"/></xsl:variable>
          <xsl:variable name="y4"><xsl:value-of select="$y2 - $adx - $ady"/></xsl:variable>
          <setln X1="{$x1}" Y1="{$y1}" X2="{$x2}" Y2="{$y2}" />
          <setcv X1="{$x3}" Y1="{$y3}" X2="{$x2}" Y2="{$y2}" />
          <expar X1="{$x4}" Y1="{$y4}" X2="{$x3}" Y2="{$y3}" />

          <setcv X1="{$x -  $inc}" Y1="{$y - $inc}" X2="{$x +  $inc}" Y2="{$y - $inc}" />
          <expar X1="{$x}" Y1="{$y + $inc}" X2="{$x - $inc}" Y2="{$y - $inc}" />

          <setcv X1="{$x -  $rad2}" Y1="{$y}" X2="{$x - $rad2}" Y2="{$y - $inc}" />
          <expar X1="{$x + $rad2}" Y1="{$y - $inc}" X2="{$x + $rad2}" Y2="{$y}" />

          <setln X1="{$x + 0.707 * ($rad2 - $inc)}" Y1="{$y + 0.707 * ($rad2 - $inc)}" X2="{$x + 0.707 * $rad2}" Y2="{$y + 0.707 * $rad2}" />
          <setln X1="{$x}" Y1="{$y + ($rad2 - $inc)}" X2="{$x}" Y2="{$y + $rad2}" />
          <setln X1="{$x - 0.707 * ($rad2 - $inc)}" Y1="{$y + 0.707 * ($rad2 - $inc)}" X2="{$x - 0.707 * $rad2}" Y2="{$y + 0.707 * $rad2}" />


          </xsl:when>


          
          </xsl:choose>
          </array>
          </stack>
          </xsl:for-each>
          
          
          
        </stacks>
        </xsl:variable>          
        <xsl:call-template name="create_arrays">
          <xsl:with-param name="cmnds" select="$cmnds[position() != 1]"/>
          <xsl:with-param name="stacks" select="$newstacks"/>
          <xsl:with-param name="restofcmnds" select="$restofcmnds"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </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>



<!-- ******************************************************** -->
<!-- ********************* 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>

<xsl:template name="drawygrid">
<xsl:param name="xval"/>
<xsl:param name="incx"/>



<xsl:choose>
<xsl:when test="$xval > (12.0 - 0.5 * $incx)"></xsl:when>
<xsl:otherwise>
<setln X1="{$xval}" Y1="0" X2="{$xval}" Y2="9.0" />
<xsl:call-template name="drawygrid">
<xsl:with-param name="xval"><xsl:value-of select="$xval + $incx"/></xsl:with-param>
<xsl:with-param name="incx"><xsl:value-of select="$incx"/></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="drawxgrid">
<xsl:param name="yval"/>
<xsl:param name="incy"/>
<xsl:choose>
<xsl:when test="$yval > 9.0 - 0.5 * $incy"></xsl:when>
<xsl:otherwise>
<setln X1="0" Y1="{$yval}" X2="12.0" Y2="{$yval}" />
<xsl:call-template name="drawxgrid">
<xsl:with-param name="yval"><xsl:value-of select="$yval + $incy"/></xsl:with-param>
<xsl:with-param name="incy"><xsl:value-of select="$incy"/></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="split">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="string-length($string) = 0"></xsl:when>
<xsl:otherwise>
<ch><xsl:value-of select="substring($string,1,1)"/></ch>
<xsl:call-template name="split">
<xsl:with-param name="string"><xsl:value-of select="substring($string,2)"/></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>

</xsl:template>

</xsl:stylesheet>