Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
DZone MVB

Links

Social

SharePoint: How to display blog feed using XML Web Part?

I wanted to show our company's blog feed on our intranet first page. There some empty space I wanted to fill somehow. I found a good solution, so there was no need for some third-party Web Parts. Also there was no need to write any additional code.

Here's my blog feed example as easy step-by-step guide.

  1. SharePoint: XML Web Part settingsMove to SharePoint page you want to add your blog feed.
     
  2. Open this page in edit view and add new Web Part called XML Web Part.
     
  3. If Web Part is added to page then open it's settings window.
     
  4. On the field XML Link insert your blog feed URL. Check out if link is correct and content is receivable by clicking the link titled as Test Link.
     
  5. Push button titled as [XSL Editor].
     
  6. XSL editing window is opened and now insert XSL code given below. When inserted click [OK].
     
  7. If everything is okay then you should see your blog's last titles as bulleted list.
     
  8. If you see your blog entries in bulleted list then it is okay to save edited page.
     
     

XSL you need is here. Take it using copy and paste.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="xsl">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="/">
        <div>
           <xsl:apply-templates select="rss/channel"/>
        </div>
    </xsl:template>
    <xsl:template match="rss/channel">
        <xsl:variable name="link" select="link"/>
        <xsl:variable name="description" select="description"/>

        <ul><xsl:apply-templates select="item"/></ul>
    </xsl:template>
    <xsl:template match="item">
        <xsl:variable name="item_link" select="link"/>
        <xsl:variable name="item_title" select="description"/>
        <li>
            <a href="{$item_link}" title="{$item_title}"><xsl:value-of select="title"/></a>
        </li>
    </xsl:template>
</xsl:stylesheet>

The result I got in my company's intranet is here.

Posted: Jan 02 2008, 06:09 PM by DigiMortal | with 62 comment(s)
Filed under:

Comments

Brian said:

I don't see the error message anymore but I only see a bullet and don't see the content of the feed.  

# January 16, 2008 5:18 PM

DigiMortal said:

Hi Brian!

There are different versions of RSS and other feed formats. My example should work with RSS 2. If you need wider support for feed formats you can replace this XSL with more complete XSL that can handle many different formats.

# January 17, 2008 5:20 AM

Brian said:

Hi Gunnar,

Thanks for your replay.

# January 17, 2008 11:06 AM

Creating RSS Feed Web Parts for WSS 3.0 « The WorkerThread Blog said:

Pingback from  Creating RSS Feed Web Parts for WSS 3.0 &laquo; The WorkerThread Blog

# February 11, 2008 11:20 AM

SharePoint: How to display blog feed using XML Web Part? - PeteStilgoe.com said:

Pingback from  SharePoint: How to display blog feed using XML Web Part? - PeteStilgoe.com

# March 11, 2008 8:24 AM

Walter Parrish said:

When I enter feeds.feedburner.com/gunnarpeipman?format=xml">feeds.feedburner.com/gunnarpeipman or feeds.feedburner.com/gunnarpeipman I receive the following error.

Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator.

Any ideas?

# April 29, 2008 2:13 PM

DigiMortal said:

You should insert full URL of feed.

# April 29, 2008 4:46 PM

Irene said:

Thanks. helped me out alot.

www.portabledisplaysystems.com

# July 1, 2008 5:36 PM

Chris said:

Thanks for this tip. Just tried it out and it worked perfectly!

# September 8, 2008 1:12 AM

Vinicius Paluch said:

Great!

I also had a problem "Webpart content expired". This issue was resolved by adding proxy configurations to my web.config.

Thanks for the helpful tutorial.

# October 28, 2008 3:26 PM

Mark said:

I'm having a problem like Walter Parrish above. The URL to the feed doesn't end in .xml, it's listview.aspx?List={GUID} instead. (It's a blog within the Sharepoint Site) When I click test link, IE7 renders the feed properly, but when I click OK in the edit shared web part box, I get the same "Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator." error message as Walter Parrish.

# November 3, 2008 6:28 PM

Mark said:

I figured it out, it's a security issue and has to do with Anonymous Access. I wrote it up and linked it to my name here in the comments, because I got info for 3 or 4 other websites and linked to them all in the post.

You need to have Anonymous Access enabled for the whole site where the blog is located. Libraries & Lists gave a different error (blank box).

Anonymous access first has to be enabled in Central Site Admin, and then managed for each site, unless you have inherit turned on for all of them. You can set your main site (root site?) to allow anonymous access to: nothing and then change just the child site where the blog is to "entire site" and that made it work.

Link: www.docjelly.com/.../PermaLink,guid,3bdcdd7d-4870-4e8d-bb58-75da62a5cf23.aspx

Cheers and thanks Gunnar for pointing the way!

-M

# November 6, 2008 11:44 AM

Matt Moore said:

Thanks, it worked!

# November 6, 2008 7:07 PM

David said:

Hello,

thanks, works fine.

