<?xml version="1.0"?> 
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:script = "http://topxml.com/forum/script"
>

<!-- document level  -->
    <xsl:template match="/">
      <html>
        <head>
          <title> ney fingerings </title>
          <style>
           <xsl:comment>
            .verticaltext { writing-mode: tb-rl; filter: flipv fliph; width:18 ; text-align:left}
           </xsl:comment>
          </style> 
        </head>
        <body><xsl:attribute name="BGCOLOR">white</xsl:attribute>

       <TABLE CELLPADDING="3" CELLSPACING="20" border="1"> 
          <xsl:attribute name="BGCOLOR">#FCFCFC</xsl:attribute>
          <xsl:apply-templates select="neyfings"/>
       </TABLE>

        </body>
      </html>
    </xsl:template>

<!-- table level for each ney (big row) and for each scale (big cell) -->
    <xsl:template match="neyfings">
      <xsl:for-each select="ney">
       <xsl:variable name="ntype"><xsl:value-of select="neytype"/></xsl:variable>
       <TR>
         <TD ALIGN="CENTER">
           <xsl:attribute name="COLSPAN"><xsl:value-of select="count(../scale)"/></xsl:attribute>
         <H1> <br/>Fingerings on <xsl:value-of select="$ntype"/> ney</H1>
         </TD>
       </TR>
       <TR>
       <xsl:for-each select="../scale">
         <TD VALIGN="TOP">
         <TABLE CELLPADDING="0" CELLSPACING="0" border="0"> 
           <xsl:attribute name="BGCOLOR">#FCFCFC</xsl:attribute>
            <TR>
              <TD COLSPAN="5" ALIGN="CENTER"><br/>
                 <h2> <xsl:value-of select="scalename"/> scale notes </h2>
              </TD>
            </TR>
            <!-- columns titles  -->
            <TR><TH colspan="2">                             Wind
              </TH><TH rowspan="2" valign="bottom">          Fingering
              </TH><TH rowspan="2" class="verticaltext">     Frequency
              </TH><TH rowspan="2" valign="bottom">          Note
              </TH></TR>
              <TR><TH class="verticaltext">               Angle
              </TH><TH class="verticaltext">              Intensity
              </TH></TR>
              <xsl:call-template name="fingerings">
                <xsl:with-param name="nytype"><xsl:value-of select="$ntype"/></xsl:with-param>
              </xsl:call-template>
         </TABLE>
         </TD>
       </xsl:for-each>
       </TR>
      </xsl:for-each>
    </xsl:template>

<!-- rows of the scale table  -->
    <xsl:template name="fingerings">
    <xsl:param name="nytype"/>
       <xsl:for-each select="f">
        <xsl:sort select="nr" order="ascending"/>
          <TR>
           <xsl:attribute name="BGCOLOR">
             <xsl:choose>
               <xsl:when test="i='1'">
                   <xsl:call-template name="anglecolor">
                     <xsl:with-param name="angle"><xsl:value-of select="a"/></xsl:with-param>
                   </xsl:call-template>
               </xsl:when>
               <xsl:otherwise>
                   <xsl:call-template name="intensitycolor">
                     <xsl:with-param name="intensity"><xsl:value-of select="i"/></xsl:with-param>
                   </xsl:call-template>
               </xsl:otherwise>
             </xsl:choose>
            </xsl:attribute>

            <xsl:apply-templates select="a" />
            <xsl:apply-templates select="i" />




        <TD bgcolor="white" width="300">
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">t</xsl:with-param>
            <xsl:with-param name="aperture"><xsl:value-of select="t"/></xsl:with-param>
          </xsl:call-template> 
          <IMG SRC="./nohole.JPG"/><IMG SRC="./nohole.JPG"/> 
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">ti</xsl:with-param>
               <xsl:with-param name="aperture"><xsl:value-of select="ti"/></xsl:with-param>
          </xsl:call-template> 
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">tm</xsl:with-param>
            <xsl:with-param name="aperture"><xsl:value-of select="tm"/></xsl:with-param>
          </xsl:call-template> 
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">tr</xsl:with-param>
            <xsl:with-param name="aperture"><xsl:value-of select="tr"/></xsl:with-param>
          </xsl:call-template> 
          <IMG SRC="./nohole.JPG"/>
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">bi</xsl:with-param>
               <xsl:with-param name="aperture"><xsl:value-of select="bi"/></xsl:with-param>
          </xsl:call-template> 
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">bm</xsl:with-param>
            <xsl:with-param name="aperture"><xsl:value-of select="bm"/></xsl:with-param>
          </xsl:call-template> 
          <xsl:call-template name="finger">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">br</xsl:with-param>
            <xsl:with-param name="aperture"><xsl:value-of select="br"/></xsl:with-param>
          </xsl:call-template>
        </TD>


          <xsl:call-template name="frequency">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">bm</xsl:with-param>
            <xsl:with-param name="ratio"><xsl:value-of select="r"/></xsl:with-param>
          </xsl:call-template> 

          <xsl:call-template name="key">
            <xsl:with-param name="ytype"><xsl:value-of select="$nytype"/></xsl:with-param>
            <xsl:with-param name="hole">bm</xsl:with-param>
            <xsl:with-param name="note"><xsl:value-of select="n"/></xsl:with-param>
          </xsl:call-template> 


          </TR>
       </xsl:for-each>
    </xsl:template>

