<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cc="http://creativecommons.org/ns#">
<xsl:output method='html' indent='yes'/>

<!-- TODO: incorporate <artist> tags, especially for collaborations -->
<!-- TODO: include date (note: (c) &#169;) -->

<!-- The song id (from the URL) -->
<xsl:param name='id'/>

<xsl:template match='/music'>
	<xsl:choose>
	<!-- Output detailed information for a single song -->
	<xsl:when test='//song[@id = $id or @title = $id]'>
	<xsl:for-each select='//song[@id = $id or @title = $id]'>
    <xsl:call-template name='song'/>
	</xsl:for-each>
	</xsl:when>
	<xsl:otherwise>
    <xsl:if test="not($id = '.') and not($id = '')">
      <h2>Songs</h2>
      <p>Couldn't find a song with the id "<xsl:value-of select='$id'/>."</p>
    </xsl:if>
    <!-- List all songs -->
    <ul class='songs'>
      <xsl:for-each select='//song'>
      <xsl:sort select='@title'/>
      <li style="clear:right;">
        <xsl:choose>
          <xsl:when test='branch[1]/recording'>
          <object type="application/x-shockwave-flash" width="20" height="20">
          <xsl:attribute name='data'>/music/xspf/button_player.swf?song_title=<xsl:value-of select='@title'/>&amp;song_url=http://audio.blaise.ca/songs/<xsl:value-of select='@id'/>/<xsl:if test='branch[1]/@id'><xsl:value-of select='branch[1]/@id'/>/</xsl:if><xsl:value-of select='@id'/>-<xsl:value-of select='branch[1]/recording/@version'/><xsl:if test='branch[1]/@id'>-<xsl:value-of select='branch[1]/@id'/></xsl:if>.mp3</xsl:attribute>
            <param name="movie"> 
              <xsl:attribute name='value'>http://blaise.ca/music/xspf/button_player.swf?songtitle=<xsl:value-of select='@title'/>&amp;song_url=http://audio.blaise.ca/songs/<xsl:value-of select='@id'/>/<xsl:if test='branch[1]/@id'><xsl:value-of select='branch[1]/@id'/>/</xsl:if><xsl:value-of select='@id'/>-<xsl:value-of select='branch[1]/recording/@version'/><xsl:if test='branch[1]/@id'>-<xsl:value-of select='branch[1]/@id'/></xsl:if>.mp3</xsl:attribute>
            </param>
          </object>
          </xsl:when>
          <xsl:otherwise>&#160;&#160;&#160;&#160;&#160;</xsl:otherwise>
        </xsl:choose>
        <a class='name'>
          <xsl:attribute name='href'>/music/songs/<xsl:value-of select='@id'/></xsl:attribute>
          <xsl:value-of select='@title'/>
        </a>
        &#160;&#160;
        <xsl:apply-templates select='tags'/>
      </li>
      </xsl:for-each>
    </ul>
	</xsl:otherwise>
	</xsl:choose>
</xsl:template>


<!-- Song details -->
<xsl:template name='song'>
  <section class='song'>
  <h2><xsl:value-of select='@title'/></h2>
  <header class='entry-meta'>
    <span class="license">
      <a rel="license">
        <xsl:attribute name='href'><xsl:value-of select='@license'/></xsl:attribute>
        <img alt="{@license-type}">
          <xsl:attribute name='src'>/images/cc/buttons/small/<xsl:value-of select='@license-type'/>.png</xsl:attribute>
        </img>
      </a>
    </span>

    <span class="entry-meta author artist song-artist">
      composed by <xsl:for-each select='artist'>
        <a rel="cc:attributionURL" property="cc:attributionName">
          <xsl:attribute name='href'><xsl:value-of select='href'/></xsl:attribute>
          <xsl:value-of select='.'/>
        </a>
      </xsl:for-each>
    </span>
    &#160;
    <xsl:apply-templates select='tags'/>
  </header>
  
  <xsl:apply-templates select="*[not(name()='tags')]"/>
  
  </section>
</xsl:template>

<xsl:template match='artist'></xsl:template>

<xsl:template match='image'>
  <section class='poster'>
    <a>
      <xsl:attribute name='href'>
        <xsl:choose>
          <xsl:when test='@href'><xsl:value-of select='@href'/></xsl:when>
          <xsl:otherwise><xsl:value-of select='@src'/></xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <img alt='Song poster'>
        <xsl:attribute name='src'><xsl:value-of select='@src'/></xsl:attribute>
      </img>
    </a>
    <xsl:if test='@cc:attributionName'>
      <footer class='credit'>
        <small>Credit: <a rel="cc:attributionURL" property="cc:attributionName">
          <xsl:attribute name='href'>
            <xsl:value-of select='@cc:attributionURL'/>
          </xsl:attribute>
          <xsl:value-of select='@cc:attributionName'/>
        </a>
        (<a><xsl:attribute name='href'><xsl:value-of select='@license'/></xsl:attribute><xsl:value-of select='@license-shortname'/></a>)</small>
      </footer>
    </xsl:if>
  </section>
</xsl:template>

<xsl:template match='branch'>
  <section class='branch'>
    <xsl:apply-templates/>
  </section>
</xsl:template>

<xsl:template match='video'>
  <article>
    <h3>Version <xsl:call-template name='file-id'/></h3> 
    <!-- Source: Video for Everybody http://camendesign.com/code/video_for_everybody/test.html -->
    <!-- first try HTML5 playback: if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise -->
    <!-- warning: playback does not work on iOS3 if you include the poster attribute! fixed in iOS4.0 -->
    <!-- TODO: poster -->
    <video width="640" height="360" controls="controls">
      <!-- MP4 must be first for iPad! -->
      <source type="video/mp4"><xsl:attribute name='src'><xsl:call-template name='video-filepath'/>.m4v</xsl:attribute></source> <!-- Safari / iOS video -->
      <source type="video/webm"><xsl:attribute name='src'><xsl:call-template name='video-filepath'/>.webm</xsl:attribute></source>
      <source type="video/ogg"><xsl:attribute name='src'><xsl:call-template name='video-filepath'/>.ogv</xsl:attribute></source> <!-- Firefox / Opera / Chrome10 -->
      <!-- fallback to Flash: -->
      <xsl:copy-of select='video/*'/>
        <!-- TODO: (should be inside object tag) fallback image. note the title field below, put the title of the video there -->
        <!-- <img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__"
             title="No video playback capabilities, please download the video below" /> -->
    </video>
    <!-- you *must* offer a download link as they may be able to play the file locally. customise this bit all you want -->
    <p><xsl:call-template name='download'/></p>
  </article>
</xsl:template>

<xsl:template match='recording'>
  <article>
  <h3>Version <xsl:call-template name='file-id'/></h3> 
  <div style='margin-bottom:0.5em'><xsl:apply-templates/></div>
  <audio controls="controls">
  <xsl:attribute name='id'>audio-<xsl:call-template name='filename'/></xsl:attribute>
    <source type="audio/ogg"><xsl:attribute name='src'><xsl:call-template name='audio-filepath'/>.ogg</xsl:attribute> </source>
    <source type="audio/mpeg"><xsl:attribute name='src'><xsl:call-template name='audio-filepath'/>.mp3</xsl:attribute> </source>

    <object width="400" height="24" type="application/x-shockwave-flash" name="audio-anaximander-0.1-folk" style="outline-color: -moz-use-text-color; outline-style: none; outline-width: medium; visibility: visible;" data="/music/1pixelout/player.swf">
      <xsl:attribute name='name'>audioplayer-<xsl:call-template name='filename'/></xsl:attribute>
      <param name="wmode" value="opaque"/>
      <param name="menu" value="false"/>
      <param name="flashvars">
        <xsl:attribute name='value'>soundFile=<xsl:call-template name='audio-filepath'/>.mp3&amp;titles=<xsl:call-template name='branch-maintitle'/>&amp;playerID=audio-<xsl:call-template name='filename'/></xsl:attribute>
      </param>

      <div class="1pixelout"><xsl:attribute name='id'>audioplayer-<xsl:call-template name='filename'/>></xsl:attribute><a><xsl:attribute name="href"><xsl:call-template name='audio-filepath'/>.mp3</xsl:attribute><xsl:call-template name='filename'/></a></div>
    </object>
  </audio>


  <p>
    <xsl:call-template name='download'/>&#160;|&#160;
    <a>
       <xsl:attribute name='id'>flashplayer-backup-<xsl:call-template name='filename'/></xsl:attribute>
       <xsl:attribute name='href'>javascript:AudioPlayer.embed("audio-<xsl:call-template name='filename'/>", { soundFile: "<xsl:call-template name='audio-filepath'/>.mp3", titles: "<xsl:value-of select='../@title'/> (<xsl:value-of select='recording[1]/@version'/><xsl:if test='@id'>-<xsl:value-of select='@id'/></xsl:if>)"   });</xsl:attribute>
       flash player</a>
    <xsl:if test='@lastfm'>
      | <xsl:call-template name='lastfm'/>
    </xsl:if>
  </p> 

  </article>
</xsl:template>


<xsl:template match='tags'>
  <span class="tag-links">
    <xsl:for-each select='tag'><a href="#"><xsl:value-of select='.'/></a>&#160;</xsl:for-each>
  </span>
</xsl:template>


<xsl:template match='lyrics'>
  <section class="lyrics">
  <h3>Lyrics</h3>
  <!-- not ready: <p><a><xsl:attribute name='href'><xsl:value-of select='@source'/></xsl:attribute>source</a></p> -->
  <article>
    <xsl:copy-of select='./*'/>
  </article>
  </section>
</xsl:template>



<!-- Paths to audio/video content of a particular branch element, minus extensions -->
<xsl:template name='audio-filepath'>http://audio.blaise.ca/songs/<xsl:call-template name='filepath'/></xsl:template>
<xsl:template name='video-filepath'>http://media.blaise.ca/songs/<xsl:call-template name='filepath'/></xsl:template>

<!-- File path on server to content -->
<xsl:template name='filepath'><xsl:call-template name='dirpath'/><xsl:call-template name='filename'/></xsl:template>

<!-- Directory that content resides in -->
<xsl:template name='dirpath'><xsl:value-of select='../../@id'/>/<xsl:if test='../@id'><xsl:value-of select='../@id'/>/</xsl:if></xsl:template>

<!-- Filename, minus extension, of the content -->
<xsl:template name='filename'><xsl:value-of select='../../@id'/>-<xsl:call-template name='file-id'/></xsl:template>

<!-- Full version / id of content -->
<xsl:template name='file-id'><xsl:value-of select='@version'/><xsl:if test='../@id'>-<xsl:value-of select='../@id'/></xsl:if></xsl:template>




<!-- Determine human-readable title of main recording from this branch -->
<xsl:template name='branch-maintitle'><xsl:value-of select='../../@title'/>&#160;(<xsl:call-template name='file-id'/>)</xsl:template>


<!-- Download link -->
<xsl:template name='download'>
	<a><xsl:attribute name='href'>/music/download.php?file=<xsl:value-of select='../../@id'/>/<xsl:if test='../@id'><xsl:value-of select='../@id'/>/</xsl:if><xsl:value-of select='../../@id'/>-<xsl:value-of select='@version'/><xsl:if test='../@id'>-<xsl:value-of select='../@id'/></xsl:if></xsl:attribute><xsl:attribute name='title'><xsl:value-of select='../../@id'/>-<xsl:value-of select='@version'/><xsl:if test='../@id'>-<xsl:value-of select='../@id'/></xsl:if></xsl:attribute>Download</a>
</xsl:template>

<!-- Links to Last.fm -->
<xsl:template name='lastfm'>
	<a><xsl:attribute name='href'><xsl:value-of select='@lastfm'/></xsl:attribute>last.fm</a>
</xsl:template>

<!-- Links to OGG Vorbis files
<xsl:template name='ogg'>
	[<a><xsl:attribute name='href'><xsl:value-of select='@filename'/>.ogg</xsl:attribute><xsl:attribute name='title'><xsl:value-of select='@title'/>&#160;<xsl:value-of select='@version'/>&#160;OGG Vorbis file</xsl:attribute>ogg</a>]
</xsl:template> -->


<!-- *********** OTHER PROJECTS *************** -->
<!-- TODO: Does this belong in another file or is it ok here? -->
<!-- Lists all projects -->
<xsl:template match='/projects'>
  <script type="text/javascript">
  $(function() {
    $("#tabs").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
    $("#tabs li").removeClass('ui-corner-top').addClass('ui-corner-left');
  });
  </script>
  <style type="text/css">
  
/* Vertical Tabs
----------------------------------*/
.ui-tabs .ui-tabs-hide {
     display: none;
}
.ui-tabs-vertical { width: 52em; }
.ui-tabs-vertical .ui-tabs-nav { padding: .2em .1em .2em .2em; float: left; width: 16em; }
.ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; }
.ui-tabs-vertical .ui-tabs-nav li a { display:block; }
.ui-tabs-vertical .ui-tabs-nav li.ui-tabs-selected { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; border-right-width: 1px; }
.ui-tabs-vertical .ui-tabs-panel { padding: 1em; float: right; width: 30em;}
  </style>


	<a name='top'></a>

	<!-- Summary of other projects -->
  <div id="tabs">
	<ul class="projects">
	<xsl:for-each select='project'>
    <xsl:sort select="@active" order="descending"/>
  	<xsl:sort select='@name'/>
		<li>
  			<a>
          <xsl:if test='@active="true"'><xsl:attribute name='class'>active</xsl:attribute></xsl:if>
  				<xsl:attribute name='href'>#<xsl:value-of select='@id'/></xsl:attribute>
  				<xsl:value-of select='@name'/>
  			</a>
		</li>
	</xsl:for-each>
	</ul>

	<!-- Detailed listing of other projects -->
	<xsl:apply-templates select='project' />
  </div>
</xsl:template>

<!-- Detailed listing of a given project -->
<xsl:template match='project'>
<div>
  <xsl:attribute name='class'>project <xsl:if test='@active="true"'>active</xsl:if></xsl:attribute>
  <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
	<a><xsl:attribute name='name'><xsl:value-of select='@id'/></xsl:attribute></a>
	<h2><xsl:value-of select='@name'/></h2>

	<!-- Link(s) -->
	<xsl:if test='link'>
			<xsl:for-each select='link'>
			<xsl:sort select='@type'/>
				<xsl:call-template name="other_link"/>
			</xsl:for-each>
		<br/>
	</xsl:if>

	<!-- Image -->
	<xsl:for-each select='img'>
		<xsl:call-template name='other_image'/>
	</xsl:for-each>

	<!-- Description -->
	<xsl:if test='sample'>
		<p><a>
			<xsl:attribute name='href'>#<xsl:value-of select='@id'/>-sample</xsl:attribute>
			<xsl:attribute name='onclick'>document.getElementById('<xsl:value-of select='@id'/>-sample').style.display="block"; this.style.display = 'none';</xsl:attribute>
			Listen
		</a></p>
		<div style='display:none;'>
			<xsl:attribute name='id'><xsl:value-of select='@id'/>-sample</xsl:attribute>
			<xsl:copy-of select='sample/p'/>
		</div>
	</xsl:if>

	<xsl:value-of select='@from'/> to <xsl:value-of select='@to'/><br/>

	<!-- Genre(s) -->
	<xsl:if test='genre'>
		<strong>Genres:</strong>&#160;
		<xsl:for-each select='genre'>
			<xsl:value-of select='.'/>
			<xsl:choose>
				<xsl:when test='following-sibling::genre'> / </xsl:when>
				<xsl:otherwise><xsl:if test='preceding-sibling::genre'></xsl:if></xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<br/>
	</xsl:if>

	<!-- Role(s) -->
	<xsl:if test='role'>
		<strong>Roles:</strong>&#160;
		<xsl:for-each select='role'>
			<xsl:value-of select='.'/>
			<xsl:choose>
				<xsl:when test='following-sibling::role'>, </xsl:when>
				<xsl:otherwise><xsl:if test='preceding-sibling::role'>.</xsl:if></xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<br/>
	</xsl:if>

	<!-- Activities -->
	<xsl:if test='activity'>
		<strong>Activities:</strong>&#160;
		<xsl:for-each select='activity'>
			<xsl:value-of select='.'/>
			<xsl:choose>
				<xsl:when test='following-sibling::activity'>, </xsl:when>
				<xsl:otherwise><xsl:if test='preceding-sibling::activity'>.</xsl:if></xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<br/>
	</xsl:if>
	
	<!-- Description -->
	<xsl:copy-of select='description/p'/>
</div>
</xsl:template>


<!-- Other Project images -->
<xsl:template name="other_image">
		<p>
			<a>
				<xsl:attribute name='href'>
					<xsl:choose>
						<xsl:when test='@href'>
							<xsl:value-of select='@href'/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select='@src'/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<img>
					<xsl:attribute name='src'>
						<xsl:value-of select='@src'/>
					</xsl:attribute>
					<xsl:if test='@credit or @title'>
						<xsl:attribute name='title'>
							<xsl:value-of select='@title'/>
							<xsl:if test='@credit'>&#160;- photo by <xsl:value-of select='@credit'/></xsl:if>
							<!--<xsl:value-of select='@credit_link'/>-->
						</xsl:attribute>
					</xsl:if>
				</img>
			</a>
		</p>
</xsl:template>

<!-- Other Project web profile links -->
<xsl:template name="other_link">
	<a>
		<xsl:attribute name='href'><xsl:value-of select='@href'/></xsl:attribute>
		<xsl:choose>
			<xsl:when test='@type'>
				<xsl:attribute name='title'><xsl:value-of select='../@name'/>&#160;<xsl:value-of select='@type'/></xsl:attribute>
				<img>
					<xsl:attribute name='src'>/images/icons/<xsl:value-of select='@type'/>.png</xsl:attribute>
				</img>
			</xsl:when>
			<xsl:otherwise>
				<img src='/images/icons/default.png'/>
			</xsl:otherwise>
		</xsl:choose>
	</a>
</xsl:template>


</xsl:stylesheet>

