Copied to clipboard

Flag this post as spam?

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


  • BarneyHall 141 posts 210 karma points
    Nov 30, 2011 @ 10:53
    BarneyHall
    0

    Reading external feedburner xml

    Hello peeps, always having struggled in this area I wonder if anyone can help me with a function I'm trying to perform.

    I'm looking to display a list of Facebook page updates on my page. Looking around the forum I've cobbled together the following, which is reading a Feedburner feed of my FB page. Trouble is I cannot grab and display the "entry" node, which when looking at the XML source is present. The only kind of display I can get is if I select the value of all nodes using the * wildcard (included as a test in my XSLT).

    This is the feed URL: http://feeds.feedburner.com/OfficialSouthEssexCollegesFacebookWall

    Here's the present XSLT:

    <?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:media="http://rssnamespace.org/feedburner/ext/1.0"
    exclude-result-prefixes="msxml umbraco.library media">
        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <!-- macroparameter with the url of the xmlfeed -->
        <xsl:variable name="url" select="/macro/url" />
        <!-- macroparameter with the number of posts from the xmlfeed to display-->
        <xsl:variable name="noOfPosts" select="/macro/noOfPosts" />

        <xsl:template match="/">
            <xsl:if test="$url != ''">
                <!--
                fetch xmlsource from url - we are unable to use select=document($url)
                but umbraco has a static function library available in xsl where there exists a
                method of fetching a xmldocument given an url
                -->
                <xsl:variable name="feedxml" select="umbraco.library:GetXmlDocumentByUrl($url)" />

                <!-- test to see that I'm getting content from feed -->
                <xsl:value-of select="$feedxml//*" />

                <ul>
                    <xsl:for-each select="$feedxml//entry">
                 
                        <xsl:if test="position() &lt;= $noOfPosts">
                            <li>
                                <a class="group" href="{link/@href}" title="{title}" target="_blank" rel="group">
                                    <xsl:value-of select="title"/>
                                </a>
                            </li>
                        </xsl:if>
                    </xsl:for-each>
                </ul>
               
            </xsl:if>
        </xsl:template>   
    </xsl:stylesheet>

    I think I'm out of my depth here so any help would be gratefully received.

    Cheers,
    Barney

     

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Nov 30, 2011 @ 21:09
    Warren Buckley
    0

    Hi Barney,
    The best way to debug and check the XML ouput you are retrieving is to ouput the value of your variable storing the XML in a similar way to that you already have done.

    Use a copy-of inside a textarea will ouput the XML you are getting.

    <textarea>
    <xsl:copy-of
    select="$feedxml//*"/>
    </textarea>

    This will help to figure out what elements you can select for your loop.

    Warren

  • BarneyHall 141 posts 210 karma points
    Dec 01, 2011 @ 10:06
    BarneyHall
    0

    Hi Wazza,

    Ok I've done this and the XML is coming through in the format I was expecting.

    Any idea why am I unable to select the <entry> nodes? I feel like all my selectors are correct?

    Here's the XML I am receiving: http://dl.dropbox.com/u/20259407/XMLFile.xml

    I'm wondering if I'm missing something with name spaces?

    Confused.

    Thanks as ever mate,
    Barney

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Dec 01, 2011 @ 10:15
    Warren Buckley
    1

    Hi Barn,
    Yep I just took a look at the remote XML you are receiving and you are spot on that its to do with namespaces.
    If you look at the remote XML the first namespace is the RSS Atom namespace which is used for the entry nodes but you can see they have not used a namespace prefix so thats why you are unable to select it with just 'entry'

    In your XSLT file at the top add underneath the other namespaces the following:

    xmlns:atom="http://www.w3.org/2005/Atom"

    And now you will be able to select the entry node like so:

    <ul>
    <xsl:for-each select="$feedxml//atom:entry">
    <xsl:if test="position() &lt;= $noOfPosts">
    <li>
    <a class="group" href="{atom:link/@href}" title="{atom:title}" target="_blank" rel="group">
    <xsl:value-of select="title"/>
    </a>
    </li>
    </xsl:if>
    </xsl:for-each>
    </ul>
  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Dec 01, 2011 @ 10:16
    Warren Buckley
    0

    Ooops forgot to update the value-of select inside the anchor tag to atom:title

  • BarneyHall 141 posts 210 karma points
    Dec 01, 2011 @ 10:23
    BarneyHall
    0

    That done the ticket!

    Thanks mate :)

Please Sign in or register to post replies

Write your reply to:

Draft