I have to format Apple RSS feeds to show the top iphone apps in a website. I downloaded XML files and thought it’d be simple to apply an stylesheet but its turning a heck of a job…
Here is the XSL iam trying to apply: pretty simple
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:im="http://itunes.apple.com/rss">
<xsl:template match="/">
<tr>
<th>ID</th>
<th>Title</th>
</tr>
<xsl:for-each select="entry">
<tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="category"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XML feeds I am trying to format can be downloaded from http://itunes.apple.com/rss/generator/ (Choose iOS Apps and click generate).
Please help on this.. the XML file does not change whatever changes I make to the XSL file, it always displays the whole contents of the XML file..
I could find only one topic on this on the Internet and it also does not has a working solution. It should be quite familiar issue if people are showing websites with i-tunes apps these days.
I think the problem you are having is with namespaces. You are not properly accounting for them in your XSLT. Looking at a sample feed, the root element is as follows:
This means that, unless otherwise specified, all elements are part of the namespace with URI “http://www.w3.org/2005/Atom”. Although you have declared this in your XSLT, you are not really using it, and your XSLT code is trying to match elements that are not part of any namespace.
There is also a problem is that your XSLT is not accounting for the feed element too. What you need to do is replace the initial template match of
<xsl:template match="/">with the followingYou xsl:for-each would then become like so
Here is the full XSLT:
This should hopefully output some results.
Note that it is often better to use template matching, rather than xsl:for-each to encourage re-use of templates, and tidier code with less indentation. This would also work