Twitter Feeds in Umbraco using XSLT

There are currently two packages tagged on the Umbraco forum that can be used to add a twitter feed to your website. I was playing around with "Twitter for Umbraco" by Warren Buckley and noticed a bug in the way it converted twitter @names to links, so I thought I would try and solve this using XSLT.

It may also be useful for those of you using Darren Ferguson's "Feed Cache" package as the demo on Darren's site does not add links to the tweets.

To use this XSLT you simple call the XSLT Template passing in your Twitter message:


Then add the XSLT template to your XSLT macro (outside of the main template)

<xsl:variable name="transform-http" select="Exslt.ExsltRegularExpressions:replace($twitterfeed, '(http\:\/\/\S+)',ig,'<ahref="$1">$1</a>')"/>
<xsl:variable name="transform-https" select="Exslt.ExsltRegularExpressions:replace($transform-http, '(HTTps\:\/\/\S+)',ig,'<ahref="$1">$1</a>')"/>
<xsl:variable name="transform-AT" select="Exslt.ExsltRegularExpressions:replace($transform-https, '(^|\s)@(\w+)',ig,' <ahref="$2">@$2</a>')"/>
<xsl:variable name="transform-HASH" select="Exslt.ExsltRegularExpressions:replace($transform-AT, '(^|\s)#(\w+)',ig,' <ahref="$2">#$2</a>')"/>

You should find that this now replaces all the @names, #names and URL's with links!


Chris Houston

Chris is the founder of Vizioz and has been working in the field of website development for over 20 years. Chris has been working with Umbraco since 1998 and now spends his time running both Vizioz and QV Offices.

comments powered by Disqus