Copied to clipboard

Flag this post as spam?

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


  • Eric Warren 48 posts 68 karma points
    Jul 16, 2010 @ 22:03
    Eric Warren
    0

    Reading Rss with Xslt

    I was wondering if anybody out there has some xslt code that will read an rss feed with audio files like the following. http://thesaltminechurch.podbean.com/feed/  I have been researching but can't seem to come up with anything. 

  • wolulcmit 357 posts 693 karma points
    Jul 16, 2010 @ 23:40
    wolulcmit
    0

    You could use the the runwayfeedviewer to learn how to read in rss feeds and display content how you like
    I did this just now. as a quick butcher/hack job to see what I could get working
    take a look: http://www.cssandstuff.com/quicktest?alttemplate=audiofeed

    install runway and have a look through runwayfeedviewer.xslt

    - Tim

     

  • wolulcmit 357 posts 693 karma points
    Jul 16, 2010 @ 23:48
    wolulcmit
    0

    Last FM for umbraco would probably give you a pretty good test case for what you're trying to acheive also
    http://our.umbraco.org/projects/website-utilities/lastfm-for-umbraco

  • jc 64 posts 101 karma points
    Jul 17, 2010 @ 02:29
    jc
    0

    umbraco.library:GetXmlDocumentByUrl should be able to read in the RSS feed. With that you could create a macro that has two parameters:

    1. Url (text)
    2. NumberOfItems (number)

    This XSLT should then parse out the MP3 links:

    <?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:umbraco.library="urn:umbraco.library"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        exclude-result-prefixes="umbraco.library">
        
        <xsl:output method="xml" omit-xml-declaration="yes" />
        
        <!-- Parameters -->
        <xsl:param name="currentPage" />
        
        <!-- Variables -->
        <xsl:variable name="Url" select="/macro/Url" />
        <xsl:variable name="NumberOfItems" select="/macro/NumberOfItems" />
        
        <!-- Template: / -->
        <xsl:template match="/">
            <xsl:choose>
                <xsl:when test="$Url != ''">
                    <xsl:variable name="Feed" select="umbraco.library:GetXmlDocumentByUrl($Url)" />
                    <h1>MP3s</h1>
                    <ul>
                        <xsl:for-each select="$Feed//item">
                            <xsl:if test="position() &lt;= $NumberOfItems">
                                <xsl:apply-templates select="." />
                            </xsl:if>
                        </xsl:for-each>
                    </ul>
                </xsl:when>
                <xsl:otherwise>
                    <p>No blog posts available</p>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        
        <!-- Template: item -->
        <xsl:template match="item">
            <li>
                <a href="{enclosure/@url}"><xsl:value-of select="enclosure/@url" /></a>
            </li>
        </xsl:template>
        
    </xsl:stylesheet>

     

  • jc 64 posts 101 karma points
    Jul 17, 2010 @ 02:37
    jc
    0

    Forgot to mention that you would also need to include the macro on the template you wanted to render to.

  • Eric Warren 48 posts 68 karma points
    Jul 19, 2010 @ 14:40
    Eric Warren
    0

    Tim,

    I was wondering if there was a way to install just the feed viewer xslt rather than the whole project.  Or if there is a place where I can grab the code for the feed viewer.

     

     

  • wolulcmit 357 posts 693 karma points
    Jul 19, 2010 @ 14:44
    wolulcmit
    2

    here's the one I hacked for the quicktest example:

    <?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">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:variable name="numberOfItems" select="10" />
    <xsl:variable name="excerptLength" select="200" />

    <xsl:variable name="feed" select="string('http://thesaltminechurch.podbean.com/feed/')"/>
    <!-- cache for 30 minutes (1.800 seconds) -->
    <xsl:variable name="cacheRate" select="number(1800)"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
    <xsl:choose>
    <xsl:when test="$feed != ''">
    <xsl:variable name="feedContent" select="umbraco.library:GetXmlDocumentByUrl($feed, number($cacheRate))"/>
    <xsl:choose>
    <xsl:when test="$feedContent != 'error'">
    <xsl:call-template name="renderFeed">
    <xsl:with-param name="feedContent" select="$feedContent"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <p>
    <strong>Feed Viewer Macro Error: Error fetching feed</strong><br />
    The feed '<xsl:value-of select="$feed"/>' could not be loaded. Verify that the feed url exists and that you have an
    active internet connection
    </p>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
    <p>
    <strong>Feed Viewer Macro Error: No feed chosen</strong><br />
    Please make sure to add a value in the "Feed Url" parameter
    </p>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="renderFeed">
    <xsl:param name="feedContent"/>
    <xsl:if test="count($feedContent//item) &gt; 0">
    <ul class="feedList">
    <xsl:for-each select="$feedContent//item">
    <xsl:if test="position() &lt;= $numberOfItems">
    <li>
    <small><xsl:value-of select="umbraco.library:LongDate(pubDate)"/></small>
    <h4>
    <a href="{link}">
    <xsl:value-of select="title" disable-output-escaping="yes"/>
    </a>
    </h4>
    <xsl:choose>
    <xsl:when test="string($excerptLength) != '0'">
    <p>
    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(description), number($excerptLength), '...')" disable-output-escaping="yes"/>
    </p>
    </xsl:when>
    <xsl:otherwise>
    <!-- <xsl:value-of select="description" disable-output-escaping="yes"/> -->
    </xsl:otherwise>
    </xsl:choose>

    </li>
    </xsl:if>
    </xsl:for-each>
    <li class="last"><xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;</li>
    </ul>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    and here's the original from runway

    <?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">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:variable name="numberOfItems">
    <xsl:choose>
    <xsl:when test="/macro/numberOfItems != ''">
    <xsl:value-of select="/macro/numberOfItems"/>
    </xsl:when>
    <xsl:otherwise>10</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="excerptLength">
    <xsl:choose>
    <xsl:when test="string(/macro/excerptLength) != ''">
    <xsl:value-of select="/macro/excerptLength"/>
    </xsl:when>
    <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="feed" select="/macro/feedUrl"/>
    <!-- cache for 30 minutes (1.800 seconds) -->
    <xsl:variable name="cacheRate" select="number(1800)"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
    <xsl:choose>
    <xsl:when test="$feed != ''">
    <xsl:variable name="feedContent" select="umbraco.library:GetXmlDocumentByUrl($feed, number($cacheRate))"/>
    <xsl:choose>
    <xsl:when test="$feedContent != 'error'">
    <xsl:call-template name="renderFeed">
    <xsl:with-param name="feedContent" select="$feedContent"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <p>
    <strong>Feed Viewer Macro Error: Error fetching feed</strong><br />
    The feed '<xsl:value-of select="$feed"/>' could not be loaded. Verify that the feed url exists and that you have an
    active internet connection
    </p>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
    <p>
    <strong>Feed Viewer Macro Error: No feed chosen</strong><br />
    Please make sure to add a value in the "Feed Url" parameter
    </p>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="renderFeed">
    <xsl:param name="feedContent"/>
    <xsl:if test="count($feedContent//item) &gt; 0">
    <ul class="feedList">
    <xsl:for-each select="$feedContent//item">
    <xsl:if test="position() &lt;= $numberOfItems">
    <li>
    <small><xsl:value-of select="umbraco.library:LongDate(pubDate)"/></small>
    <h4>
    <a href="{link}">
    <xsl:value-of select="substring(title, 10)" disable-output-escaping="yes"/>
    </a>
    </h4>
    <xsl:choose>
    <xsl:when test="string($excerptLength) != '0'">
    <p>
    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(description), number($excerptLength), '...')" disable-output-escaping="yes"/>
    </p>
    </xsl:when>
    <xsl:otherwise>
    <!-- <xsl:value-of select="description" disable-output-escaping="yes"/> -->
    </xsl:otherwise>
    </xsl:choose>

    </li>
    </xsl:if>
    </xsl:for-each>
    <li class="last"><xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;</li>
    </ul>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>
  • Eric Warren 48 posts 68 karma points
    Jul 19, 2010 @ 15:07
    Eric Warren
    0

    Tim,

    Thanks for your fast response.  I copy the code above for the test example you used.  I had to place the url in the feedUrl but when i go to render it gives the error "Feed Viewer Macro Error: No feed chosen Please make sure to add a value in the "Feed Url" parameter."    Is there a certain way that the url should be placed in beside this way.

    <xsl:variable name="feed" select="/macro/www.thesaltminechurch.podbean.com/feed"/>

     

  • wolulcmit 357 posts 693 karma points
    Jul 19, 2010 @ 15:26
    wolulcmit
    0

    Yes,I went a bit crazy with my copy and pasting.... they were both the same code (have updated now though)

    you shouldn't get rid of the variable paramaters directly like I did in my quicktest.... I was just short on time.

    if you copy the 2nd lot of xslt from my previous post > create a new xslt and make sure the 'create macro' is also checked when you do it.
    then take a look at the associated macro (which will have the same name as what you gave your xslt) > click on the paremeters tab and create the following parameters

    Then when you insert your macro into a template you'll be asked for the feedurl, number of items and excerpt length which you can enter so that your xslt can do it's job.

    Failing that, install runway.... you can always remove it again after you're done looking under the hood.

Please Sign in or register to post replies

Write your reply to:

Draft