<!-- angle column  -->
    <xsl:template match="a">
      <xsl:variable name="angle">
           <xsl:choose>
             <xsl:when test=".='\'" > regular blowing angle </xsl:when>
             <xsl:when test=".='-'" > more straight angle for deeper sound </xsl:when>
             <xsl:when test=".='|'" > more sidewise blow for higher pitched sound </xsl:when>
             <xsl:otherwise         > ???-angle </xsl:otherwise>
           </xsl:choose>
      </xsl:variable>
        <TD>
          <A>
           <xsl:attribute name="TITLE"><xsl:value-of select="$angle"/></xsl:attribute>
           &#160; <xsl:value-of select="."/>
          </A>
        </TD>
    </xsl:template>

    <xsl:template name="anglecolor">
    <xsl:param name="angle"/>
             <xsl:choose>
               <xsl:when test="$angle='\'">#FF0066</xsl:when>
               <xsl:when test="$angle='-'">#CC0066</xsl:when>
               <xsl:when test="$angle='|'">#990066</xsl:when>
               <xsl:otherwise            >#00<xsl:value-of select="$angle"
               /><xsl:value-of select="$angle"/>00</xsl:otherwise>
             </xsl:choose>
    </xsl:template>

    <xsl:template name="intensitycolor">
    <xsl:param name="intensity"/><!-- shades of grey - - > <xsl:choose>
             <xsl:when test="$intensity='1'" >#AAAAAA</xsl:when>
             <xsl:when test="$intensity='2'" >#BBBBBB</xsl:when>
             <xsl:when test="$intensity='3'" >#CCCCCC</xsl:when>
             <xsl:when test="$intensity='4'" >#DDDDDD</xsl:when>
             <xsl:when test="$intensity='5'" >#EEEEEE</xsl:when>
             <xsl:when test="$intensity='6'" >#FFFFFF</xsl:when>
             <xsl:otherwise                  >#000066</xsl:otherwise>
           </xsl:choose--><!--   shades of red --><xsl:choose>
               <xsl:when test="$intensity='1'">#FF0066</xsl:when>
               <xsl:when test="$intensity='2'">#FF3300</xsl:when>
               <xsl:when test="$intensity='3'">#FF6600</xsl:when>
               <xsl:when test="$intensity='4'">#FF9900</xsl:when>
               <xsl:when test="$intensity='5'">#FFCC00</xsl:when>
               <xsl:when test="$intensity='6'">#FFFF00</xsl:when>
               <xsl:otherwise                >#00<xsl:value-of select="$intensity"
               /><xsl:value-of select="$intensity"/>00</xsl:otherwise>
           </xsl:choose>
    </xsl:template>

