Click to See Complete Forum and Search --> : Parent Node-Set Position


tomhartland
01-26-2004, 05:16 AM
I'm having difficulty working this out and wondered if anybody would be kind enough to point me in the right direction (or just tell me how to do it) :)

I need to have a nested <xsl:for-each> statement where I can access the position() of the parent node.

For example...<xsl:for-each select="PARENTNODE">
<xsl:for-each select="CHILDNODE">
<xsl:value-of select="position()"/>-<xsl:value-of="../position()">
</xsl:for-each>
</xsl:for-each>The above doesn't work (Ie. "../position()"), but it hopefully shows what I'm after.

Any ideas?
Tom :)

crh3675
01-26-2004, 08:44 AM
You forgot to add "select" in this statment:

<xsl:value-of="../position()">

should be

<xsl:value-of select="../position()">


If that still does not work, store the position in a variable, and then display it where you need to.

--Craig

tomhartland
01-26-2004, 09:52 AM
Apologies for the typo - that will teach me to type it straight in rather than copy a tested version!
Even with the typo corrected (select="../position()") it still wouldn't work.

But thank you for the suggestion of setting a variable. :)
I'd got it into my head that you could only ever set a variable once - but had forgotten that it can be set on each iteration of the "for-each" loop.

The following works perfectly...
<xsl:for-each select="PARENTNODE">
<xsl:variable name="PARENTID"><xsl:value-of select="position()"/></xsl:variable>
<xsl:for-each select="CHILDNODE">
<xsl:value-of select="position()"/>-<xsl:value-of select="$PARENTID"/>
</xsl:for-each>
</xsl:for-each>
Thanks again for your help and time :)