title: XSLT - replace specific content of the text() node with a new node
body: <p>I have a xml like this,</p>
  
  <pre><code> &lt;doc&gt;
      &lt;p&gt;Biological&lt;sub&gt;89&lt;/sub&gt; bases&lt;sub&gt;4456&lt;/sub&gt; for&lt;sub&gt;8910&lt;/sub&gt; sexual&lt;sub&gt;4456&lt;/sub&gt;
              differences&lt;sub&gt;8910&lt;/sub&gt; in&lt;sub&gt;4456&lt;/sub&gt; the brain exist in a wide range of
          vertebrate species, including chickens&lt;sub&gt;8910&lt;/sub&gt; Recently&lt;sub&gt;8910&lt;/sub&gt; the
              dogma&lt;sub&gt;8910&lt;/sub&gt; of&lt;sub&gt;4456&lt;/sub&gt; hormonal dependence for the sexual
          differentiation of the brain has been challenged.&lt;/p&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>As you can see there are <code>&lt;sub&gt;</code> nodes and <code>text()</code> node contains inside the <code>&lt;p&gt;</code> node. and every <code>&lt;sub&gt;</code> node end, there is a text node, starting with a space. (eg: <code>&lt;sub&gt;89&lt;/sub&gt; bases</code> : here before 'bases' text appear there is a space exists.) I need to replace those specific spaces with  nodes.</p>
  
  <p>SO the expected output should look like this,</p>
  
  <pre><code>&lt;doc&gt;
      &lt;p&gt;Biological&lt;sub&gt;89&lt;/sub&gt;&lt;s/&gt;bases&lt;sub&gt;4456&lt;/sub&gt;&lt;s/&gt;for&lt;sub&gt;8910&lt;/sub&gt;&lt;s/&gt;sexual&lt;sub&gt;4456&lt;/sub&gt;
          &lt;s/&gt;differences&lt;sub&gt;8910&lt;/sub&gt;&lt;s/&gt;in&lt;sub&gt;4456&lt;/sub&gt;&lt;s/&gt;the brain exist in a wide range of
          vertebrate species, including chickens&lt;sub&gt;8910&lt;/sub&gt;&lt;s/&gt;Recently&lt;sub&gt;8910&lt;/sub&gt;&lt;s/&gt;the
          dogma&lt;sub&gt;8910&lt;/sub&gt;&lt;s/&gt;of&lt;sub&gt;4456&lt;/sub&gt;&lt;s/&gt;hormonal dependence for the sexual
          differentiation of the brain has been challenged.&lt;/p&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>to do this I can use regular expression like this,</p>
  
  <pre><code>&lt;xsl:template match="p/text()"&gt;
          &lt;xsl:analyze-string select="." regex="(&amp;#x20;)"&gt;
              &lt;xsl:matching-substring&gt;
                  &lt;xsl:choose&gt;
                      &lt;xsl:when test="regex-group(1)"&gt;
                          &lt;s/&gt;
                      &lt;/xsl:when&gt;                
                  &lt;/xsl:choose&gt;
              &lt;/xsl:matching-substring&gt;
              &lt;xsl:non-matching-substring&gt;
                  &lt;xsl:value-of select="."/&gt;
              &lt;/xsl:non-matching-substring&gt;
          &lt;/xsl:analyze-string&gt;
      &lt;/xsl:template&gt;
  </code></pre>
  
  <p>But this adds <code>&lt;s/&gt;</code> nodes to every spaces in the text() node. But I only need thi add  nodes to that specific spaces.</p>
  
  <p>Can anyone suggest me a method how can I do this.. </p>