<!-- intensity column  -->
    <xsl:template match="i">
      <xsl:variable name="intensity">
           <xsl:choose>
             <xsl:when test=".='1'" > warmest breath for deepest register (1) sounds </xsl:when>
             <xsl:when test=".='2'" > cooler blow for register 2 sounds </xsl:when>
             <xsl:when test=".='3'" > slightly cooler blow for register 3 sounds  </xsl:when>
             <xsl:when test=".='4'" > decidedly cooler blow for register 4 sounds  </xsl:when>
             <xsl:when test=".='5'" > even cooler blow for register 5 sounds  </xsl:when>
             <xsl:when test=".='6'" > much cooler blow for register 6 sounds  </xsl:when>
             <xsl:otherwise         > ???-angle </xsl:otherwise>
           </xsl:choose>
      </xsl:variable>
        <TD>
           <xsl:attribute name="BGCOLOR">
                   <xsl:call-template name="intensitycolor">
                     <xsl:with-param name="intensity"><xsl:value-of select="."/></xsl:with-param>
                   </xsl:call-template>
               </xsl:attribute>
          <A>
           <xsl:attribute name="TITLE"><xsl:value-of select="$intensity"/></xsl:attribute>
           <xsl:value-of select="."/>
          </A>
        </TD>
    </xsl:template>


