I've got an xml feed coming from Twitter which I want to transform using XSLT. What I want the xslt to do is to replace every occuring URL in an twittermessage. I've already created the following xslt template using this and this topic here on stackoverflow. How can I achieve this? If I use the template as below i'm getting an infinite loop but I don't see where. As soon as I comment out the call to the 'replaceAll'-template everything seem to work, but then ofcourse no content of the twittermessage gets replaced. I'm new to XSLT so every bit of help is welcome.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="text" omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<xsl:param name="html-content-type" />
<xsl:variable name="urlRegex" select="8"/>
<xsl:template match="statuses">
<xsl:for-each select="//status[position() < 2]">
<xsl:variable name="TwitterMessage" select="text" />
<xsl:call-template name="replaceAll">
<xsl:with-param name="text" select="$TwitterMessage"/>
<xsl:with-param name="replace" select="De"/> <!--This should become an regex to replace urls, maybe something like the rule below?-->
<xsl:with-param name="by" select="FOOOO"/> <!--Here I want the matching regex value to be replaced with valid html to create an href-->
<!--<xsl:value-of select="replace(text,'^http://(.*)\.com','#')"/>
<xsl:value-of select="text"/>-->
</xsl:call-template>
<!--<xsl:value-of select="text"/>-->
<!--<xsl:apply-templates />-->
</xsl:for-each>
</xsl:template>
<xsl:template name="replaceAll">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="replaceAll">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
EDIT: This in an example of the xml feed.
<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
<created_at>Mon May 16 14:17:12 +0000 2011</created_at>
<id>10000000000000000</id>
<text>This is an message from Twitter http://bit.ly/xxxxx http://yfrog.com/xxxxx</text>
<status>
This is just the basic html twitter outputs on an url like below;
http://twitter.com/statuses/user_timeline.xml?screen_name=yourtwitterusername
This text;
This is an message from Twitter http://bit.ly/xxxxx http://yfrog.com/xxxxx
Should be converted to;
This is an message from Twitter <a href="http://bit.ly/xxxxx>http://bit.ly/xxxxx</a> <a href="http://yfrog.com/xxxxx">http://yfrog.com/xxxxx</a>