eb*******@mindspring.com (Eyal) writes:
Hello,
I am new to xslt and try to have an argument that for each iteration
of the "FOR-EACH" will grow in one:
<xsl:for-each select="//AssetCode">
<node id="_1">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
I want id to be in the next iteration _2 and _3 in the next one
etc....
any ideas of how to do it?
Use the XPath position() function.
These data
<test>
<AssetCode>abc</AssetCode>
<AssetCode>def</AssetCode>
<AssetCode>ghi</AssetCode>
<AssetCode>jkl</AssetCode>
</test>
with a very slight modification to your stylesheet:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:template match="/">
<xsl:for-each select="//AssetCode">
<node id="_{position()}">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Gives this output
<?xml version="1.0"?>
<node id="_1" text="abc"/><node id="_2" text="def"/>
<node id="_3" text="ghi"/><node id="_4" text="jkl"/>
Ben
--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
www.edginet.org