xsl-list
[Top] [All Lists]

RE: Get value outside of for-each Statement

2004-08-19 12:32:16
From: Niclas Hedhman [mailto:niclas(_at_)hedhman(_dot_)org]
Sent: Thursday, August 19, 2004 3:17 PM

To start with, I wouldn't write a for-each loop at all. Instead;

<xsl:template match="employees"> <!-- or whatever root you have-->
  <table>
    <xsl:apply-template select="employee_name" />
  </table>
</xsl:template>

<xsl:template match="employee_name" >
  <tr>
    <td><xsl:value-of select="." /></td>
    <td><xsl:value-of select="following-sibling::employee_number"
/></td>
  </tr>
</xsl:template>

But the proper answer to your question is about learning the so called
'axis'
concept and in your particular case the "following-sibling::".

Just for a bit of completeness, following-sibling will find the
employee_number nodes even if you do use xsl:for-each, so it can still
be used if desired.

Cheers,

Tom P