title: XSLT replacing url in text with regex
body: <p>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 <a href="https://stackoverflow.com/questions/1069092/xslt-replace-function-not-found">this</a> and <a href="https://stackoverflow.com/questions/4647746/use-custom-template-name-in-xslapply-templates">this</a> 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.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt;
      &lt;xsl:output method="text" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" /&gt;
      &lt;xsl:param name="html-content-type" /&gt;
      &lt;xsl:variable name="urlRegex" select="8"/&gt;
      &lt;xsl:template match="statuses"&gt;
          &lt;xsl:for-each select="//status[position() &amp;lt; 2]"&gt;
              &lt;xsl:variable name="TwitterMessage" select="text" /&gt;
              &lt;xsl:call-template name="replaceAll"&gt;
                  &lt;xsl:with-param name="text" select="$TwitterMessage"/&gt;
                  &lt;xsl:with-param name="replace" select="De"/&gt; &lt;!--This should become an regex to replace urls, maybe something like the rule below?--&gt;
                  &lt;xsl:with-param name="by" select="FOOOO"/&gt; &lt;!--Here I want the matching regex value to be replaced with valid html to create an href--&gt;
                  &lt;!--&lt;xsl:value-of select="replace(text,'^http://(.*)\.com','#')"/&gt;
                  &lt;xsl:value-of select="text"/&gt;--&gt;
              &lt;/xsl:call-template&gt;
              &lt;!--&lt;xsl:value-of select="text"/&gt;--&gt;
              &lt;!--&lt;xsl:apply-templates /&gt;--&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name="replaceAll"&gt;
          &lt;xsl:param name="text"/&gt;
          &lt;xsl:param name="replace"/&gt;
          &lt;xsl:param name="by"/&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="contains($text,$replace)"&gt;
                  &lt;xsl:value-of select="substring-before($text,$replace)"/&gt;
                  &lt;xsl:value-of select="$by"/&gt;
                  &lt;xsl:call-template name="replaceAll"&gt;
                      &lt;xsl:with-param name="text" select="substring-after($text,$replace)"/&gt;
                      &lt;xsl:with-param name="replace" select="$replace"/&gt;
                      &lt;xsl:with-param name="by" select="$by"/&gt;
                  &lt;/xsl:call-template&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:value-of select="$text"/&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>EDIT:
  This in an example of the xml feed.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;statuses type="array"&gt;
  &lt;status&gt;
    &lt;created_at&gt;Mon May 16 14:17:12 +0000 2011&lt;/created_at&gt;
    &lt;id&gt;10000000000000000&lt;/id&gt;
    &lt;text&gt;This is an message from Twitter http://bit.ly/xxxxx http://yfrog.com/xxxxx&lt;/text&gt;
  &lt;status&gt;
  </code></pre>
  
  <p>This is just the basic html twitter outputs on an url like below;</p>
  
  <pre><code>http://twitter.com/statuses/user_timeline.xml?screen_name=yourtwitterusername
  </code></pre>
  
  <p><strong>This text;</strong></p>
  
  <pre><code>This is an message from Twitter http://bit.ly/xxxxx http://yfrog.com/xxxxx
  </code></pre>
  
  <p><strong>Should be converted to;</strong></p>
  
  <pre><code>This is an message from Twitter &lt;a href="http://bit.ly/xxxxx&gt;http://bit.ly/xxxxx&lt;/a&gt; &lt;a href="http://yfrog.com/xxxxx"&gt;http://yfrog.com/xxxxx&lt;/a&gt;
  </code></pre>