i have only one question. how can i create limit for dislpayed RSS items?

# January 14, 2009 9:07 AM

DigiMortal said:

To create a limit you need some xsl hacking here. Take look at <a href="incrementaldevelopment.com/.../">Parvez's Wing of the Gallery of Stupid XSL and XSLT Tricks</a>, this page may help you limiting count of items shown.

# January 19, 2009 4:33 PM

arhiderrr said:

Nice article

# February 28, 2009 1:20 PM

arhiderrr said:

Nice article

# February 28, 2009 10:14 PM

arhiderrr said:

Nice article

# March 1, 2009 6:02 AM

ioffersearch001 said:

Hii Frend

There are different versions of RSS and other feed formats. My example should work with RSS 2. If you need wider support for feed formats you can replace this XSL with more complete XSL that can handle many different formats.

<a href="http://ioffersearch.com">Ioffersearch.com Blogs - Just another Ioffersearch.com weblog</a>

Thanks

# March 5, 2009 8:43 PM

ioffersearch001 said:

Hiii

Thanks for this tip. Just tried it out and it worked perfectly! Nice instruction!,.. There are different versions of RSS and other feed formats Very Nice!,..

<a href="http://ioffersearch.com">Ioffersearch.com Blogs - Just another Ioffersearch.com weblog</a>

Thanks!...

# March 7, 2009 9:01 AM

dimcho tsanov said:

nice artical , thanks

# March 30, 2009 7:29 AM

Singh said:

Hello friends,

   I tried to add the xml webpart in wss 3.0 and added the feed url as "rss.nyalert.gov/.../NYSRSS.xml " and also added the xslt as described above.The error iam getting is ""Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator"".Can anybosy tell me the reason please?? Any help really appreciated....Thanks...

# April 17, 2009 11:28 AM

Sherry said:

Hi, I created the XLS webpart and copied the XSL scripts but got the error 'Failed to apply XSLT to the content.' Pls help. Thanks.

# May 25, 2009 4:26 AM

Stewart said:

Thanks much,

A big help.

Stewart

www.netrackservers.com

# June 16, 2009 4:02 PM

Gav said:

Is it easy to restrict the number of entries the rss brings back? I had hoped to use it for a simple bbc news feed but it is bringing back about 30 entries which is shoving everything off the bottom of the page.

This is a great little article by the way, so simple. Many thanks for publishing.

Gav

# August 10, 2009 3:58 AM

Matt :D said:

Gav,

I had the same problem, try this

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"

   xmlns:xsl="www.w3.org/.../Transform"

   exclude-result-prefixes="xsl">

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

   <xsl:template match="/">

       <div>

          <xsl:apply-templates select="rss/channel"/>

       </div>

   </xsl:template>

   <xsl:template match="rss/channel">

   <xsl:variable name="link" select="link"/>

       <xsl:variable name="description" select="description"/>

       <ul><xsl:apply-templates select="item"/></ul>

   </xsl:template>

   <xsl:template match="item">

       <xsl:variable name="item_link" select="link"/>

       <xsl:variable name="item_title" select="description"/>

<xsl:if test="position() &lt; 6">

<li>

           <a href="{$item_link}" title="{$item_title}"><xsl:value-of select="title"/></a>

       </li>

</xsl:if>

   </xsl:template>

</xsl:stylesheet>

Matt :D

# September 9, 2009 11:59 AM

Patrik said:

Hi

Is it possible to change to something else than bullets in the feed ?

# October 7, 2009 5:02 AM

DigiMortal said:

Hi Patrik!

Yes, it is possible. You have to change the XSL transform a little bit. That's it.

# October 7, 2009 8:48 AM

Charlie said:

Thanks for saying it is possible but how do you do it?

# October 27, 2009 10:41 PM

lvirden said:

When I try the original XSLT on this page, I get an error saying failed to apply xslt to content. Then I tried Matt D's xslt, and I get the error The XSL specified by the XSL property or XSL Link property is not valid, or the XSL file cannot be accessed. Make sure you have specified a valid XSL style sheet for this Web Part, or if the XSL file is linked that it can be accessed by the server. For assistance, contact your site administrator. More about making XSL files accessible

The RSS feed in question is a twitter feed. Is there something unique about them?

# November 10, 2009 3:11 PM

MGeijsberts said:

Matt :D's xslt to limit the number of items displayed works! Just be sure to write out the full link to www.w3.org.

Thanks for this tip!

# November 17, 2009 10:48 AM

Joel said:

I'm interested in using this to display recent images from a Flickr pool in Sharepoint.  I've got the code that Matt :D provided to work, and it looks quite good.  However, I haven't had any luck modifying it to be able to pull the url attribute from each item's media:thumbnail.

# November 17, 2009 2:26 PM

Francisco said:

the XML webpart works well, to display a blog post , put when hovering over the list item through the web part it displays html code - how can you hide this?

If I click on the Link it takes me to the blog post without issue

# January 11, 2010 8:43 PM

DigiMortal said:

