This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
position() within for-each usage
- From: "Nuri Besen" <nb_news at hotmail dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 06 Jun 2002 13:04:15 -0400
- Subject: [xsl] position() within for-each usage
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hello,
I am trying to use the position function to indicate the line I am currently
processing but I want the position of the parent node. If the data looks
like:
<data>
<item>
<name>xyz</name>
<lineitem>
<cost>24</cost>
<lineitem>
<cost>30</cost>
<item>
<name>abc</name>
<lineitem>
<cost>24</cost>
<lineitem>
<cost>30</cost>
and I use a for loop as to output HTML:
<xsl:template match="item">
<xsl:for-each select="lineitem">
For item #<xsl:value-of select="position()">
<xsl:value-of select="../name">
the cost for lineitem is <xsl:value-of select="cost">
</xsl:for-each>
</xsl:template>
Here, the output I want should have the item position rather than the
lineitem position but because of the location it gives me lineitem position,
which is correct within the loop construct. So how can I get the parent
position?
I tried ../self::node()[position()] but no good.
Sample output should be:
For item #1 xyz the cost for lineitem is 24
For item #1 xyz the cost for lineitem is 30
For item #2 abc the cost for lineitem is 24
For item #2 abc the cost for lineitem is 30
BUT it gives:
For item #1 xyz the cost for lineitem is 24
For item #2 xyz the cost for lineitem is 30
For item #1 abc the cost for lineitem is 24
For item #2 abc the cost for lineitem is 24
I know I could have used two templates to match rather than a loop but in
the real scenario I need to use the loop.
Any help is appreciated....
Thanks,
Nuri
P.S.: If there is a syntax error, i just typed it in fast, it is the logic
that i am trying to portray.
_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list