I wrote
No, if you wanted that you'd have to add from="entry" the default is the
whole document.
This is true.
That is true as written, but not entirely helpful as xsl:number counts
the input tree (in this case the sum of the number of k and r nodes)
but you want the count in the output (essentially the product in this
case)
Your original post indicated that actually you just need a unique
identifier rather than a count, that's easier in xslt, the default mode
in the code below produces
[81732,kval1,rval1][d0e3d0e10d0e17]
[81732,kval1,rval2][d0e3d0e10d0e19]
[81732,kval2,rval1][d0e3d0e12d0e17]
[81732,kval2,rval2][d0e3d0e12d0e19]
[81732,kval1,rval1][d0e23d0e30d0e37]
[81732,kval1,rval2][d0e23d0e30d0e39]
[81732,kval2,rval1][d0e23d0e32d0e37]
[81732,kval2,rval2][d0e23d0e32d0e39]
on
<entries>
<entry>
<seq_num>81732</seq_num>
<k_entries>
<k val="kval1"/>
<k val="kval2"/>
</k_entries>
<r_entries>
<r val="rval1"/>
<r val="rval2"/>
</r_entries>
</entry>
<entry>
<seq_num>81732</seq_num>
<k_entries>
<k val="kval1"/>
<k val="kval2"/>
</k_entries>
<r_entries>
<r val="rval1"/>
<r val="rval2"/>
</r_entries>
</entry>
</entries>
which has a duplicated entry element.
You'll see the first [] on each line iterates twice through the k and r
values, but the second [] on each line is unique.
If you do need a count you have to work (a bit) harder. as shown in mode
b which passes the "count so far" as a parameter to the template for
entry. so in this case you get
[81732,kval1,rval1][1]
[81732,kval1,rval2][2]
[81732,kval2,rval1][3]
[81732,kval2,rval2][4]
[81732,kval1,rval1][5]
[81732,kval1,rval2][6]
[81732,kval2,rval1][7]
[81732,kval2,rval2][8]
David
<xsl:stylesheet
version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
<xsl:template match="entries">
<xsl:apply-templates select="entry"/>
<xsl:apply-templates mode="b" select="entry[1]"/>
</xsl:template>
<xsl:template match="entry">
<xsl:variable name="e" select="."/>
<xsl:for-each select="k_entries/k">
<xsl:variable name="k" select="."/>
<xsl:for-each select="../../r_entries/r">
[<xsl:value-of select="concat($e/seq_num,',',$k/@val,',',@val,'][',generate-id($e),generate-id($k),generate-id(.),']')"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="entry" mode="b">
<xsl
aram name="c" select="0"/>
<xsl:variable name="e" select="."/>
<xsl:variable name="nr" select="count(r_entries/r)"/>
<xsl:for-each select="k_entries/k">
<xsl:variable name="k" select="."/>
<xsl:variable name="kp" select="position()"/>
<xsl:for-each select="../../r_entries/r">
[<xsl:value-of select="concat($e/seq_num,',',$k/@val,',',@val,'][',$c+($kp -1)*$nr + position(),']')"/>
</xsl:for-each>
</xsl:for-each>
<xsl:apply-templates select="following-sibling::entry[1]" mode="b">
<xsl:with-param name="c" select="$c + $nr * count(k_entries/k)"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>