Adding a Twitter feed with SharePoint xml viewer web part

Working on sites these days you have many social feeds that need to be added to your SharePoint site. One way we have accomplished this is using the XML viewer web part.

You can add this into a web part zone on your page through your browser or you can add the web part directly to your master page. I typically don’t add this directly into a client’s master page, but for my blog I did add it directly to my master page.

Browse to your site and add the XML Viewer Web Part to your page. To make this work you need the XML Link – this will be the RSS feed/code used to pull the information from twitter. Next you need the XSL Link, this will format the tweets that you are pulling from twitter.

Getting the XML Link

First thing you need is a link for your Twitter account.  For my site I use an RSS feed and can also control the number of tweets I want to show on my site (count=3).  Since Twitter removed the RSS feed on their site you can use this link to find your RSS feed link or you can use the following code, which is just as easy.

Now that you have your feed link you can add the XML viewer web part to your page/zone and make the proper connections.

Create your Twitter.xsl File

<xsl:stylesheet xmlns:x=””
xmlns:atom=”” xmlns:georss=”” xmlns:twitter=””
exclude-result-prefixes=”ddwrt xsl cmswrt x”
xmlns:ddwrt=”” xmlns:ddwrt2=”urn:frontpage:internal”>
<xsl:output method=”html” indent=”no” />

<xsl:param name=”rss_FeedLimit”>4</xsl:param>
<xsl:output method=”html” />

<xsl:template match=”rss” xmlns:atom=”” xmlns:georss=”” xmlns:twitter=””>
<xsl:for-each select=”channel/item”>
<xsl:if test=”position() &lt;= $rss_FeedLimit”>
<xsl:call-template name=”item” />

<xsl:template name=”item”>
<xsl:variable name=”item_title” select=”description”/>
<p class=”date”>
<xsl:value-of select=”substring(pubDate, 1, 16)” />
<p class=”tweet”>
<xsl:attribute name=”title”><xsl:value-of select=”substring-after($item_title, ‘:’)” disable-output-escaping=”yes”/></xsl:attribute>
<xsl:value-of select=”substring-after($item_title, ‘:’)” disable-output-escaping=”yes”/>

Copy this code into notepad and name it twitter.xsl or yournamehere.xsl. Then upload the file to your Style Library or another library where you keep your custom xsl files. Or use this link to download the xsl file from Dropbox.

UPDATED: You will link to this file in the XSL Link part of the XML Viewer.

Using the feed count in this code you can change this number to increase or decrease the number of twitter items showing in your web part (<xsl:param name=”rss_FeedLimit”>4</xsl:param>).

For styling you can change the class for the <ul>, the date and the tweet are wrapped in a <p> tag and have their own classes as well.

Credit to Michael Mendelson for letting me show off his code.

Thanks for reading!

, , , , , , , ,

  • Martin Johansson

    Thanks for a reat blog Heather.  Being a novice I get the following error in the XML Viewer Web part.  Any help would be greatly appreciated.

    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

    • hwaterman

      After re-reading the last part of my post, it may be confusing (I will be updating my post). Make sure you link to your file in the XSL Link part of the XML viewer. I followed my same instructions and when I did that everything worked. Please let me know if you are still having issues.

  • Ben

    Hi Heather
    Thanks for this. Does the ‘Recent Tweets’ box on this page use the method you’ve described in the article?

    • hwaterman

      Hi Ben – When it was a SharePoint Blog I did use this code. We have also used this code on some client sites.

  • George

    Hi Heather,

    I’m trying this on my site. The XML Link seems to work–when I test it, it opens an xml page with my company’s info and recent tweets. When I test the XSL link, “/style library/twitter.xsl”, it opens my browser’s standard file download window to download twitter.xsl from my style library. But, I’m still getting the error Martin reported about invalid XSL or XSL Link.
    Do you have any idea what I might be doing wrong? Should I enter anything in the XML or XSL Editor text boxes?

    • hwaterman

      I updated the post after Martin had the issue. If you are still having problems, feel free to email me.

  • In the tweet, links show up as plain text. I don’t see a way around this (maybe not familiar with xsl enough) but are there any suggestions/workarounds?

  • Ricardo C.

    If you are receiving the error “The XSL specified by the XSL property or XSL Link property is not valid,…” make sure you search and replace all of the single and double quotes from the copied version with normal ones.

  • kalpesh

    Really helpful post.

    Can you please help me if I have following xml file, How can I read or display in xmlViewer webpart? or What would be the XSLT to read and display that xml file?

    XML File :

    I want to display the data of last node for e.g. in above xml file “” .

  • Sanchez

    Long shot this will be viewed after so long but getting the web part timed out error when trying to implement this. Any ideas as to why this may be happening?

    • Hi – can you tell me if you are getting the error on the whole page or just the web part? Is this a public site? Can you check the feed to see if you can access it with just the URL you are using?