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() < 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)) < 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 > 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 > 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>
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
Comments
Leave a Comment
About dwalker
David Walker has over 15 years experience in application development with over 50% of that employed as a consultant with companies such as: Texaco, Bank of Oklahoma, Winner Communications (ESPN.com) and IBM Global Services. At the age of 14, he began his application development ambitions with a Commodore 64, BASIC, and a 300 baud modem. Even at that early age, he primarily focused on two specific application types: multi-user communities and database applications.
His hunger to learn as much as possible about development lead him through courses such as DBase III, DBase IV, Pascal, C, C++, Java, and several in UNIX. He started his development career first doing heavy processing with Access and VBA, then moved on to VB 3, Oracle, and Delphi. Visual Basic was one environment that remained constant for many years, including his very first .NET projects performed in Visual Basic.NET.
After working several years on very high end internal Corporate applications, the consultant company he was working for, sought out his ideas for actual software products that could be packaged and sold. He had already developed several prototypes of a dynamic portal application, before portals even became popular, so this became the logic decision and he became the Director of Product Development. Under his direction, a team of developers and graphic artists, took a skinning approach before that become popular, and completed the core portal application, and continued on to developer 15+ add-on modules, including things such as: Help Desk Ticket Systems, Change Control, Records Management, Human Resources, and many more applications. Eventually, it spun off into it's own separate company as KnowledgeGEAR, a complete intranet in the box solution.
Having worked as a consultant, he has had a experience with a very wide range of applications and architectures, at one time, even converting several Fox Pro and GW-Basic applications to VB 6 and ASP. His early training of Unix and the C language and years of experience with JavaScript, lead him very quickly to C#, where he has remained focused ever since.
He is the current President of the
Tulsa Developers .NET user group.. He has been an MCP since 2003 and MCAD and MCSD since 2005. He is currently pursuing his MCDBA and then on to MCSE.