<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
	<xsl:output indent="no" encoding="ISO-8859-1" method="html"/>

	<xsl:template match="/">
		<xsl:element name="table">
			<xsl:attribute name="cellpadding">0</xsl:attribute>
			<xsl:attribute name="cellspacing">0</xsl:attribute>
			<xsl:attribute name="width">100%</xsl:attribute>

			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="align">left</xsl:attribute>
					<xsl:text>#</xsl:text>
				</xsl:element>
				<xsl:element name="th">
					<xsl:attribute name="align">left</xsl:attribute>
					<xsl:text>Artist</xsl:text>
				</xsl:element>
				<xsl:element name="th">
					<xsl:attribute name="align">left</xsl:attribute>
					<xsl:text>Album</xsl:text>
				</xsl:element>
				<xsl:element name="th">
					<xsl:attribute name="align">left</xsl:attribute>
					<xsl:text>Title</xsl:text>
				</xsl:element>
				<xsl:element name="th">
					<xsl:attribute name="align">left</xsl:attribute>
					<xsl:text>My Rating</xsl:text>
				</xsl:element>
			</xsl:element>

			<xsl:apply-templates select="plist/dict/dict/dict">
				<xsl:sort select="key[.='Play Date']/following-sibling::node()[1]" data-type="number" order="descending"/>
			</xsl:apply-templates>
		</xsl:element>
    </xsl:template>

    <xsl:template match="plist/dict/dict/dict">
	    <xsl:if test="position()&lt;=200">
		    <xsl:element name="tr">
			    <xsl:if test="position() mod 2 = 0">
				    <xsl:attribute name="style">background-color: #f3f3f3;</xsl:attribute>
			    </xsl:if>
			    <xsl:element name="td">
				    <xsl:value-of select="position()"/>.
			    </xsl:element>
			    <xsl:element name="td">
				    <xsl:attribute name="nowrap">true</xsl:attribute>
				    <xsl:value-of select="substring(key[.='Artist']/following-sibling::node()[1], 1, 30)"/>
			    </xsl:element>
			    <xsl:element name="td">
				    <xsl:attribute name="nowrap">true</xsl:attribute>
				    <xsl:value-of select="substring(key[.='Album']/following-sibling::node()[1], 1, 30)"/>
			    </xsl:element>
			    <xsl:element name="td">
				    <xsl:attribute name="nowrap">true</xsl:attribute>
				    <xsl:value-of select="substring(key[.='Name']/following-sibling::node()[1], 1, 30)"/>
			    </xsl:element>
			    <xsl:element name="td">
				    <xsl:attribute name="nowrap">true</xsl:attribute>
				    <xsl:variable name="rating" select="key[.='Rating']/following-sibling::node()[1]" />
				    <xsl:choose>
					    <xsl:when test="$rating = 100">
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
					    </xsl:when>
					    <xsl:when test="$rating = 80">
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
					    </xsl:when>
					    <xsl:when test="$rating = 60">
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
					    </xsl:when>
					    <xsl:when test="$rating = 40">
						    <img src="img/star.gif" alt="" />
						    <img src="img/star.gif" alt="" />
					    </xsl:when>
					    <xsl:when test="$rating = 20">
						    <img src="img/star.gif" alt="" />
					    </xsl:when>
				    </xsl:choose>
			    </xsl:element>
		    </xsl:element>
	    </xsl:if>
    </xsl:template>

    <xsl:template match="text()">
	    <xsl:value-of select="normalize-space()"/>
    </xsl:template>
    
</xsl:stylesheet>

