Having probably basic troubles with images in RSS
This is an open discussion with 6 replies, filed under Troubleshooting.
Search
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> <xsl:include href="../utilities/date-time.xsl"/> <xsl:template match="/"> <rss version="2.0"> <channel> <title><xsl:value-of select="$website-name"/></title> <link><xsl:value-of select="$root"/></link> <description>A blog of inspirational work handpicked by Thomas Bates. A friendly creative from London, UK.</description> <generator>Symphony</generator> <xsl:for-each select="data/rss/entry"> <item> <title><xsl:value-of select="title"/></title> <link><xsl:value-of select="$root"/></link> <description><xsl:value-of select="body"/></description> <image> <url><xsl:value-of select="$workspace"/><xsl:text>/post-images/</xsl:text><xsl:value-of select="image/filename"/></url> <title>image</title> <link>http://www.ilovemonsters.co.uk</link> </image> <pubDate> <xsl:call-template name="format-date"> <xsl:with-param name="date" select="date"/> <xsl:with-param name="format" select="'w, d m Y T'"/> </xsl:call-template> <xsl:text>:00 </xsl:text> <xsl:value-of select="translate($timezone,':','')"/> </pubDate> <guid><xsl:value-of select="$root"/></guid> </item> </xsl:for-each> </channel> </rss> </xsl:template> </xsl:stylesheet>
That should work now.
Can we see your XML?
I guess you only need one entry from the xml right?
<rss> <section id="7" handle="articles">Articles</section> <entry id="63"> <image size="60 KB" path="/post-images" type="image/jpeg"> <filename>3796860601_24d9a1bfda_z.jpg</filename> <meta creation="2010-10-27T18:17:56+01:00" width="440" height="640" /> </image> <category> <item id="15" handle="illustration" section-handle="categories" section-name="Categories">Illustration</item> </category> <date time="18:17" weekday="3">2010-10-27</date> <body mode="formatted"><p>I really like this, from the guys at <a href="http://www.crazylabel.com/">Crazy Label</a>. Great vinyl. </p></body> <title handle="baby-treeson-tote">Baby Treeson Tote</title> </entry>
Does that help?
Since, I didn’t know what your default parameters were, I guessed values and put them in the stylesheet.
Based on the XML you posted… (I added back in the <data>
root element)
<?xml version="1.0" encoding="UTF-8"?> <data> <rss> <section id="7" handle="articles">Articles</section> <entry id="63"> <image size="60 KB" path="/post-images" type="image/jpeg"> <filename>3796860601_24d9a1bfda_z.jpg</filename> <meta creation="2010-10-27T18:17:56+01:00" width="440" height="640"/> </image> <category> <item id="15" handle="illustration" section-handle="categories" section-name="Categories">Illustration</item> </category> <date time="18:17" weekday="3">2010-10-27</date> <body mode="formatted"><p>I really like this, from the guys at <a href="http://www.crazylabel.com/">Crazy Label</a>. Great vinyl. </p></body> <title handle="baby-treeson-tote">Baby Treeson Tote</title> </entry> </rss> </data>
Here’s the XSLT. I used apply-templates instead of for-each since it’s a little more flexible.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="date-time.xsl"/> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:param name="root" select="'http://ilovemonsters.co.uk'"/> <xsl:param name="workspace" select="concat($root,'/blog/workspace')"/> <xsl:param name="website-name" select="'I Love Monsters'"/> <xsl:param name="timezone" select="'-05:00'"/> <xsl:template match="/"> <rss version="2.0"> <channel> <title> <xsl:value-of select="$website-name"/> </title> <link> <xsl:value-of select="$root"/> </link> <description>A blog of inspirational work handpicked by Thomas Bates. A friendly creative from London, UK.</description> <generator>Symphony</generator> <!-- List out entries here --> <xsl:apply-templates select="data/rss/entry"/> <!-- End of entries --> </channel> </rss> </xsl:template> <!-- Item entry template for RSS --> <xsl:template match="entry"> <item> <title> <xsl:value-of select="title"/> </title> <link> <xsl:value-of select="$root"/> </link> <description> <xsl:value-of select="body"/> </description> <image> <url> <xsl:value-of select="$workspace"/> <xsl:text>/post-images/</xsl:text> <xsl:value-of select="image/filename"/> </url> <title>image</title> <link>http://www.ilovemonsters.co.uk</link> </image> <pubDate> <xsl:call-template name="format-date"> <xsl:with-param name="date" select="date"/> <xsl:with-param name="format" select="'w, d m Y T'"/> </xsl:call-template> <xsl:text>:00 </xsl:text> <xsl:value-of select="translate($timezone,':','')"/> </pubDate> <guid> <xsl:value-of select="$root"/> </guid> </item> </xsl:template> </xsl:stylesheet>
Here’s the result that I get…
<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"> <channel> <title>I Love Monsters</title> <link>http://ilovemonsters.co.uk</link> <description>A blog of inspirational work handpicked by Thomas Bates. A friendly creative from London, UK.</description> <generator>Symphony</generator> <item> <title>Baby Treeson Tote</title> <link>http://ilovemonsters.co.uk</link> <description><p>I really like this, from the guys at <a href="http://www.crazylabel.com/">Crazy Label</a>. Great vinyl. </p></description> <image> <url>http://ilovemonsters.co.uk/blog/workspace/post-images/3796860601_24d9a1bfda_z.jpg</url> <title>image</title> <link>http://www.ilovemonsters.co.uk</link> </image> <pubDate>Wed, 27 Oct 2010 18:17:00 -0500</pubDate> <guid>http://ilovemonsters.co.uk</guid> </item> </channel> </rss>
Is that what you were looking for.
I get the same result as you but when I check the feed no image seems to show up? I’ve checked the url for the image and it’s right. Any other ideas?
@ilovemonsters - Try place the image in the description and call it from a regular image tag…
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="date-time.xsl"/> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:param name="root" select="'http://ilovemonsters.co.uk'"/> <xsl:param name="workspace" select="concat($root,'/blog/workspace')"/> <xsl:param name="website-name" select="'I Love Monsters'"/> <xsl:param name="timezone" select="'-05:00'"/> <xsl:template match="/"> <rss version="2.0"> <channel> <title> <xsl:value-of select="$website-name"/> </title> <link> <xsl:value-of select="$root"/> </link> <description>A blog of inspirational work handpicked by Thomas Bates. A friendly creative from London, UK.</description> <generator>Symphony</generator> <!-- List out entries here --> <xsl:apply-templates select="data/rss/entry"/> <!-- End of entries --> </channel> </rss> </xsl:template> <!-- Item entry template for RSS --> <xsl:template match="entry"> <item> <title> <xsl:value-of select="title"/> </title> <link> <xsl:value-of select="$root"/> </link> <description> <img src="{concat($workspace,'/post-images/',image/filename)}" alt="{title}"/> <xsl:value-of select="body"/> </description> <pubDate> <xsl:call-template name="format-date"> <xsl:with-param name="date" select="date"/> <xsl:with-param name="format" select="'w, d m Y T'"/> </xsl:call-template> <xsl:text>:00 </xsl:text> <xsl:value-of select="translate($timezone,':','')"/> </pubDate> <guid> <xsl:value-of select="$root"/> </guid> </item> </xsl:template> </xsl:stylesheet>
Create an account or sign in to comment.
Hi, would really appreciate some help with my RSS feed. Wondering whats wrong with this and why it won’t show images?
My RSS page is as follows:
A blog of inspirational work handpicked by Thomas Bates. A friendly creative from London, UK.Symphony/post-images/imagehttp://www.ilovemonsters.co.uk :00
Anyone shed some light on where I’m going wrong?
Cheers.