<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" media-type="text/html" encoding="utf-8" indent="yes" />
<xsl:template match="/TEI">
<xsl:element name="html">
  <xsl:attribute name="xml:lang">
    <xsl:value-of select="'en'" />
  </xsl:attribute>
  <xsl:attribute name="lang">
    <xsl:value-of select="'en'"/>
  </xsl:attribute>

  <xsl:element name="head">
    <title>Alexander Svoboda's Journal of a Journey</title>
    <link rel="stylesheet" type="text/css" href="styles/diary_style.css" />
    <script type="text/javascript" src="scripts/growme.js"/> 
    <script type="text/javascript" src="scripts/showpage.js" />
  </xsl:element>
    <body>
    <div id="mainBox">
<div id="title">
      <h2 style="display:inline">Alexander Svoboda's Journal of a Journey to Europe</h2> | <h4 style="display:inline">(<a href="instructions.html">instructions/features</a>)</h4><br />
          <div id="navver1" onclick="shrinkme('echaps')"> <span> <a href="#apr_engl">April</a> | <a href="#may_engl">May</a> | <a href="#jun_engl">June</a> | <a href="#jul_engl">July</a> </span> | <span onmouseover="growme('echaps')" onclick="shrinkme('echaps')"> Chapters:</span>

<div id="echaps" onmouseout="shrinkme('echaps')">
<ul>
  <xsl:for-each select="//head[@type='chapter']">
    <xsl:variable name="lang">
      <xsl:value-of select="substring(ancestor::div[@type='month']/@xml:id,5,4)" />
    </xsl:variable>
    <xsl:variable name="numb">
      <xsl:value-of select="ancestor::div[@type='chapter']/@n" />
    </xsl:variable>
      <xsl:choose>
        <xsl:when test="$lang='engl'">
        <li>
          <xsl:element name="a">  
          <xsl:attribute name="href">
          <xsl:value-of select="concat('#',$lang,'ch_', $numb)" />
          </xsl:attribute>
          <xsl:value-of select="concat('ch ',$numb,': ',.)"/>
        </xsl:element>
        </li>    
        </xsl:when>

        <xsl:otherwise />
      </xsl:choose>
  </xsl:for-each> 
</ul>
</div>
 </div>
                  <div id="navver2"> <span> <a href="#apr_arab">نيسان</a> | <a href="#may_arab">ايار</a> | <a href="#jun_arab">حزيران</a> | <a href="#jul_arab">تموز</a> </span> | 
<span onmouseover="growme('achaps')" onclick="shrinkme('achaps')" style="direction:ltr"> Chapters:</span>

<div id="achaps" onmouseout="shrinkme('achaps')">
<ul>
  <xsl:for-each select="//head[@type='chapter']">
    <xsl:variable name="lang">
      <xsl:value-of select="substring(ancestor::div[@type='month']/@xml:id,5,4)" />
    </xsl:variable>
    <xsl:variable name="numb">
      <xsl:value-of select="ancestor::div[@type='chapter']/@n" />
    </xsl:variable>
      <xsl:choose>
        <xsl:when test="$lang='arab'">
        <li>
          <xsl:element name="a">  
          <xsl:attribute name="href">
          <xsl:value-of select="concat('#',$lang,'ch_', $numb)" />
          </xsl:attribute>
          <xsl:value-of select="concat('ch ',$numb,': ',.)"/>
        </xsl:element>
        </li>    
        </xsl:when>

        <xsl:otherwise />
      </xsl:choose>
  </xsl:for-each> 
</ul>
</div>
</div><br />

</div><br />

        <div class="allMonths">

          <div class="engl">

          <h4 class="monthTitle"><a name="apr_engl">April</a></h4>
          <xsl:apply-templates select="text/body/div[@xml:id='apr_engl']" />

          <h4 class="monthTitle"><a name="may_engl">May</a></h4>
          <xsl:apply-templates select="text/body/div[@xml:id='may_engl']" />
          <h4 class="monthTitle"><a name="jun_engl">June</a></h4>
          <xsl:apply-templates select="text/body/div[@xml:id='jun_engl']" />
          <h4 class="monthTitle"><a name="jul_engl">July</a></h4>

          <xsl:apply-templates select="text/body/div[@xml:id='jul_engl']" />
          </div>

          <div class="arab">

          <h4 class="monthTitle"><a name="apr_arab">April</a></h4>
          <xsl:apply-templates select="text/body/div[@xml:id='apr_arab']" />
          <h4 class="monthTitle"><a name="may_arab">May</a></h4>
          <xsl:apply-templates select="text/body/div[@xml:id='may_arab']" />
          <h4 class="monthTitle"><a name="jun_arab">June</a></h4>
          <xsl:apply-templates select="text/body/div[@xml:id='jun_arab']" />

          <h4 class="monthTitle"><a name="jul_arab">July</a></h4>

          <xsl:apply-templates select="text/body/div[@xml:id='jul_arab']" />
          </div>
        </div>
          <div class="notes_glosses">
          <h5>Notes</h5>
          <xsl:apply-templates select="text/back/div[@xml:id='notes']/div"/>
          </div>
	  </div>
      </body>
  </xsl:element>
