title: XSLT 1.0 multiple call of a template
body: <p>I need to replace strings in an XML file. I'm trying to use XSLT to do it. I want to use call-template for each string I need to replace. </p>
  
  <p>When I make multiple call to the template, only the last call works fine. </p>
  
  <p>The XML file I need to change : I want to replace the strings </p>
  
  <pre><code>&amp;#145;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>&amp;#151;
  </code></pre>
  
  <p>by spaces</p>
  
  <pre><code>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RAPPORT&gt;
      &lt;reason&gt;start test_145 : &amp;#145; and test_ 151 : &amp;#151; _end_test&lt;/reason&gt;
  &lt;/RAPPORT&gt;
  
  </code></pre>
  
  <p>The template I use :</p>
  
  <pre><code>
      &lt;xsl:template name="globalReplace"&gt;
          &lt;xsl:param name="outputString"/&gt;
          &lt;xsl:param name="target"/&gt;
          &lt;xsl:param name="replacement"/&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="contains($outputString,$target)"&gt;
                  &lt;xsl:value-of select="concat(substring-before($outputString,$target),$replacement)"/&gt;
                  &lt;xsl:call-template name="globalReplace"&gt;
                      &lt;xsl:with-param name="outputString" select="substring-after($outputString,$target)"/&gt;
                      &lt;xsl:with-param name="target" select="$target"/&gt;
                      &lt;xsl:with-param name="replacement" select="$replacement"/&gt;
                  &lt;/xsl:call-template&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:value-of select="$outputString"/&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt; 
  
  </code></pre>
  
  <p>The multiple calls : </p>
  
  <pre><code>
      &lt;xsl:template match="text()"&gt;
          &lt;xsl:call-template name="globalReplace"&gt;
              &lt;xsl:with-param name="outputString" select="."/&gt;
              &lt;xsl:with-param name="target" select="'&amp;#145;'"/&gt;
              &lt;xsl:with-param name="replacement" select="' '"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="text()"&gt;
          &lt;xsl:call-template name="globalReplace"&gt;
              &lt;xsl:with-param name="outputString" select="."/&gt;
              &lt;xsl:with-param name="target" select="'&amp;#151;'"/&gt;
              &lt;xsl:with-param name="replacement" select="' '"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:template&gt;
  
  </code></pre>
  
  <p>Expected result : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RAPPORT&gt;
      &lt;reason&gt;debut test_test_145  et test 151 _fin test&lt;/reason&gt;
  &lt;/RAPPORT&gt;
  </code></pre>
  
  <p>What I get in fact : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RAPPORT&gt;
      &lt;reason&gt;debut test_test_145**PUI** et test 151 _fin test&lt;/reason&gt;
  &lt;/RAPPORT&gt;
  </code></pre>
  
  <p><strong>PUI</strong> means an unexpected character instead of the needed space</p>