<!-- aperture -->
    <xsl:template name="finger">
    <xsl:param name="ytype"/>
    <xsl:param name="hole"/>
    <xsl:param name="aperture"/>
      <xsl:variable name="positn">
           <xsl:choose>
             <xsl:when test="$hole='t'"  >Exactly at the middle of the <xsl:value-of select="$ytype"
               /> neys length of <xsl:value-of select="/neyfings/ney/l[../neytype=$ytype]"/> - <xsl:value-of 
               select="/neyfings/ney/h/l[../nr='08' and ../../neytype=$ytype]"/> from either end</xsl:when>
             <xsl:when test="$hole='ti'" > 
               <xsl:value-of select="/neyfings/ney/h/l[../nr='07' and ../../neytype=$ytype]" 
               /> from bottom end of the <xsl:value-of select="$ytype"/> ney</xsl:when>
             <xsl:when test="$hole='tm'" > 
               <xsl:value-of select="/neyfings/ney/h/l[../nr='06' and ../../neytype=$ytype]" 
               />from bottom end of the <xsl:value-of select="$ytype"/> ney</xsl:when>
             <xsl:when test="$hole='tr'" > 
               <xsl:value-of select="/neyfings/ney/h/l[../nr='05' and ../../neytype=$ytype]" 
               /> from bottom end of the <xsl:value-of select="$ytype"/> ney</xsl:when>
             <xsl:when test="$hole='bi'" > 
               <xsl:value-of select="/neyfings/ney/h/l[../nr='04' and ../../neytype=$ytype]" 
               /> from bottom end of the <xsl:value-of select="$ytype"/> ney</xsl:when>
             <xsl:when test="$hole='bm'" > 
               <xsl:value-of select="/neyfings/ney/h/l[../nr='03' and ../../neytype=$ytype]" 
               /> from bottom end of the <xsl:value-of select="$ytype"/> ney</xsl:when>
             <xsl:when test="$hole='br'" > 
               <xsl:value-of select="/neyfings/ney/h/l[../nr='02' and ../../neytype=$ytype]" 
               /> from bottom end of the <xsl:value-of select="$ytype"/> ney</xsl:when>
             <xsl:otherwise              >???-hole:</xsl:otherwise>
           </xsl:choose>
      </xsl:variable>
      <xsl:variable name="holename">
           <xsl:choose>
             <xsl:when test="$hole='t'"  >Top hand thumb hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:when test="$hole='ti'" >Top hand index finger hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:when test="$hole='tm'" >Top hand middle finger hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:when test="$hole='tr'" >Top hand ring finger hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:when test="$hole='bi'" >Bottom hand index finger hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:when test="$hole='bm'" >Bottom hand middle finger hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:when test="$hole='br'" >Bottom hand ring finger hole (<xsl:value-of select="$positn"/>):</xsl:when>
             <xsl:otherwise              > ???-hole:</xsl:otherwise>
           </xsl:choose>
      </xsl:variable>
      <xsl:variable name="openness">
           <xsl:choose>
             <xsl:when test="$aperture='O'"     ><xsl:value-of select="$holename"/> open</xsl:when>
             <xsl:when test="$aperture='o'"     ><xsl:value-of select="$holename"/> open</xsl:when>
             <xsl:when test="$aperture='0'"     ><xsl:value-of select="$holename"/> open</xsl:when>
             <xsl:when test="$aperture='D'"     ><xsl:value-of select="$holename"/> half open</xsl:when>
             <xsl:when test="$aperture='C'"     ><xsl:value-of select="$holename"/> half open</xsl:when>
             <xsl:when test="$aperture='c'"     ><xsl:value-of select="$holename"/> half open</xsl:when>
             <xsl:when test="$aperture='&#189;'"><xsl:value-of select="$holename"/> half open</xsl:when>
             <xsl:when test="$aperture='1/2'"   ><xsl:value-of select="$holename"/> half open</xsl:when>
             <xsl:when test="$aperture='.'"     ><xsl:value-of select="$holename"/> closed</xsl:when>
             <xsl:otherwise                     ><xsl:value-of select="$holename"/> ???</xsl:otherwise>
           </xsl:choose>
      </xsl:variable>
      <A>
       <xsl:attribute name="TITLE"><xsl:value-of select="$openness"/></xsl:attribute>
           <xsl:choose>
             <xsl:when test="$aperture='O'"     ><IMG SRC="./open.JPG"/></xsl:when>
             <xsl:when test="$aperture='o'"     ><IMG SRC="./open.GIF"/></xsl:when>
             <xsl:when test="$aperture='0'"     ><IMG SRC="./open.GIF"/></xsl:when>
             <xsl:when test="$aperture='-'"     ><IMG SRC="./open.GIF"/></xsl:when>
             <xsl:when test="$aperture='_'"     ><IMG SRC="./open.GIF"/></xsl:when>
             <xsl:when test="$aperture='D'"     ><IMG SRC="./half.JPG"/></xsl:when>
             <xsl:when test="$aperture='C'"     ><IMG SRC="./half.JPG"/></xsl:when>
             <xsl:when test="$aperture='c'"     ><IMG SRC="./half.JPG"/></xsl:when>
             <xsl:when test="$aperture='&#189;'"><IMG SRC="./half.JPG"/></xsl:when>
             <xsl:when test="$aperture='1/2'"   ><IMG SRC="./half.JPG"/></xsl:when>
             <xsl:when test="$aperture='1'"     ><IMG SRC="./closed.JPG"/></xsl:when>
             <xsl:when test="$aperture='|'"     ><IMG SRC="./closed.JPG"/></xsl:when>
             <xsl:when test="$aperture='.'"     ><IMG SRC="./closed.JPG"/></xsl:when>
             <xsl:otherwise                ><xsl:value-of select="$aperture"/></xsl:otherwise>
           </xsl:choose>
      </A>
    </xsl:template>


<!-- ratio/frequency column  -->
    <xsl:template name="frequency">
    <xsl:param name="ytype"/>
    <xsl:param name="hole"/>
    <xsl:param name="ratio"/>
      <xsl:variable name="rat">
        <xsl:choose>
          <xsl:when test="$ytype='h&#252;seyni'"  >1</xsl:when>
          <xsl:otherwise              >1.334</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="freq"><xsl:value-of select="round($ratio * $rat)"/></xsl:variable>
        <TD bgcolor="white">
        <xsl:choose>
          <xsl:when test="$freq='NaN'"  >&#160;</xsl:when>
          <xsl:otherwise                ><xsl:value-of select="$freq"/></xsl:otherwise>
        </xsl:choose>
        &#160;</TD>
    </xsl:template>

<!-- note column  -->
    <xsl:template name="key">
    <xsl:param name="ytype"/>
    <xsl:param name="hole"/>
    <xsl:param name="note"/>
        <TD BGCOLOR="white"><xsl:value-of select="$note"/></TD>
    </xsl:template>



</xsl:stylesheet>
