this works perfectly for just showing all the tweets, though now i need to filter the tweets on the # keys.
i have 3 table cells on the website with each need to have 2 tweets with a different # tag in it.
i got this working now. but it is extremly slow. now i set it to search the last 50 tweets (wich is to less) and it takes about 2 seconds till the page is loaded.
does anyone has any idea how to make this xslt file better? or maby know a way to load the page and then start loading the tweets when the page is already shown?
the xslt: modified from the xslt with the package!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<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:CWS.Twitter="urn:CWS.Twitter"
xmlns:georss="http://www.georss.org/georss"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets CWS.Twitter georss">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<!-- Twitter username -->
<xsl:param name="twitterUsername" select="/macro/twitterUsername" />
<xsl:variable name="filter1" select="$currentPage/ancestor-or-self::node [@level = 1]/data [@alias = 'filterWoord1']" />
<xsl:variable name="filter2" select="$currentPage/ancestor-or-self::node [@level = 1]/data [@alias = 'filterWoord2']" />
<xsl:variable name="filter3" select="$currentPage/ancestor-or-self::node [@level = 1]/data [@alias = 'filterWoord3']" />
<!-- Number of Statuses -->
<!-- Max status's we can retrieve is upto 200 -->
<xsl:param name="noStatus">50</xsl:param>
<!-- Display @replies? -->
<xsl:param name="displayReplies" select="/macro/displayReplies" />
<!-- Display map? -->
<xsl:param name="displayMaps" select="/macro/displayMaps" />
<!-- Google Maps Key -->
<xsl:param name="googleMapsAPIKey" select="/macro/googleMapsAPIKey" />
<!-- Goole Static Maps Params-->
<xsl:param name="baseURL" select="'http://maps.google.com/maps/api/staticmap'"/>
<!-- DO NOT CHANGE URL -->
<xsl:param name="zoom" select="/macro/zoom" />
<!-- Zoom level -->
<xsl:param name="size" select="/macro/size" />
<!-- Size of Map -->
<xsl:param name="mapType" select="/macro/mapType" />
<!-- roadmap, satellite, terrain, hybrid -->
<xsl:template match="/">
<!-- Twitter XML URL -->
<xsl:variable name="twitterXMLUrl" select="concat('http://twitter.com/statuses/user_timeline/', $twitterUsername ,'.xml?count=', $noStatus)"/>
<xsl:variable name="tweets" select="umbraco.library:GetXmlDocumentByUrl($twitterXMLUrl)//statuses/status"/>
<!-- Go fetch the tweets -->
<table>
<tr>
<td style="width:33%;vertical-align:top;">
<xsl:choose>
<xsl:when test="$displayReplies = 1">
<!-- Just show user's tweets only and display @replies -->
<xsl:apply-templates mode="tweet" select="$tweets [contains(Exslt.ExsltStrings:lowercase(text),Exslt.ExsltStrings:lowercase($filter1))]" >
<xsl:with-param name="filter" select="$filter1"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$displayReplies = 0">
<!-- Just show user's tweets only and DONT display @replies -->
<xsl:apply-templates mode="tweet" select="$tweets [in_reply_to_screen_name = ''] [contains(Exslt.ExsltStrings:lowercase(text),Exslt.ExsltStrings:lowercase($filter1))]" >
<xsl:with-param name="filter" select="$filter1"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</td>
<td style="width:33%;vertical-align:top;">
<xsl:choose>
<xsl:when test="$displayReplies = 1">
<!-- Just show user's tweets only and display @replies -->
<xsl:apply-templates mode="tweet" select="$tweets[contains(Exslt.ExsltStrings:lowercase(text),Exslt.ExsltStrings:lowercase($filter2))]" >
<xsl:with-param name="filter" select="$filter2"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$displayReplies = 0">
<!-- Just show user's tweets only and DONT display @replies -->
<xsl:apply-templates mode="tweet" select="$tweets [in_reply_to_screen_name = ''] [contains(Exslt.ExsltStrings:lowercase(text),Exslt.ExsltStrings:lowercase($filter2))]" >
<xsl:with-param name="filter" select="$filter2"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</td>
<td style="width:33%;vertical-align:top;">
<xsl:choose>
<xsl:when test="$displayReplies = 1">
<!-- Just show user's tweets only and display @replies -->
<xsl:apply-templates mode="tweet" select="$tweets [contains(Exslt.ExsltStrings:lowercase(text),Exslt.ExsltStrings:lowercase($filter3))]">
<xsl:with-param name="filter" select="$filter3"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$displayReplies = 0">
<!-- Just show user's tweets only and DONT display @replies -->
<xsl:apply-templates mode="tweet" select="$tweets [in_reply_to_screen_name = ''] [contains(Exslt.ExsltStrings:lowercase(text),Exslt.ExsltStrings:lowercase($filter3))]" >
<xsl:with-param name="filter" select="$filter3"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="status" mode="tweet">
<xsl:param name="filter"/>
<!-- Change the XHTML here for how you want each tweet to be displayed -->
<xsl:if test="position() < 3">
<div class="tweet{position()}">
<xsl:if test="position() = 1">
<div class="tweetHash">
<xsl:value-of select="$filter"/>
</div>
</xsl:if>
<p>
<xsl:value-of select="CWS.Twitter:FormatUrls(text)" disable-output-escaping="yes"/>
</p>
</div>
<xsl:if test="position() = 2">
<div class="tweetFollow" onclick="window.location = 'http://twitter.com/rob_bensdorp'">
<!--<img src="/images/follow.png" style="width: 30px; height: 10px;margin-top:30px;margin-left:200px;cursor:pointer;" onclick="window.location = 'http://www.twitter.com/{screen_name}'"/>-->
</div>
</xsl:if>
</xsl:if>
<!-- EXAMPLE TWEET/STATUS XML -->
<!--
<status>
<created_at>Wed Dec 09 10:45:26 +0000 2009</created_at>
<id>6493042759</id>
<text>Test tweet to check how geo info is stored Twitter XML.</text>
<source><a href="http://www.atebits.com/" rel="nofollow">Tweetie</a></source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name></in_reply_to_screen_name>
<user>
<id>9751992</id>
<name>Warren Buckley</name>
<screen_name>warrenbuckley</screen_name>
<location>iPhone: 51.559616,0.592538</location>
<description>A web developer who is based in the UK that works for Norwegian Web Agency Xeed - http://www.xeed.no</description>;
<profile_image_url>http://a1.twimg.com/profile_images/63253002/warren-buckley_normal.jpg</profile_image_url>;
<url>http://www.creativewebspecialist.co.uk</url>;
<protected>false</protected>
<followers_count>426</followers_count>
<profile_background_color>B2DFDA</profile_background_color>
<profile_text_color>333333</profile_text_color>
<profile_link_color>93A644</profile_link_color>
<profile_sidebar_fill_color>ffffff</profile_sidebar_fill_color>
<profile_sidebar_border_color>eeeeee</profile_sidebar_border_color>
<friends_count>211</friends_count>
<created_at>Sun Oct 28 11:44:59 +0000 2007</created_at>
<favourites_count>393</favourites_count>
<utc_offset>0</utc_offset>
<time_zone>London</time_zone>
<profile_background_image_url>http://s.twimg.com/a/1260214487/images/themes/theme13/bg.gif</profile_background_image_url>;
<profile_background_tile>false</profile_background_tile>
<statuses_count>5252</statuses_count>
<notifications>false</notifications>
<geo_enabled>true</geo_enabled>
<verified>false</verified>
<following>false</following>
</user>
<geo xmlns:georss="http://www.georss.org/georss">
<georss:point>51.559618 0.592546</georss:point>
</geo>
</status>
-->
</xsl:template>
<xsl:template name="map">
<xsl:param name="coordinates" />
<!--
See Google Static Maps API to customise your map
http://code.google.com/apis/maps/documentation/staticmaps/
-->
<img src="{$baseURL}?center={$coordinates}&zoom={$zoom}&size={$size}&maptype={$mapType}&markers=color:red|label:A|{$coordinates}&key={$googleMapsAPIKey}&sensor=false" />
</xsl:template>
</xsl:stylesheet>
can anyone tell from this if the problem is the downloading the tweets from twitter.com or the searching for the words?
Regarding speed, I can think of a couple of things:
Whenever possible, store the results of a function in a variable, and use the variable instead, e.g., you're calling Exslt's lowercase() function more than once with the same arguments ($filter1, $filter2 + $filter3), which could easily be cached in a variable.
The same goes for the way you're defining the filter variables themselves - 3 times you're asking the processor to go up the ancestor tree and find the node at level 1... do this instead:
Another thing could be the table rendering - generally, the browser won't start rendering a table before the closing tag has 'arrived', unless its layout has been set to 'fixed', which tells the browser that every row has the same height and distribution of cells etc.
Finally, you can easily test if the problem has to do with fetching the data by just only rendering a simple <p>test</p> in the rootnode template: Replace the match="/" with match="/DontUseMe" and create a new rootnode template:
i didnt think of those solutions yet! i enterd them and the peformance improved a bit and i used your testing code. and indeed as i expected the thing that takes long is downloading the data from twitter... since even with only the test in there it took quite long to load.
xslt twitter funcition for umbraco.
hello everyone,
i recently installed twitter for umbraco package. (http://our.umbraco.org/projects/twitter-for-umbraco)
this works perfectly for just showing all the tweets, though now i need to filter the tweets on the # keys.
i have 3 table cells on the website with each need to have 2 tweets with a different # tag in it.
i got this working now. but it is extremly slow. now i set it to search the last 50 tweets (wich is to less) and it takes about 2 seconds till the page is loaded.
does anyone has any idea how to make this xslt file better? or maby know a way to load the page and then start loading the tweets when the page is already shown?
the xslt: modified from the xslt with the package!
can anyone tell from this if the problem is the downloading the tweets from twitter.com or the searching for the words?
Regards
Nick
comon!! still 0 replies??
is this problem even solveable?
Hi Nick,
Regarding speed, I can think of a couple of things:
Whenever possible, store the results of a function in a variable, and use the variable instead, e.g., you're calling Exslt's lowercase() function more than once with the same arguments ($filter1, $filter2 + $filter3), which could easily be cached in a variable.
The same goes for the way you're defining the filter variables themselves - 3 times you're asking the processor to go up the ancestor tree and find the node at level 1... do this instead:
Another thing could be the table rendering - generally, the browser won't start rendering a table before the closing tag has 'arrived', unless its layout has been set to 'fixed', which tells the browser that every row has the same height and distribution of cells etc.
Finally, you can easily test if the problem has to do with fetching the data by just only rendering a simple <p>test</p> in the rootnode template: Replace the match="/" with match="/DontUseMe" and create a new rootnode template:
/Chriztian
hey Chriztian,
thanks for your reply.
i didnt think of those solutions yet! i enterd them and the peformance improved a bit and i used your testing code. and indeed as i expected the thing that takes long is downloading the data from twitter... since even with only the test in there it took quite long to load.
but the waiting time is accapteble now!
thank you!!
Gr
Nick
is working on a reply...