title: Replace all instances of a string in XML with ****
body: <p>I have a XSL that needs to filter out specific data found in the XML.</p>
  
  <p>Somewhere in my XML there will be a node like:</p>
  
  <p><code>&lt;id root="2.16.840.1.113883.3.51.1.1.6.1" extension="9494949494949" /&gt;</code></p>
  
  <p>The XSL I have below deletes the <strong>extension</strong> node and adds a <strong>nullFlavor="MSK"</strong> to the node. </p>
  
  <p>What I need to do now, is take the value from the extension node, and search the entire XML document for that value, and replace it with <em>*</em>*.</p>
  
  <p>But I'm not sure how to take the <strong>extension</strong> attribute, and find all instances of that value in the XML (they could be burried in text and inside attributes) and turn them into <em>*</em>*  (4 *).</p>
  
  <p>The example below is just an example. I cannot hard code the XSL to look at specific nodes, it needs to look through all text / attribute text in the xml (reason for this is there are 5+ different versions of XML that this will be applied to).</p>
  
  <p>I need to find the Extension in the  node, then replace (delete really) that value from the rest of the XML. I'm looking for a 1 solution fits all messages, so a global search->wipe of the Extension value.</p>
  
  <p>Example:          </p>
  
  <pre><code>        &lt;identifiedPerson classCode="IDENT"&gt;
                  &lt;id root="2.16.840.1.113883.3.51.1.1.6.1" extension="9494949494949" displayable="true" /&gt;
                  &lt;addr use="PHYS"&gt;
                      &lt;city&gt;KAMLOOPS&lt;/city&gt;
                      &lt;country&gt;CA&lt;/country&gt;
                      &lt;postalCode&gt;V1B3C1&lt;/postalCode&gt;
                      &lt;state&gt;BC&lt;/state&gt;
                      &lt;streetAddressLine&gt;1A&lt;/streetAddressLine&gt;
                      &lt;streetAddressLine&gt;2A&lt;/streetAddressLine&gt;
                      &lt;streetAddressLine&gt;9494949494949&lt;/streetAddressLine&gt;
                      &lt;streetAddressLine&gt;4A&lt;/streetAddressLine&gt;                        
                  &lt;/addr&gt;
                  &lt;note text="9494949494949 should be stars"/&gt;
  </code></pre>
  
  <p>Should be (The below XSLT already masks the extension in the  node with the matching OID). </p>
  
  <pre><code>            &lt;identifiedPerson classCode="IDENT"&gt;
                  &lt;id root="2.16.840.1.113883.3.51.1.1.6.1" nullFlavor="MSK" displayable="true" /&gt;
                  &lt;addr use="PHYS"&gt;
                      &lt;city&gt;KAMLOOPS&lt;/city&gt;
                      &lt;country&gt;CA&lt;/country&gt;
                      &lt;postalCode&gt;V1B3C1&lt;/postalCode&gt;
                      &lt;state&gt;BC&lt;/state&gt;
                      &lt;streetAddressLine&gt;1A&lt;/streetAddressLine&gt;
                      &lt;streetAddressLine&gt;2A&lt;/streetAddressLine&gt;
                      &lt;streetAddressLine&gt;****&lt;/streetAddressLine&gt;
                      &lt;streetAddressLine&gt;4A&lt;/streetAddressLine&gt;                        
                  &lt;/addr&gt;
                  &lt;note text="**** should be stars"/&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>I am able to use XSL 2.0</p>
  
  <p>I have the current XSL.IT works fine. It matches any  tag where the root is '2.16.840.1.113883.3.51.1.1.6.1', kills all attributes and adds a nullFlavor="MSK". However, this will not search the entire XML for that same #.</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="xml" indent="yes"/&gt;
      &lt;xsl:param name="attrToKeep" select="'root'" /&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="@*"&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test="../@root = '2.16.840.1.113883.3.51.1.1.6.1'"&gt;
            &lt;xsl:copy-of select=".[contains($attrToKeep, name())]" /&gt;     
            &lt;xsl:attribute name="nullFlavor"&gt;MSK&lt;/xsl:attribute&gt;
            &lt;!-- Need some way to use the value found in this node and hide the extension --&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
            &lt;xsl:copy-of select="." /&gt;
          &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks,</p>