Show your Twitter log in SharePoint

About year ago I wrote how to display blog feeds in SharePoint sites using XML Web Part. Today is Twitter very popular and we can use XML Web Part to render Twitter feeds. To see how to configure XML Web Part check out blog feeds entry referred above.

This time you have to insert user Twitter feed as XML link, by example http://twitter.com/statuses/user_timeline/12358522.rss. Click XSL Editor button and insert the following XSL to dialog window.


<?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="/"
>
    <
xsl:value-of select="rss/channel/title"
/>
    <
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="owner"
>
      <
xsl:value-of select="substring(/rss/channel/title,11)"
/>
    </
xsl:variable
>
    <
xsl:variable name="item_link" select="link"
/>
    <
xsl:variable name="item_title" select="substring(description,string-length($owner)+3)"/>

    <li
>
      <
xsl:call-template name="getDate"
>
        <
xsl:with-param name="dateTime" select="pubDate"
/>
      </
xsl:call-template> |
      <a href="{$item_link}" title="{$item_title}"
>
        <
xsl:value-of select="$item_title"
/>
      </
a
>
    </
li
>
  </
xsl:template>

  <xsl:template name="getDate"
>
    <
xsl:param name="dateTime"
/>
    <
xsl:variable name="monthName"
>
      <
xsl:value-of select="substring($dateTime,9,3)"
/>
    </
xsl:variable
>
    <
xsl:variable name="day"
>
      <
xsl:value-of select="substring($dateTime,6,2)"
/>
    </
xsl:variable
>
    <
xsl:variable name="month"
>
      <
xsl:choose
>
        <
xsl:when test="$monthName = 'Jan'">01</xsl:when
>
        <
xsl:when test="$monthName = 'Feb'">02</xsl:when
>
        <
xsl:when test="$monthName = 'Mar'">03</xsl:when
>
        <
xsl:when test="$monthName = 'Apr'">04</xsl:when
>
        <
xsl:when test="$monthName = 'May'">05</xsl:when
>
        <
xsl:when test="$monthName = 'Jun'">06</xsl:when
>
        <
xsl:when test="$monthName = 'Jul'">07</xsl:when
>
        <
xsl:when test="$monthName = 'Aug'">08</xsl:when
>
        <
xsl:when test="$monthName = 'Sep'">09</xsl:when
>
        <
xsl:when test="$monthName = 'Oct'">10</xsl:when
>
        <
xsl:when test="$monthName = 'Nov'">11</xsl:when
>
        <
xsl:when test="$monthName = 'Dec'">12</xsl:when
>
      </
xsl:choose
>
    </
xsl:variable>

    <xsl:variable name="year"
>
      <
xsl:value-of select="substring($dateTime,13,4)"
/>
    </
xsl:variable>

    <xsl:variable name="time"
>
      <
xsl:value-of select="substring($dateTime,18,8)"
/>
    </
xsl:variable>

    <xsl:value-of select="concat($day,'.',$month,'.',$year,' ',$time)"
/>
  </
xsl:template
>
</
xsl:stylesheet
>

Now apply or save changes and check out the result. You should see something like this.

Twitter feed in SharePoint

If you find any bugs in this code or you know some tricks how to make this XSL shorter then please feel free to drop me a line. 🙂


One thought on “Show your Twitter log in SharePoint

Leave a Reply

Your email address will not be published. Required fields are marked *