title: XSLT, mapping id's to new values
body: <p>I have searched through all the xslt mapping questions but haven't found a solution to my very specific case yet.</p>
  
  <p>So, suppose this is my source XML:</p>
  
  <pre><code>&lt;Data&gt;
    &lt;A val='1'&gt;
      &lt;CC&gt;1234&lt;/CC&gt;
    &lt;/A&gt;
    &lt;A val='2'&gt;
      &lt;CC&gt;1234&lt;/CC&gt;
      &lt;CC&gt;5678&lt;/CC&gt;
    &lt;/A&gt;
    &lt;A val='3'&gt;
      &lt;CC&gt;1234&lt;/CC&gt;
    &lt;/A&gt;
    &lt;B val='1'&gt;
      &lt;CC&gt;5678&lt;/CC&gt;
    &lt;/B&gt;
    &lt;B val='2'&gt;
      &lt;CC&gt;1234&lt;/CC&gt;
      &lt;CC&gt;9012&lt;/CC&gt;
    &lt;/B&gt;
  &lt;/Data&gt;
  </code></pre>
  
  <p>What I want as result is the following:</p>
  
  <pre><code>&lt;Data&gt;
    &lt;A val='1'&gt;
      &lt;CC&gt;-1&lt;/CC&gt;
    &lt;/A&gt;
    &lt;A val='2'&gt;
      &lt;CC&gt;-1&lt;/CC&gt;
      &lt;CC&gt;-2&lt;/CC&gt;
    &lt;/A&gt;
    &lt;A val='3'&gt;
      &lt;CC&gt;-1&lt;/CC&gt;
    &lt;/A&gt;
    &lt;B val='1'&gt;
      &lt;CC&gt;-2&lt;/CC&gt;
    &lt;/B&gt;
    &lt;B val='2'&gt;
      &lt;CC&gt;-1&lt;/CC&gt;
      &lt;CC&gt;-3&lt;/CC&gt;
    &lt;/B&gt;
  &lt;/Data&gt;
  </code></pre>
  
  <p>If I would code this in some programming language I would first put all the CC-values into a set/collection and then when I know all the possible CC-values I would iterate through the set and replace the value in the XML with a counter that is decreased within the loop. But I have no clue how to do that in XSLT...
  So in the above example I have the CC-values 1234, 5678 and 9012.
  When iterating over the values, <strong>all</strong> CC-values having 1234 should become -1, 5678 ==> -2 and 9012 ==>-3 <strong>regardless if CC is under A or B</strong>. It would also be ok if 5678 is mapped to -1, 9012 to -2 and 1234 to -3, but <strong>all</strong> occurences of 1234 must be changed to -3 then and so on.
  Thanks for any help!</p>