Define media namespace also in your XSL file. This way XSL is able to "see" this namespace.

# January 22, 2010 2:43 PM

paul said:

@diimortal: Can you clarify "Define media namespace also in your XSL file. This way XSL is able to "see" this namespace"? I have the same issue.

# February 18, 2010 8:10 AM

DigiMortal said:

Hi Paul!

If you want to use elements from namespaces that are not dfined in your XSL you must add definitions of these namespaces to your XSL file.

If your XML contains tag like mymedia:imageurl then you have to add mymedia namespace also to your XSL file.

# February 18, 2010 8:47 AM

Acinnina said:

мне кажется: бесподобно.  а82ч

# February 22, 2010 1:58 PM

dotnetguts said:

Yuhoooo!!! I found this.

Thanks a ton, you made my day.

# February 23, 2010 12:01 AM

Rick said:

Hi

I keep getting 'The Web Part has timed out' message.

Any further help would be most appreciated.

Thanks.

# March 9, 2010 6:46 AM

Max said:

Hi.

still i am getting the error "Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator" while loading my blog feed rss it display with List{GUID}.What to change? i changed to Anonymous access in inetmgr still i am getting the error..Tell me some suggestion

# August 19, 2010 10:15 AM

Jason said:

Worked great!

Any way to force these links to open in a new tab/page?

# August 23, 2010 4:04 PM

Blanca said:

Any way to force these links to open in a new tab/page?

# August 30, 2010 5:38 PM

DigiMortal said:

Blanca, instead of

<a href="{$item_link}" title="{$item_title}">

use

<a href="{$item_link}" title="{$item_title}" target="_blank">

# August 30, 2010 8:13 PM

Asanka said:

This is an excellent post mate...

What if I have some kind of a requirement like this...

To display a thumbnail of each blog post with some description and have some paging capability to go through numbers and see some small part of the actual blog post.

Any idea...

Thanx

# September 21, 2010 5:50 AM

Christy said:

I'm having the same issue as Max.  

Anon. Access is turned on, yet I am still receiving the "Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator" error message.  

Anyone have any ideas?

# September 28, 2010 1:07 PM

cg said:

excellent.  thanks.

# October 1, 2010 3:31 PM

RSS Feed sharepoint new window said:

Pingback from  RSS Feed sharepoint new window

# November 2, 2010 12:56 PM

jdoe said:

Hi, I need help. Trying to create a xml blog with a menu (repeater) that shows post number and dynamically changes(datalist) based on category clicked . Any help would be appreciated. It has to be XML and I don't want to use other bloated blog applications. Just a simple example one page.

hm_team2003@hotmail.com

# November 6, 2010 10:22 AM

Pradeep said:

Hi Gunnar,

It's a nice article and the XML webpart works as RSS Viewer webpart.

Thanks & Regards

Pradeep

Bangalore

# December 2, 2010 2:24 AM

Sathish said:

Hi

I need to display feed in random number sequence. Please post

cmsathish@gmail.com

# April 30, 2011 5:58 AM

Nilesh PATIL said:

Issue Solve :

"Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator" error message.

Ans:When You Test Link, Default  it take Https:// Redirect Your URL  With Http://

# May 5, 2011 7:28 AM

John Paul Handrigan said:

This was just what I needed! Thank you.

# August 3, 2011 12:27 PM

gds said:

works great : thanx a lot

# September 14, 2011 9:53 AM

v.arunkarthik said:

how do i consume my blog's rss feeds in my asp.net site..

# September 15, 2011 7:54 AM

dejan said:

How do I gett letters like Č,Š, Ž inside.

it is windows-1250 tabels.

# September 21, 2011 9:52 AM

DigiMortal said:

Easiest way without coding something should be using XML with different character set. Other option is to download XML to server, make conversions and then produce output.

# September 21, 2011 6:28 PM

Ama said:

I am getting an error "Failed to apply XSLT to the content."

Test link is working fine.

Any Idea?

# October 18, 2011 9:50 AM

Emiliano said:

HEy, this is a great tool! But i'm getting "Failed to apply XSLT to the content." Could you help me?

# November 3, 2011 9:29 AM

Gordon said:

Thanks for this. It has been a while since I even looked at XSLT and this helped a lot.

I am restricting my article number to six articles and that is fine.

Unfortunately, the RSS feed is providing the feed in alphabetical order not date order. One of my feeds has about 100 articles and so my six items do not change often even though new articles are added.

Any pointers to sorting the XML feed before I run through this code? Or other alternatives?

This is the feed I am look at.

www.ec.gc.ca/default.asp

Thanks,

G

# November 23, 2011 11:07 AM

MrB said:

Great - works a treat

# July 13, 2012 7:04 AM

Everything I need to know about RSS and XML Viewer Web Part (WP) « Automate IT! said:

Pingback from  Everything I need to know about RSS and XML Viewer Web Part (WP) &laquo; Automate IT!

# January 4, 2013 2:44 PM