Author:
bzerangue
Version:
1.0
Release Date:
22 Feb 2011
Category:
Third-Party Integration

Description

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’

XSLT

View Raw
<?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>
  https://gist.github.com/838304

  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>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details