Search

I’m working on creating a RSS for an events page and would like to include an image, but I can’t figure out what’s wrong with my code that’s not working. Help?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../utilities/date-time.xsl"/>
<?xml-stylesheet type="text/css" href="{$root}/workspace/css/rss.css"?>

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="data">

    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

        <channel>
            <title><xsl:value-of select="$website-name"/></title>
            <link><xsl:value-of select="$root"/></link>
            <description><xsl:value-of select="$website-name"/> Feed</description>
            <language>en-us</language>
            <generator>Symphony (build <xsl:value-of select="$symphony-version"/>)</generator>
            <atom:link href="{$root}/events/rss/" rel="self" type="application/rss+xml" />

            <xsl:for-each select="rss-calendar/entry">

                <image>
                    <link><xsl:value-of select="$root"/>/events</link>
                    <url><xsl:value-of select="$root"/>/image/1/140/0/<xsl:value-of select="event-photo/item/image/filename"/></url>
                    <title><xsl:value-of select="event-photo/alt-tag-content"/></title>
                </image>

                <item>
                    <title><xsl:value-of select="event-title"/></title>
                    <link><xsl:value-of select="$root"/>/events/#<xsl:value-of select="event-title/@handle"/>/</link>
                    <pubDate>
                        <xsl:call-template name="format-date">
                            <xsl:with-param name="date" select="publish-date"/>
                            <xsl:with-param name="format" select="'M x, Y'"/>
                        </xsl:call-template>
                            <xsl:text> </xsl:text>
                            <xsl:value-of select="translate($timezone,':','')"/>
                    </pubDate>

                    <guid><xsl:value-of select="$root"/>/events/#<xsl:value-of select="event-title/@handle"/>/</guid>

                    <description>
                            <xsl:call-template name="format-date">
                                <xsl:with-param name="date" select="event-date/date/start"/>
                                <xsl:with-param name="format" select="'M x, Y'"/>
                            </xsl:call-template> | 
                            <xsl:call-template name="format-time">
                                <xsl:with-param name="time" select="event-date/date/start/@time"/>
                                <xsl:with-param name="format" select="'t'"/>
                            </xsl:call-template> - 
                            <xsl:call-template name="format-time">
                                <xsl:with-param name="time" select="event-date/date/end/@time"/>
                                <xsl:with-param name="format" select="'t'"/>
                            </xsl:call-template>
                            <xsl:value-of select="event-location"/>, <xsl:value-of select="event-directions-link"/>
                            <xsl:value-of select="event-info"/>
                            <xsl:value-of select="event-rsvp-link"/>
                    </description>
                </item>

            </xsl:for-each>

        </channel>

    </rss>

</xsl:template>

</xsl:stylesheet>

Define “not working”… are you not seeing the output you expect? Is the feed not validating?

AFAIK you can only have one image per feed, because it’s the image for the channel as a whole, not one for each item. So having it inside your for-each loops seems like it could cause problems.

Sorry, when I get frustrated a tend to blurt out “Someone else solve it for me!”.

The channel/item issue DID point me in the right direction, however I’ve run into a new problem… well, pretty much the same problem:

I got rid of everything Image and setup the enclosure tag instead, so my for-each is the following:

<enclosure url="{$root}/image/1/140/0/images/{event-photo/item/image/filename}" length="{event-photo/item/image/@size}" type="{event-photo/item/image/@type}" />

Only the image is broken despite the length, type and link data come through just fine. The SRC for the image comes back as src=”feed:///icon32/jpg”

Why don’t you put it in the ‘description’ element (and do some “encoding” by hand)? This is working for me, like so:

<description>
    <xsl:if test="image">
        <xsl:text>&lt;p&gt;</xsl:text>
        <xsl:text>&lt;img src="</xsl:text>
        <xsl:value-of select="$root"/>
        <xsl:text>/image/2/216/134/5</xsl:text>
        <xsl:value-of select="image/@path"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="image/filename"/>
        <xsl:text>" width="216" height="134" alt="" /&gt;</xsl:text>
        <xsl:text>&lt;/p&gt;</xsl:text>
    </xsl:if>
    <xsl:value-of select="text"/>
</description>

BRILLIANT! Thanks Michael!

:-)

Create an account or sign in to comment.

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