tt: zwei Attribute zählen und verändern

Hallo,

folgende Transformation möchte ich gerne durchführten, weiß aber nicht wie. Habt ihr vielleicht einen Vorschlag?

Xml-Dokument:

<F>  
 <T>  
  <B           id="1">  
   <C name="x" id="1" type="text"/>  
  </B>  
  <B>  
   <C name="y" id="1" type="zahl"/>  
  </B>  
  <B           id="1" type="text">  
   <C name="y" id="1"/>  
  </B>  
  <A           id="1" type="zahl"/>  
</T>  
</F>

XML-Dokument nach der Transformation:

<F>  
 <T>  
  <B           id="1">  
   <C name="x" id="2" type="3"/>  
  </B>  
  <B>  
   <C name="y" id="4" type="5"/>  
  </B>  
  <B           id="6" type="2">  
   <C name="y" id="7"/>  
  </B>  
  <A           id="8" type="5"/>  
</T>  
<M  name="zahl"   id="3"/>  
<M  name="text"   id="5"/>  
</F>

Mein erster Ansatz:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  
<xsl:import href="copy.xsl" /> <!-- Kopier - Stylesheet-->  
  
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />  
<xsl:template match="@id | @type">  
<xsl:param name="countxmi">  
<xsl:number count="*[@id]" level="any" /></xsl:param>  
<xsl:param name="counttype"><xsl:number count="*[not(@type=preceding::*/@type)]" level="any" /></xsl:param>  
  
<xls:choose>  
<xsl:when test="../@type">  
<xsl:attribute name="id"><xsl:value-of select="$countxmi"/></xsl:attribute>  
<xsl:attribute name="type"><xsl:value-of select="$counttype "/></xsl:attribute></xsl:when>  
  
<xsl:otherwise><xsl:attribute name="id"><xsl:value-of select="$countxmi" /></xsl:attribute> </xsl:otherwise>  
</xls:choose>  
  
</xsl:stylesheet>

Dieses Stylesheet zählt bis jetzt nur die Id ohne das type Attribut zu mit einzubeziehen. Wie kann ich das type Attribut miteinbeziehen und so verändern das ich mein Transformationsergebnis erhalte?
Oder kann ich vielleicht, die Elemente M anlegen, wenn der aktuelle Knoten ein neues Typen-Attribut enthält. Diesem Element die fortlaufende Id übergeben und dann eine entsprechende Referenzen zu dem Attribut type anlegen.
 ???
Vielen vielen Dank im Voraus.
Viele Grüße, Tini