Copied to clipboard

Flag this post as spam?

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


  • Jonas Henriksen 32 posts 90 karma points
    Jul 27, 2009 @ 11:35
    Jonas Henriksen
    0

    Feed Cache trouble

    Hi guys,

    I needed to display an RSS feed from an external source and I found Darren Fergusons Feed Cache which seemed to be able to do the trick.

    The trouble is that Fergusons XSLT is displaying XML that looks like this:

    <feed>
        <entry>...</entry>
        <entry>...</entry>
    </feed>

    and the source of the feed I need to display looks like this:

    <rss>
        <channel>
            <item>...</item>
            <item>...</item>
        </channel>
    </rss>

    My question is: How do I customize Fergusons XSLT to display the feed above:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:Stylesheet [<!ENTITY nbsp "&#x00A0;">]>
    <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 Atom"
     xmlns:Atom="http://www.w3.org/2005/Atom">
       
        <xsl:variable name="y" select="document('../umbraco/plugins/FergusonMoriyama/FeedCache/twit.xml')/Atom:feed"/>
        <xsl:output method="xml" omit-xml-declaration="yes"/>
        <xsl:param name="currentPage"/>
       
        <xsl:template match="/">
            <xsl:for-each select="$y/Atom:entry">
                <p>
                    <em>
                        <xsl:value-of select="umbraco.library:FormatDateTime(Atom:published, 'MMMM d, yyyy @ H:mm')"/>
                    </em>
            <xsl:value-of select="Atom:content" disable-output-escaping="yes"/>
                </p>
            </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>

    The package has been installed correctly (its no problem to display Fergusons Twit feed). Hope someone can help!

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Jul 27, 2009 @ 12:57
    Sebastiaan Janssen
    0

    I have not used this package before... But you could have a look in twit.xml to see if there is a feed definition in there. If so, you can probably change "entry" into "item" and you should be good to go. If not.. then I don't know ;-)

  • Jonas Henriksen 32 posts 90 karma points
    Jul 27, 2009 @ 13:14
    Jonas Henriksen
    0

    Thanks Sebastiaan! I've already tried replacing "entry" with "item", "feed" with "rss" and included "channel" in different way - and nothing seems to work! No output... Thanks for your suggestion though! :)

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Jul 27, 2009 @ 13:17
    Sebastiaan Janssen
    0

    No problem! Oh by the way, you might also need to change the "Atom:" references to convert to rss feeds instead of atom feeds. I am not familiar with the "Atom:" notation in this XSLT though.

  • Jonas Henriksen 32 posts 90 karma points
    Jul 27, 2009 @ 13:36
    Jonas Henriksen
    0

    The feed I want to use is also an ATOM-feed - so no problem there ;)

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jul 27, 2009 @ 14:02
    Darren Ferguson
    0

    Hi Jonas, what is the URL of the feed you want to transform?

  • Daniel.S 50 posts 135 karma points
    Jul 27, 2009 @ 14:13
    Daniel.S
    100

    To me it looks like you're getting your feed types mixed up. You say that it's storing in the "<feed><entry></entry></feed>" format. That looks like an ATOM feed to me.

    I found a random ATOM feed and put together this XSLT file. Works fine for me:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <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"
      xmlns:atom="http://www.w3.org/2005/Atom"
        exclude-result-prefixes="msxml umbraco.library atom">
    
      <xsl:output method="xml" omit-xml-declaration="yes"/>
    
      <xsl:param name="currentPage"/>
      <xsl:param name="numberOfItems">
        <!--<xsl:value-of select="/macro/numberOfItems"/>-->
        <xsl:text>5</xsl:text>
      </xsl:param>
    
      <xsl:param name="dataPath">
        <xsl:value-of select="umbraco.library:RequestServerVariables('APPL_PHYSICAL_PATH')"/>
        <xsl:text>umbraco\plugins\FergusonMoriyama\feedcache\sophos-security-news.xml</xsl:text>
        <!--<xsl:value-of select="/macro/cachedFeedFile"/>-->
      </xsl:param>
    
      <xsl:param name="feedData" select="umbraco.library:GetXmlDocument($dataPath,false)"/>
    
      <xsl:template match="/">
        <div class="display-feed">
          <xsl:apply-templates select="$feedData//atom:entry [position() &lt;= $numberOfItems]"/>
        </div>
      </xsl:template>
    
      <xsl:template match="atom:entry">
        <dl>
          <a class="feed-link">
            <xsl:attribute name="href">
              <xsl:value-of select="atom:link"/>
            </xsl:attribute>
            <xsl:value-of select="atom:title"/>
          </a>
        </dl>
        <dt>
          <xsl:value-of select="umbraco.library:StripHtml(atom:summary)"/>
        </dt>
      </xsl:template>
    
    </xsl:stylesheet>
  • Daniel.S 50 posts 135 karma points
    Jul 27, 2009 @ 14:18
    Daniel.S
    1

    Forgot to mention, feedcache doesn't change the format of the feed. You can even cache ICS iCal files.

    The XSLT file for an RSS-formatted feed would be as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <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"
      xmlns:atom="http://www.w3.org/2005/Atom"
        exclude-result-prefixes="msxml umbraco.library atom">
    
      <xsl:output method="xml" omit-xml-declaration="yes"/>
    
      <xsl:param name="currentPage"/>
      <xsl:param name="numberOfItems">
        <!--<xsl:value-of select="/macro/numberOfItems"/>-->
        <xsl:text>5</xsl:text>
      </xsl:param>
    
      <xsl:param name="dataPath">
        <xsl:value-of select="umbraco.library:RequestServerVariables('APPL_PHYSICAL_PATH')"/>
        <xsl:text>umbraco\plugins\FergusonMoriyama\feedcache\sophos-security-rss-news.xml</xsl:text>
        <!--<xsl:value-of select="/macro/cachedFeedFile"/>-->
      </xsl:param>
    
      <xsl:param name="feedData" select="umbraco.library:GetXmlDocument($dataPath,false)"/>
    
      <xsl:template match="/">
        <div class="rss-feed">
          <xsl:apply-templates select="$feedData//item [position() &lt;= $numberOfItems]"/>
        </div>
      </xsl:template>
    
      <xsl:template match="item">
        <dl>
          <a class="feed-link">
            <xsl:attribute name="href">
              <xsl:value-of select="./link"/>
            </xsl:attribute>
            <xsl:value-of select="./title"/>
          </a>
        </dl>
        <dt>
          <xsl:value-of select="umbraco.library:StripHtml(./description)"/>
        </dt>
      </xsl:template>
    
    </xsl:stylesheet>
  • Jonas Henriksen 32 posts 90 karma points
    Jul 27, 2009 @ 15:54
    Jonas Henriksen
    0

    Daniel S: The feed I need to display is not <feed><entry></entry></feed> but <rss><channel><item></item></channel></rss>. I will try out your examples.

    Darren: It's located at http://helpanoutdoor.dk/rss/catalog/new/sid/1/

  • Jonas Henriksen 32 posts 90 karma points
    Jul 27, 2009 @ 15:59
    Jonas Henriksen
    0

    Thanks Daniel!!!! Worked very well! :)

Please Sign in or register to post replies

Write your reply to:

Draft