<Menu>
<Food>
<Item>
<Name>Waffles</Name>
<Price>$9</Price>
<Description>Try them with syrup *Additional Charge*</Description>
</Item>
<Item name="Pop-Tarts" price="$40" description="yummy"></Item>
<Food>
<Menu>
I used the following XSLT to break up the second food item into three elements
<xsl:template match="/">
<xsl:apply-templates select="Menu/Food" />
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Item">
<xsl:element name="{name()}">
<!--This is what Im trying to fix-->
<xsl:attribute name="id"></xsl:attribute>
<xsl:for-each select="@*">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
<xsl:apply-templates select="* | text()"/>
</xsl:element>
</xsl:template>
In the last template, how would I take the 'id' attribute for each 'Item' element and increment it for each new item?
This is what my current output looks like
<Food>
<Item id="">
<Name>Waffles</Name>
<Price>$9</Price>
<Description>Try them with syrup *Additional Charge*</Description>
</Item>
<Item id="">
<name>Pop-Tarts</name>
<price>$40</price>
<description>yummy</description>
</Item>
</Food>