Skip to content

Instantly share code, notes, and snippets.

@bzerangue
Created February 22, 2011 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzerangue/838304 to your computer and use it in GitHub Desktop.
Save bzerangue/838304 to your computer and use it in GitHub Desktop.
Last.fm Recent Tracks by User
<?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&amp;user=</xsl:text>
<xsl:value-of select="$username"/>
<xsl:text>&amp;api_key=</xsl:text>
<xsl:value-of select="$api-key"/>
<xsl:text>&amp;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