title: Find and replace for the particular texts within same text() node, more than once
body: <p>Please suggest to find replace the required text within one text() node, some times find-replace text repeated more than once.</p>
  
  <p>Here, scripts should exclue the element '&lt;p&gt;'. Working fine when 'find' text occuring only once in a text node, if it occures more than once, then skipping the replace process (see first &lt;p1>). Please suggest.</p>
  
  <p><strong>XML:</strong></p>
  
  <pre><code>&lt;article&gt;
  &lt;p1&gt;The text 1111, 2222, 3333 and 4444 are some values, 1111 another occurance.&lt;/p1&gt;
  &lt;p1&gt;The text 1111, 2222, 3333 and 4444 are some values&lt;/p1&gt;
  &lt;p&gt;The text 1111, 2222, 3333 and 4444 are some values&lt;/p&gt;
  &lt;p1&gt;The text aaaaa, bbbbb, ccccc and ddddd are another set of values&lt;/p1&gt;
  &lt;p1&gt;The text &lt;i&gt;aaaaa&lt;/i&gt;, &lt;b&gt;bbbbb&lt;/b&gt;  and &lt;c&gt;ccccc&lt;/c&gt; are in different form&lt;/p1&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p><strong>XSLT 2.0:</strong></p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;&lt;xsl:apply-templates select="@* | node()"/&gt;&lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="*/text()"&gt;
      &lt;xsl:call-template name="tempFindReplace"&gt;
          &lt;xsl:with-param name="pText1" select="."/&gt;
      &lt;/xsl:call-template&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="tempFindReplace"&gt;
      &lt;xsl:param name="pText1"/&gt;
      &lt;xsl:if test="string-length($pText1) &gt; 0"&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="ancestor::p1"&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="contains($pText1, '1111')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'1111')"/&gt;&lt;xsl:text&gt;Alpha1&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, '1111')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:when test="contains($pText1, '2222')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'2222')"/&gt;&lt;xsl:text&gt;Alpha2&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, '2222')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:when test="contains($pText1, '3333')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'3333')"/&gt;&lt;xsl:text&gt;Alpha3&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, '3333')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:when test="contains($pText1, '4444')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'4444')"/&gt;&lt;xsl:text&gt;Alpha4&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, '4444')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
  
                  &lt;xsl:when test="contains($pText1, 'aaaaa')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'aaaaa')"/&gt;&lt;xsl:text&gt;Beta1&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, 'aaaaa')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:when test="contains($pText1, 'bbbbb')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'bbbbb')"/&gt;&lt;xsl:text&gt;Beta2&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, 'bbbbb')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:when test="contains($pText1, 'ccccc')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'ccccc')"/&gt;&lt;xsl:text&gt;Beta3&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, 'ccccc')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:when test="contains($pText1, 'ddddd')"&gt;
                      &lt;xsl:value-of select="substring-before($pText1,'ddddd')"/&gt;&lt;xsl:text&gt;Beta4&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;&lt;xsl:with-param name="pText1" select="substring-after($pText1, 'ddddd')"/&gt;&lt;/xsl:call-template&gt;&lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:value-of select="substring($pText1,1,1)"/&gt;
                      &lt;xsl:call-template name="tempFindReplace"&gt;
                          &lt;xsl:with-param name="pText1" select="substring($pText1, 2)"/&gt;
                      &lt;/xsl:call-template&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
          &lt;xsl:value-of select="."/&gt;
      &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
      &lt;/xsl:if&gt; 
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>Required Result:</strong></p>
  
  <pre><code>&lt;article&gt;
  &lt;p1&gt;The text Alpha1, Alpha2, Alpha3 and Alpha4 are some values, Alpha1 another occurance.&lt;/p1&gt;&lt;!-- Alpha1 only replacing, but other texts also required change, I assume here failing because of 1111 appearing twice--&gt;
  &lt;p1&gt;The text Alpha1, Alpha2, Alpha3 and Alpha4 are some values&lt;/p1&gt;
  &lt;p&gt;The text 1111, 2222, 3333 and 4444 are some values&lt;/p&gt;
  &lt;p1&gt;The text Beta1, Beta2, Beta3 and Beta4 are another set of values&lt;/p1&gt;
  &lt;p1&gt;The text &lt;i&gt;Beta1&lt;/i&gt;, &lt;b&gt;Beta2&lt;/b&gt;  and &lt;c&gt;Beta3&lt;/c&gt; are in different form&lt;/p1&gt;
  &lt;/article&gt;
  </code></pre>