</xsl:template>

  <xsl:template match="pb">
      <xsl:variable name="momma"><xsl:value-of select="ancestor::div[@type='month']/@xml:id"/></xsl:variable>
      <xsl:variable name="lang"><xsl:value-of select="substring($momma,5,4)"/></xsl:variable>
      <xsl:variable name="q">'</xsl:variable>
      <xsl:variable name="r">,</xsl:variable>

    <br/>
    <xsl:element name="h4">
      <xsl:choose>  
        <xsl:when test="$lang='engl'">
        <xsl:attribute name="onclick"><xsl:value-of select="concat('showPage(',$q,@n,$q,$r,$q,$lang,$q,')')"/></xsl:attribute>
        </xsl:when>
        <xsl:when test="$lang='arab'">
        <xsl:attribute name="onclick"><xsl:value-of select="concat('showPage(',$q,@n,$q,$r,$q,$lang,$q,')')"/></xsl:attribute>
        </xsl:when>

        <xsl:otherwise />
      </xsl:choose>
      <xsl:element name="span">
        <xsl:attribute name="class">pageLink</xsl:attribute>
        Page <xsl:value-of select="@n"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template match="lb">
    <xsl:variable name="n"><xsl:value-of select="@n"/></xsl:variable>
    <br/><div class="break"><xsl:value-of select="$n"/></div>
            
    <xsl:variable name="noteTest" select="local-name(following-sibling::*[1])" />
    <xsl:variable name="pagenum" select="preceding::pb[1]/@n" />
    <xsl:variable name="lang" select="ancestor::div[@type='month']/@xml:id"/>
    <xsl:variable name="addy">
      <xsl:choose>
        <xsl:when test="substring($lang,5,4)='engl'">
          <xsl:value-of select="concat('HE',$pagenum,'-',@n)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="substring($lang,5,4)='arab'">
              <xsl:value-of select="concat('HA',$pagenum,'-',@n)"/>
            </xsl:when>
            <xsl:otherwise />
          </xsl:choose>
        </xsl:otherwise>  
      </xsl:choose>
    </xsl:variable>
          <xsl:choose>
                <xsl:when test="$noteTest = 'note'" />
                <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="//head/@xml:id = $addy">
            <xsl:element name="div">

              <xsl:attribute name="class">
                <xsl:value-of select="'margin'"/>
              </xsl:attribute>
              <xsl:value-of select="//head[@xml:id=$addy]" />
            </xsl:element>
          </xsl:when>
          <xsl:otherwise>
             <div class="margin"><div style="padding-left:5%;padding-right:5%"><span style="display:none">.</span></div></div>
          </xsl:otherwise>  
        </xsl:choose>
                </xsl:otherwise>
          </xsl:choose> 
  </xsl:template>

  <xsl:template match="//head[@type='chapter']">
    <xsl:variable name="l">
      <xsl:value-of select="substring(ancestor::div[@type='month']/@xml:id,5,4)"/>
    </xsl:variable>
    <xsl:variable name="ch_num">
      <xsl:value-of select="ancestor::div[@type='chapter']/@n"/> 
    </xsl:variable>
    <div style="width:100%">

    <span style="text-align:center;padding-left:5%;padding-right:5%"><strong>
    <xsl:element name="a">
      <xsl:attribute name="name"><xsl:value-of select="concat($l,'ch_',$ch_num)"/></xsl:attribute>
    <xsl:value-of select="."/>
    </xsl:element></strong>
    </span>
    </div>
  </xsl:template>

  <xsl:template match="div[@type='chapnote']/head">
  <strong><xsl:value-of select="."/></strong>
  </xsl:template>

