Thomas J.S.: iteration

Beitrag lesen

Hallo,

fonctioniert immer nicht.der rausgegebenen Zahl ist immer gleich="1".Hängt vielleicht von der struktur des Documents .
kann ich eine untere function programmieren , die wenn sie im xsl:attribute-set gerufen ist immer an der Stelle eine neue Zahl(zahl+1) für meine "id" rausgibt? wie geht das?

Ich habe jetzt ein Beispiel gemacht und es funktioniert wie es soll, wenn bei dir das nicht der Fall ist, solltest du ein Stück von deinem XML posten.

Grüße
Thomas
--- xml ---

<?xml version="1.0" encoding="ISO-8859-1"?>  
<data>  
 <dig:instances xmlns:dig="http://www.dig.org">  
  <dig:catom xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="meta:ActionWithSuccessor"/>  
 </dig:instances>  
 <dig:instances xmlns:dig="http://www.dig.org">  
  <dig:catom xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="meta:Action"/>  
 </dig:instances>  
 <dig:instances xmlns:dig="http://www.dig.org">  
  <dig:catom xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="meta:Action"/>  
 </dig:instances>  
</data>

--- xslt ---

<?xml version="1.0" encoding="iso-8859-1"?>  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dig="http://www.dig.org">  
 <xsl:output method="xml" indent="yes"/>  
 <xsl:template match="/data">  
  <data>  
   <xsl:for-each select="dig:*">  
    <xsl:copy>  
     <xsl:copy-of select="@*"/>  
     <xsl:attribute name="id">  
      <xsl:value-of select="position()"/>  
     </xsl:attribute>  
     <xsl:copy-of select="*"/>  
    </xsl:copy>  
   </xsl:for-each>  
  </data>  
 </xsl:template>  
</xsl:stylesheet>

--- ausgabe ---

<?xml version="1.0" encoding="UTF-8"?>  
<data xmlns:dig="http://www.dig.org">  
   <dig:instances id="1">  
      <dig:catom xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="meta:ActionWithSuccessor"/>  
   </dig:instances>  
   <dig:instances id="2">  
      <dig:catom xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="meta:Action"/>  
   </dig:instances>  
   <dig:instances id="3">  
      <dig:catom xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="meta:Action"/>  
   </dig:instances>  
</data>