Dealing with spaces in a document() call
This is an open discussion with 2 replies, filed under XSLT.
Search
Can you write out $one and look at its value? Last.FM URLs require the artist name to be URL encoded (e.g. Michael Jackson becomes Michael+Jackson). Perhaps you could try replacing spaces with +?
translate($one, ' ', '+')
EDITED: I had a question then answered it myself! You got me on the right track though with the url encoding.
I should note this is on 1.7
I created a new component called url-encode based on this script and edited my code as follows:
<xsl:template name="last-fm"> <xsl:variable name="last" select="document('http://ws.audioscrobbler.com/1.0/user/devkinetic/recenttracks.rss')" /> <h2>Recently Played Tracks - <a href="{$last/rss/channel/link}" alt="My Last FM Profile">Profile</a></h2> <ul class="menu"> <xsl:for-each select="$last/rss/channel/item[position() < 5]"> <xsl:variable name="artist"><xsl:value-of select="substring-before(title, ' –')"/></xsl:variable> <xsl:variable name="track"><xsl:value-of select="substring-after(title, '– ')"/></xsl:variable> <xsl:variable name="api-key" select="'*******my api key*********'" /> <xsl:variable name="artist-encoded"> <xsl:call-template name="url-encode"> <xsl:with-param name="str" select="$artist"/> </xsl:call-template> </xsl:variable> <xsl:variable name="track-encoded"> <xsl:call-template name="url-encode"> <xsl:with-param name="str" select="$track"/> </xsl:call-template> </xsl:variable> <xsl:variable name="info" select="document(concat('http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=', $api-key, '&artist=', $artist-encoded, '&track=', $track-encoded))"/> <li> Artist: <xsl:value-of select="$artist"/><br /> Song: <xsl:value-of select="$track"/><br /> Album: <xsl:value-of select="$info/lfm/track/album/mbid" /><br /> Encoded Artist: <xsl:value-of select="$artist-encoded"/><br /> Encoded Song: <xsl:value-of select="$track-encoded"/><br /> </li> </xsl:for-each> </ul> </xsl:template>
Is there a better way to do this? I'm still new and am sure my code though working is hackish at best
Create an account or sign in to comment.
Hello All,
I am having some trouble and thought I would ask the experts. What I'me doing is using my Last FM rss feed to display the artist and title of the song... easy and done. I'm then passing them to the Last FM API to return info about the album; image,name, id etc.
Everything works fine for artists/song containing no spaces or odd characters as shown at the link below with the first two artists but anything else dies:
http://blog.devkinetic.com/music/
here is my XSLT:
I realize if the external feeds go down the page will break, once this is working I will transfer it over to a locally cached feed.