<!--content nesting combinations: prototypes-->
<!--Template for non-nested name tags-->
  <xsl:template match="name[not(child::term)][not(child::ref)]">
    <xsl:choose>
      <xsl:when test="@type = 'person'">
        <span style="color:#CC9933"> <xsl:value-of select="." /> </span>
      </xsl:when>
      <xsl:when test="@type = 'place'">
        <span style="color:#8B2323"> <xsl:value-of select="." /> </span>

      </xsl:when>
    </xsl:choose>
  </xsl:template>
<!--Template for non-nested time tags-->  
  <xsl:template match="time[not(child::term)][not(child::ref)]">
    <span style="color:green">
      <xsl:value-of select="." />
    </span>
  </xsl:template>

<!--Template for nested term tags-->  
  <xsl:template match="//term[not(ancestor::ref)]">

    <xsl:element name="span">
    <xsl:attribute name="class">term</xsl:attribute>
    <xsl:variable name="type">
      <xsl:value-of select="ancestor::name/@type|descendant::name/@type" />
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$type = 'person'">
        <xsl:attribute name="style">color:#CC9933</xsl:attribute>

      </xsl:when>
      <xsl:when test="$type = 'place'">
        <xsl:attribute name="style">color:#8B2323</xsl:attribute>
      </xsl:when>
      <xsl:when test="ancestor::time">
        <xsl:attribute name="style">color:green;</xsl:attribute>
      </xsl:when>
      </xsl:choose>

    <xsl:value-of select="."/>
    </xsl:element>  
  </xsl:template>

<!--Template for nested tags-->    
<!--term/ref/name is not working! jc 14July2010-->
  <xsl:template match="//ref">
    <xsl:variable name="target" select="@target"/>
    <xsl:choose>
    <xsl:when test="//note[@xml:id=substring($target,2)]">   
    <xsl:element name="a">
      <xsl:attribute name="class"> <xsl:value-of select="'noteButton'" /> </xsl:attribute>
          <xsl:attribute name="style">color:black</xsl:attribute> 
      <xsl:variable name="type">
        <xsl:value-of select="ancestor::name/@type|descendant::name/@type" />
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="$type = 'person'">
          <xsl:attribute name="style">color:#CC9933</xsl:attribute> 
        </xsl:when>
        <xsl:when test="$type = 'place'">

          <xsl:attribute name="style">color:#8B2323</xsl:attribute>
        </xsl:when>
        <xsl:when test="ancestor::time|descendant::time">
          <xsl:attribute name="style">color:green</xsl:attribute>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="ancestor::term|descendant::term">
          <xsl:attribute name="class">term</xsl:attribute>
        </xsl:when>
      </xsl:choose>
      <xsl:attribute name="href"><xsl:value-of select="$target"/></xsl:attribute>
        <xsl:value-of select="." />
      <xsl:element name="ins">
        <xsl:value-of select="//note[@xml:id=substring($target,2)]" /> 
      </xsl:element>
    </xsl:element>

    </xsl:when>
    <xsl:otherwise>
      <xsl:element name="span">
      <xsl:variable name="type">
        <xsl:value-of select="ancestor::name/@type|descendant::name/@type" />
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="$type = 'person'">
          <xsl:attribute name="style">color:#CC9933</xsl:attribute> 
        </xsl:when>
        <xsl:when test="$type = 'place'">

          <xsl:attribute name="style">color:#8B2323</xsl:attribute>
        </xsl:when>
        <xsl:when test="ancestor::time|descendant::time">
          <xsl:attribute name="style">color:green</xsl:attribute>
        </xsl:when>
      </xsl:choose>
      <xsl:value-of select="."/>
      </xsl:element>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="head[@type='margin']" />

  <xsl:template match="note[@xml:id !=''][not(child::gloss)]">
  <li>
    <xsl:apply-templates />
  </li>    
  </xsl:template> 
  
  <xsl:template match="a[parent::note]">  
    <xsl:copy-of select="."/>
  </xsl:template> 

  <xsl:template match="foreign[not(child::term)][not(child::ref)]">
    <span style="color:#33cccc;">
      <xsl:apply-templates />
    </span>
  </xsl:template>

  <xsl:template match="text/back/div[@xml:id='notes']/div">
      <xsl:apply-templates select="head" />
    <ol>
      <xsl:apply-templates select="note" />
    </ol>
  </xsl:template>

  <xsl:template match="milestone[@rend='horizontal rule']">
    <hr style="width:50%;display:inline-block"/>
  </xsl:template>

  <xsl:template match="graphic">
    <xsl:element name="img">
      <xsl:attribute name="src">
        <xsl:value-of select="@url" />
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="figure">
    <xsl:apply-templates select="graphic"/>
  </xsl:template>
</xsl:stylesheet>
