Welcome to AspAdvice Sign in | Join | Help

DotNetNuke Twitter XSL Transformation

I have become a big fan of Twitter. It helps bridge the gap between blog posts and IM. It's also a great way to keep people informed quickly and easily.

Of course, the very first thing I wanted to do was display the tweets on the various DotNetNuke sites I own and operate.

The XSLT transform that comes with DotNetNuke was pretty ugly when displaying the Twitter RSS feed, so I hacked up some modifications using Visual Studio 2008. It provides a great IDE to debug XSLTs. The only spot of this XSLT that will need tweaking for you is the TimeZone Offset (tzOffset) variable. I wanted it to display my tweets time based on my time zone CST.

Feel free to modify this to your hearts content. Let me know if you come up with any cool changes! Have fun! (You can also download it via: http://www.davidlwalker.com/Portals/1/twitter.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform>
  <xsl:output method="html" indent="yes"/>
  <xsl:template match="rss/channel">
    <xsl:for-each select="item[position() &lt; 11]">
      <div class="twitterEntry">
        <p>
          <a href="{link}">
            <xsl:call-template name="getDate">
              <xsl:with-param name="dateTime" select="pubDate" />
              <xsl:with-param name="tzOffset" select="-6" />
            </xsl:call-template>
          </a>
          -   <xsl:value-of select="substring-after(title,': ')" />
        </p>
      </div>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="getDate">
    <xsl:param name="dateTime" />
    <xsl:param name="tzOffset" />
    <xsl:value-of select="substring($dateTime,9,4)" />
    <xsl:value-of select="substring($dateTime,6,2)" />
    <xsl:text>,</xsl:text>
    <xsl:value-of select="substring($dateTime,12,6)" />
    <xsl:variable name="orighour">
      <xsl:choose>
        <xsl:when test="(number(substring($dateTime,18,2))+number($tzOffset)) &lt; 0">
          <xsl:value-of select="(12+(number(substring($dateTime,18,2))+number($tzOffset)))+12" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="number(substring($dateTime,18,2))+number($tzOffset)" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="hour">
      <xsl:choose>
        <xsl:when test="$orighour &gt; 12">
          <xsl:value-of select="number($orighour)-12" />
        </xsl:when>
        <xsl:when test="$orighour = 0">
          <xsl:value-of select="'12'" />
        </xsl:when>
        <xsl:when test="$orighour = 12">
          <xsl:value-of select="'12'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="number($orighour)-12" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="ampm" >
      <xsl:choose>
        <xsl:when test="$orighour &gt; 11">
          <xsl:value-of select="' PM'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="' AM'" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:value-of select="$hour" />
    <xsl:value-of select="substring($dateTime,20,3)" />
    <xsl:value-of select="$ampm" />
  </xsl:template>

</xsl:stylesheet>

Technorati Tags: ,,,,
Sponsor
Published Monday, January 14, 2008 8:35 PM by dwalker

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: DotNetNuke Twitter XSL Transformation

How bout a nice pic showing the results?
Tuesday, January 15, 2008 5:14 PM by Joe Brinkman

# re: DotNetNuke Twitter XSL Transformation

Many thanks for sharing this, most useful - will share if I change (other than timezone).
Sunday, March 16, 2008 4:38 PM by James

# re: DotNetNuke Twitter XSL Transformation

I had to make some changes to the hour. I change the else clause. 10am was displaying -2am
Wednesday, September 03, 2008 2:54 PM by Glenn

# re: DotNetNuke Twitter XSL Transformation

Thanks for sharing. I never tweet during business hours, so I wouldn't have found it. (Just kidding!)

What was your if?

Does anyone know if there's a good tool to share XSLT in a collaborative environment, similar to www.CodexPlex.com, etc?

Thursday, September 04, 2008 6:45 PM by dwalker

# DNN içinde Twitter

Web sitemde yaptığım güncelleme çalışmaları arasında bugünlerde yeni yeni bulaştığım twitter ile de ilgilenmeyi

Wednesday, August 19, 2009 5:07 PM by Arabellek

# DNN içinde Twitter

Web sitemde yaptığım güncelleme çalışmaları arasında bugünlerde yeni yeni bulaştığım twitter ile de ilgilenmeyi

Friday, August 21, 2009 7:21 AM by Arabellek

# Integrating Twitter into Your DNN Blog

&lt;p&gt;Here I will tell you how to integrate twitter with DNN website or DNN blog module, like our SunBlogNuke module. It will help bridge the gap between blog posts and IM. It's also a great way to ...

Sunday, September 27, 2009 8:20 AM by SunBlogNuke Team Blog

# Integrating Twitter into Your DNN Blog

&lt;p&gt;&lt;img width=&quot;522&quot; height=&quot;152&quot; border=&quot;0&quot; src=&quot;http://www.sunblognuke.net/Portals/0/SunBlogNuke/WindowsLiveWriter/IntegratingTwitterintoYourDNNBlog_1244C/ ...

Sunday, November 15, 2009 3:14 AM by SunBlogNuke Team Blog

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below