Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • phenryll 28 posts 53 karma points
    Oct 31, 2010 @ 19:08
    phenryll
    0

    Rss: displaying an image in my feed

    I'd like to insert an image in my RSS feed. This is technically feasible, but I cannot insert it.

    Here is an example of what I am talking about::

    http://www.dogglounge.com/feed/

    If I well-understood, everything is embedded inside <content:encoded/> while <description /> doesn't accept any <img /> tag.

    Any idea how to achieve this?

    Thanks

  • Sebastiaan Janssen 5045 posts 15478 karma points MVP admin hq
    Nov 01, 2010 @ 08:23
    Sebastiaan Janssen
    0

    Both the description and content node look like this in my RSS feed:

    <xsl:value-of select="concat('&lt;![CDATA[ ', umbraco.library:Replace(./data [@alias='bodyText'], '/media/', concat($siteUrl, '/media/')),']]&gt;')" disable-output-escaping="yes"/>

    It wraps the content in a CDATA tag, any images in the media folder are changed by adding the siteUrl in front of them. The siteUrl variable is defined like this:

      <xsl:variable name="siteUrl">
        <xsl:text>http://</xsl:text>;
        <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />
      </xsl:variable>
    
  • phenryll 28 posts 53 karma points
    Nov 01, 2010 @ 14:21
    phenryll
    0

    Thanks for posting ;)

    I successfully rendered the image's url:

    concat($siteUrl, photo)

    Now I need to enclose the url into an <img />:

    <img src="{concat($siteUrl, photo)}"/>

     Such tag cannot be enclosed within the content node. Do I have to insert it whitin the CDATA? How can I escape illegal characters?

    Thanks :) 

     

  • Sebastiaan Janssen 5045 posts 15478 karma points MVP admin hq
    Nov 01, 2010 @ 16:07
    Sebastiaan Janssen
    0

    Isn't  the <img> already in your bodyText? You need to add an EXTRA image in there? 

    I'd try to do the same thing then yes, with CDATA, (not sure if this will work):

    <xsl:value-of select="'&lt;![CDATA[ '/>
        <img src="{concat($siteUrl, photo)}"/>
    <xsl:value-of select="']]&gt;'"/>

     

  • phenryll 28 posts 53 karma points
    Nov 01, 2010 @ 17:16
    phenryll
    0

    The image is not in the bodyText. I get the path from my DocType's property called "photo". As I previously wrote, I successfully get the path, which I concat with the domain name.

    The code above doesn't work as value-of doesn't accept any value outside the select property :(

     

  • phenryll 28 posts 53 karma points
    Nov 01, 2010 @ 23:07
    phenryll
    0

    Here is the solution I found:

     

    <xsl:value-of select="concat('&lt;![CDATA[&lt;img src=&quot;', concat($siteUrl, photo),'&quot;/&gt;',']]&gt;')" disable-output-escaping="yes"/> 


    This is totally crazy to read. The trick was to escape illegal character, even those required by CDATA.
    concat($siteUrl, photo) returns http://www.domain.com/photo.jpg

  • Sebastiaan Janssen 5045 posts 15478 karma points MVP admin hq
    Nov 01, 2010 @ 23:20
    Sebastiaan Janssen
    0

    Hehe, glad you got it, this was going to be my next suggestion. It's messy, for sure, but it works! :-)

  • phenryll 28 posts 53 karma points
    Nov 02, 2010 @ 08:01
    phenryll
    0

    Thanks Sebastian. It was best to sleep on it, because the solution is much simpler. Take a look at the url:

    http://stackoverflow.com/questions/4072872/xslt-embedding-an-image-in-a-rss-feed

    The trick was to wrap <xsl:value-of /> inside 2 CDATA, then closing them accordingly:

    <content:encoded>
      <![CDATA[<img src="]]>
      <xsl:value-of select='$url' />
      <![CDATA[">]]>
    </content:encoded>
Please Sign in or register to post replies

Write your reply to:

Draft