title: using regex for string replacement in XSLT
body: <p>I am using datapower xi50 and following is my input xml</p>
  
  <pre><code>&lt;Sample&gt;
  &lt;AccountNumber&gt;37289882&lt;/AccountNumber&gt;
  &lt;SortCode&gt;789-88-8907&lt;/SortCode&gt;
  &lt;CardNumber&gt;4545-6767-9876-8764&lt;/CardNumber&gt;
  &lt;address&gt;j-89-8999&lt;/address&gt;
  &lt;/Sample&gt;
  </code></pre>
  
  <p>I have to get the following output</p>
  
  <pre><code>&lt;Sample&gt;
      &lt;AccountNumber&gt;37289882&lt;/AccountNumber&gt;
      &lt;SortCode&gt;789-xx-xxxx&lt;/SortCode&gt;
      &lt;CardNumber&gt;4545-xxxx-xxxx-xxxx&lt;/CardNumber&gt;
      &lt;address&gt;j-89-8999&lt;/address&gt;
      &lt;/Sample&gt;
  </code></pre>
  
  <p>in particular whenever we have the following format--</p>
  
  <pre><code>678-87-2827(3 number-2 number-4 number)
   5253-2626-9808-8787(4 number-4 number-4 number-4 number)
  </code></pre>
  
  <p>we have to change it to </p>
  
  <pre><code>678-xx-xxxx
    5253-xxxx-xxxx-xxxx
  </code></pre>
  
  <p>Following is what I am doing</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:dp="http://www.datapower.com/extensions"
  xmlns:dpconfig="http://www.datapower.com/param/config"
  xmlns:regexp="http://exslt.org/regular-expressions"
  extension-element-prefixes="dp" 
  exclude-result-prefixes="dp"&gt;
  &lt;xsl:template match="/"&gt; 
  &lt;xsl:value-of select="regexp:replace(string(.), '-\d{2}-\d{4}', 'i', '-xx-xxxx')"/&gt;
  &lt;xsl:value-of select="regexp:replace(string(.), '-\d{4}-\d{4}-\d{4}', 'i', '-xxxx-xxxx-xxxx')"/&gt;
  &lt;/xsl:template&gt; 
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I am getting output now</p>
  
  <p>but the output is comming twice</p>
  
  <pre><code>37289882
  789-xx-xxxx
  4545-6767-9876-8764
  j-89-8999
  
  37289882
  789-88-8907
  4545-xxxx-xxxx-xxxx
  j-89-8999
  </code></pre>
  
  <p>is it because of twice <code>&lt;xsl:value-of select&gt;</code></p>
  
  <p>Thanks</p>