Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • willhc 5 posts 22 karma points
    Apr 29, 2010 @ 16:27
    willhc
    0

    Multiple twitter feeds, using only xslt

    I have used some topics of this great forum, and now I want to share my xslt code for multiple twitter feeds.

    I hope you enjoy it!

    Here is the Date structure of twitter I treated for the code: (If some day it change, now you can format the way you want)
     Wed Apr 28 18:17:03 +0000 2010
     When splitted by " ", it became a Array of 6 elements

     


    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]><xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxml="urn:schemas-microsoft-com:xslt"
     xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:TagCloud.Helper="urn:TagCloud.Helper" xmlns:CWSHelper.twitter="urn:CWSHelper.twitter"
     exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets TagCloud.Helper CWSHelper.twitter ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">


    <xsl:variable name="MyFeeds" select="umbraco.library:GetXmlDocumentByUrl('http://twitter.com/statuses/user_timeline/itautec.xml?count=5')" /> 
    <xsl:variable name="MyFeeds2" select="umbraco.library:GetXmlDocumentByUrl('http://twitter.com/statuses/user_timeline/durafloor_.xml?count=5')" /> 

    <xsl:variable name="AllFeeds">
     
     <container>
      <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl('http://twitter.com/statuses/user_timeline/username1.xml?count=5')"/>
      <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl('http://twitter.com/statuses/user_timeline/username2.xml?count=5')"/>
     </container>
    </xsl:variable>

    <xsl:variable name="newTwitterFeedStructure">
     <xsl:for-each select="msxml:node-set($AllFeeds)/container/statuses/status">
      <xsl:sort select="created_at" order="descending" />
      <xsl:variable name="transform-http" select="Exslt.ExsltRegularExpressions:replace(text, '(http\:\/\/\S+)',ig,'&lt;a href=$1&gt;$1&lt;/a&gt;')"/>
      <xsl:variable name="transform-https" select="Exslt.ExsltRegularExpressions:replace($transform-http, '(HTTps\:\/\/\S+)',ig,'&lt;a href=$1&gt;$1&lt;/a&gt;')"/>
      <xsl:variable name="transform-AT" select="Exslt.ExsltRegularExpressions:replace($transform-https, '(^|\s)@(\w+)',ig,' &lt;a href=http://www.twitter.com/$2&gt;@$2&lt;/a&gt;')"/>
      <xsl:variable name="transform-HASH" select="Exslt.ExsltRegularExpressions:replace($transform-AT, '(^|\s)#(\w+)',ig,' &lt;a href=http://www.twitter.com/search?q=$2&gt;#$2&lt;/a&gt;')"/>


      <!-- formating DateTime -->

      <xsl:variable name="Datefield" select="umbraco.library:Split(created_at,' ')"/>
      <xsl:value-of select="$Datefield/value[2]"/>
      <xsl:variable name="mes">
      <xsl:choose>
       <xsl:when test="$Datefield/value[2]='Jan'">
        <xsl:value-of select="01"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='Feb'">
        <xsl:value-of select="02"/>
       </xsl:when>  
       <xsl:when test="$Datefield/value[2]='Mar'">
        <xsl:value-of select="03"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='Apr'">
        <xsl:value-of select="04"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='May'">
        <xsl:value-of select="05"/>
       </xsl:when>  
       <xsl:when test="$Datefield/value[2]='Jun'">
        <xsl:value-of select="06"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='Jul'">
        <xsl:value-of select="07"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='Aug'">
        <xsl:value-of select="08"/>
       </xsl:when>  
       <xsl:when test="$Datefield/value[2]='Sep'">
        <xsl:value-of select="09"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='Oct'">
        <xsl:value-of select="10"/>
       </xsl:when>
       <xsl:when test="$Datefield/value[2]='Nov'">
        <xsl:value-of select="11"/>
       </xsl:when>
      
       <xsl:otherwise>
        <xsl:value-of select="12"/>

       </xsl:otherwise>
      </xsl:choose>
      </xsl:variable>


     
      <xsl:variable name="FinalDate" select="concat(concat(concat(concat(concat(concat($Datefield/value[3],'/'),$mes),'/'),$Datefield/value[6]),' '),$Datefield/value[4])"/>

    <!-- Creating the xml string for sort by datetime -->


      <xsl:element name="feed">
       <xsl:element name="feeddate"><xsl:value-of select="$FinalDate"/></xsl:element>
       <xsl:element name="Textfield">
       
    <a href="http://www.twitter.com/{user/name}"><xsl:value-of select="user/name" /></a> às <xsl:value-of select="umbraco.library:FormatDateTime($FinalDate,'dd-MM-yyyy HH:mm:ss')"/>: <xsl:value-of select="$transform-HASH" disable-output-escaping="yes"/>
       
       </xsl:element>
      </xsl:element>
    </xsl:for-each>
    </xsl:variable>

    <!-- sorting by datetime -->

    <xsl:for-each select="msxml:node-set($newTwitterFeedStructure)/feed">
     <xsl:sort select="umbraco.library:FormatDateTime(feeddate,'yyyy-MM-dd HH:mm:ss')" order="descending" />
     <p>
     <xsl:value-of select="Textfield" disable-output-escaping="yes"/>
     <br/>
     </p>
    </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>

     

  • willhc 5 posts 22 karma points
    Apr 29, 2010 @ 16:32
    willhc
    0

    Ups...

    You don´t need the MyFeeds and MyFeeds2 Variables line!

    Its just unuseful, but it works anyway!

     

    cheers,

    willhc

  • Andre 6 posts 26 karma points
    Feb 15, 2011 @ 10:45
    Andre
    0

    Thanks for sharing, I'll give it a try as I need to merge several feeds from the same source and display them on the document sorted by date.

    Cheers.

Please Sign in or register to post replies

Write your reply to:

Draft