<?xml version="1.0"?>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
 |                                                                           |
 | Created by Carl Asman <contact@edlin.org>.                                |
 |                                                                           |
 | For more information:  http://www.edlin.org/xslt/                         |
 |                                                                           |
 +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output method="html" indent="yes" encoding="UTF-8"/>

  <xsl:template match="/">
    <html>
      <head>
	<title>The music list</title>
	 <style>
body {
    font:normal 10% verdana,arial,helvetica;
    color:#000000;
}
th {
    font:normal 12pt verdana,arial,helvetica;
    color:#000000;
}
td {
    font:normal 8pt verdana,arial,helvetica;
    color:#000000;
}
	 </style>
      </head>
      <body>
	<table border="0">
	  <tr bgcolor="#cccccc">
	    <th align="left">Artist</th>
	    <th align="left">Album</th>
	    <th align="left">Title</th>
	    <th align="left">Genre</th>
	    <th align="left">Time</th>
	  </tr>
	 <xsl:for-each select="plist/dict/dict/dict">
	   <xsl:sort select="key[. = 'Artist']/following-sibling::*/text()"/>
	   <xsl:sort select="key[. = 'Album']/following-sibling::*/text()"/>
	   <xsl:sort select="key[. = 'Name']/following-sibling::*/text()"/>
	   <xsl:if test="contains(key[. = 'Track Type']/following-sibling::*/text(), 'File')">
	     <tr>
	       <td bgcolor="ffffcc"><xsl:apply-templates select="key[. = 'Artist']" mode="content"/></td>
	       <td bgcolor="ccffff"><xsl:apply-templates select="key[. = 'Album']" mode="content"/></td>
	       <td bgcolor="ffccff"><xsl:apply-templates select="key[. = 'Name']" mode="content"/></td>
	       <td bgcolor="aaaacc"><xsl:apply-templates select="key[. = 'Genre']" mode="content"/></td>
	       <td bgcolor="ccaaaa"><xsl:apply-templates select="key[. = 'Total Time']" mode="time"/></td>
	     </tr>
	   </xsl:if>
	 </xsl:for-each>
	 <tr><td colspan="5" align="right"> </td></tr>
	 <tr><td colspan="5" align="right"><i>iTunes song list generated by <a href="http://www.edlin.org/xslt/" target="_top">http://www.edlin.org/xslt/</a></i></td></tr>
	</table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="key" mode="content">
    <xsl:value-of select="following-sibling::*/text()"/>
  </xsl:template>

  <xsl:template match="key" mode="time">
    <!-- since time is in milliseconds we habe to recalculate it -->
    <xsl:variable name="mytime" select="following-sibling::*/text()"/>

    <xsl:value-of select="floor ($mytime div 60000)"/> m
    <xsl:value-of select="floor((($mytime div 60000) - floor ($mytime div 60000)) * 60)"/> s
  </xsl:template>

</xsl:stylesheet>