I think you *could* get into infinite recursion (depending on the value of $Char) if you have the template call itself with
select="concat($Before, ' ', $After)"/>
Since you've already found the match, you can just call with
Also, $Char isn't a good parameter name, since we're looking for a substring. How about $SubString and the name SubStringCount for the template?