Created
February 22, 2011 06:50
-
-
Save bzerangue/838304 to your computer and use it in GitHub Desktop.
Last.fm Recent Tracks by User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='utf-8'?> | |
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> | |
<!-- | |
Name: Last.fm Recent Tracks by User | |
Version: 1.0 | |
Author: Brian Zerangue <brian.zerangue@gmail.com> | |
REQUIRED PARAMETERS: api-key, username | |
Call the template like so... | |
<xsl:call-template name="get-last-fm-recent-tracks"> | |
<xsl:with-param name="api-key" select="'YOUR-API-KEY-HERE'"/> | |
<xsl:with-param name="username" select="'YOUR-USERNAME-HERE'"/> | |
</xsl:call-template> | |
OPTIONAL PARAMETERS: | |
page: Default is 1. | |
location-source: Default is 'external'. This uses the document() to bring in the XML from the URL. | |
Or if you put 'local' it will use the one local to your Symphony install. | |
image-size: Default is 'large'. Other options include 'small', 'medium', 'extralarge' | |
--> | |
<xsl:template name="get-last-fm-recent-tracks"> | |
<xsl:param name="location-source" select="'external'"/> | |
<xsl:param name="api-key"/><!-- Required --> | |
<xsl:param name="username"/><!-- Required --> | |
<xsl:param name="page" select="1"/> | |
<xsl:param name="xml-source"> | |
<xsl:text>http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=</xsl:text> | |
<xsl:value-of select="$username"/> | |
<xsl:text>&api_key=</xsl:text> | |
<xsl:value-of select="$api-key"/> | |
<xsl:text>&page=</xsl:text> | |
<xsl:value-of select="$page"/> | |
</xsl:param> | |
<xsl:param name="image-size" select="'large'"/> | |
<xsl:element name="ul"> | |
<xsl:choose> | |
<xsl:when test="$location-source='external'"> | |
<xsl:apply-templates select="document($xml-source)/lfm/recenttracks/track"> | |
<xsl:with-param name="img-size" select="$image-size"/> | |
</xsl:apply-templates> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:apply-templates select="//track"> | |
<xsl:with-param name="img-size" select="$image-size"/> | |
</xsl:apply-templates> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:element> | |
</xsl:template> | |
<xsl:template match="track"> | |
<xsl:param name="element-wrap" select="'li'"/> | |
<xsl:param name="img-size"/> | |
<xsl:element name="{$element-wrap}"> | |
<a href="{url}" title="{name} by {artist}"> | |
<img src="{image[@size=$img-size]}" alt="{name} by {artist}"/> | |
</a> | |
</xsl:element> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment