title: xslt replace attribute values that are duplicated of parent node
body: <p>I have a XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ROOT&gt;
      &lt;tag1 id="abc" name="first tag"&gt;
          &lt;tag2 id="efg" name="embedded tag1"&gt;
          &lt;/tag2&gt;
      &lt;/tag1&gt;
      &lt;tag1 id="hij" name="first tag"&gt;
          &lt;tag2 id="hij" name="embedded tag1"&gt;
          &lt;/tag2&gt;
      &lt;/tag1&gt;
      &lt;LOTS OF TAG1/TAG2S&gt;...&lt;/&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>I would like to find out the nodes tag2 which have the same id value as the parent node tag1's id value, replace the value of tag2 id to original id with suffix "D".</p>
  
  <p>In above example: tag2 has id "hij" which is the same as its parent node tag1, hence it should be replaced as: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ROOT&gt;
      &lt;tag1 id="abc" name="first tag"&gt;
          &lt;tag2 id="efg" name="embedded tag1"&gt;
          &lt;/tag2&gt;
      &lt;/tag1&gt;
      &lt;tag1 id="hij" name="first tag"&gt;
          &lt;tag2 id="hijD" name="embedded tag1"&gt;
          &lt;/tag2&gt;
      &lt;/tag1&gt;
      &lt;LOTS OF TAG1/TAG2S&gt;...&lt;/&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>I wrote an xslt:</p>
  
  <pre><code>&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="//tag2/@id[.=../tag1/@id]"&gt;
    &lt;xsl:with-param name="id" select="@id" /&gt;
    &lt;xsl:with-param name="extra" select="'D'" /&gt;
    &lt;xsl:attribute name="id"&gt;
      &lt;xsl:value-of select="concat($id,$extra)"/&gt;
    &lt;/xsl:attribute&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Doesn't quite work as expected.
  Any lights would be appreciated!</p>