|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 777 Location: Leigh-on-Sea, Essex, UK
|
Hello all, I was wondering how I could improve speed in a semi-complex XSLT I am running. Can anyone give me some general pointers first? I am creating a Last.FM recently played mashup that displays the album art as well as the track details. Below is the XSLT code I am currently using, which works fine technically but however it is very slow when loading the page. I appreciate any feedback you could give me, to improve the speed of this XSLT mashup. Thanks, Warren Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<!-- Get macro parameter of Last.FM username --> <xsl:variable name="userID" select="/macro/userName"/>
<xsl:template match="/">
<!-- BUILD URL of recent tracks from Last.FM, passing in Last.FM username --> <xsl:variable name="recent_tracks_url" select="concat('http://ws.audioscrobbler.com/1.0/user/', $userID, '/recenttracks.xml')" />
<!-- GET XML from URL --> <xsl:variable name="recent_tracks" select="umbraco.library:GetXmlDocumentByUrl($recent_tracks_url)" />
<!-- FOR EACH track in the XML, do the following --> <xsl:for-each select="$recent_tracks//track">
<!-- Store in variables to reuse --> <xsl:variable name="artist_var" select="artist" /> <xsl:variable name="track_var" select="name" /> <xsl:variable name="date_var" select="date" />
<!-- Build up ALBUM XML URL string passing in variables from track --> <xsl:variable name="album_art_url" select="concat('http://ws.audioscrobbler.com/1.0/album/', artist, '/' ,album, '/info.xml')" />
<xsl:variable name="album_art" select="umbraco.library:GetXmlDocumentByUrl($album_art_url)" />
<!-- Check that album art contains one XML node and not an error --> <xsl:choose> <xsl:when test="count($album_art/album) = 1"> <!-- Found album art --> <img src="{$album_art//coverart/medium}" alt="{$artist_var} - {$track_var}" width="130" height="130" /> </xsl:when> <xsl:otherwise> <!-- Not found album art --> <img src="Assets/LastFM/NoImage.gif" alt="No Album Artwork ({$artist_var} - {$track_var})"/> </xsl:otherwise> </xsl:choose>
<!-- Display track info --> <p> <strong><xsl:value-of select="$track_var"/></strong> by <xsl:value-of select="$artist_var"/><br/> <em><xsl:value-of select="$date_var"/></em> </p> </xsl:for-each>
</xsl:template> </xsl:stylesheet> Warren Buckley an Umbraco MVP 08-09 & level 1 certified developer
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,698 Location: KY, USA
|
Are you sure the performance is related to your XSLT, and not the speed of the external site you're grabbing the data from? You can add some timing output around various items by using a bit of javascript code. (Take a look at xsltsearch to see how I do the timing). That is a crude way to measure performance and could help you isolate the problem. Be aware that such an approach is "server" time and not necessarily related to how long it takes to transfer/render in the client's browser. cheers, doug.
MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 790 Location: Århus, Denmark
|
How about simply adding some cache to the macro? I'm guessing that a song lasts 3 minutes on average, so maybe just caching the macro for 3 minutes would make sense, ensuring that it only fetches data when it is necessary. Another approach could be to fetch data separately. Meaning that you make one page with a usercontrol that saves the xml as a local file. This page is then called by umbracos built in timed events (in the umbracoSetting.config), and then you have your xslt macros that loops through the local file every time, ensuring that the xslt macro will never need to wait for the last.fm server...
|
|
 Rank: Administration
Joined: 7/25/2006 Posts: 415 Location: vipperoed, denmark
|
If your XSLT is slow because of the speed of the external site you're grabbing the data from and simple cashing is not an option then you could create an extension that cashed your requests? I've done this a couple of times when integrating with email (pop) and slow xml feeds with great success. Kindly, Jesper webbureau jesper.com doing webdesign / development / umbraco implementations / 2007&2008 MVP
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 777 Location: Leigh-on-Sea, Essex, UK
|
Thank you for all your suggestions I have spoken to various people recently and Per suggested using AJAX for the album art XML fetch. I have created this XSLT to use on my webblog, would anyone else be interested if I packaged this up and blog it? With a potential to be hosted in the package repo if people think it is appropriate. If your wondering what it is, I am display my recently listened tracks from my computer via the Last.FM service using a simple XML feed and XSLT, but with jQuery I am doing AJAX calls to request a new XML file in order for me to check/get the album art image url, pure mash-up! Warren Buckley an Umbraco MVP 08-09 & level 1 certified developer
|
|
 Rank: Fanatic
Joined: 10/9/2006 Posts: 419
|
i would be interested in taking a look at this... is it only xslt or is a .net solution used as well??? don't know squat about .net coding, but would love to see what ideas the xslt brought to life... thanks for your hard work!
bootnumlock - aka bob baty-barr [ http://www.baty-barr.com] Level 1 Certified!
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 777 Location: Leigh-on-Sea, Essex, UK
|
Bob The package will include the following: a XSLT macro a .NET aspx page to render remote XML to be used in conjunction with AJAX jQuery min javascript library file jQuery javascript file that uses AJAX to retrieve the album art I will try my best to package up as soon as I can. Warren Warren Buckley an Umbraco MVP 08-09 & level 1 certified developer
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 777 Location: Leigh-on-Sea, Essex, UK
|
|
|
|
Guest |