Re: [xsl] Get value outside of for-each Statement

Subject: Re: [xsl] Get value outside of for-each Statement
From: Niclas Hedhman <niclas@xxxxxxxxxxx>
Date: Fri, 20 Aug 2004 03:16:42 +0800
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::".


Niclas

On Friday 20 August 2004 03:05, john lee wrote:
> Hi All,
>
> I got a problem with for-each statement. When you are inside a for-each
> statement, how do you link the value inside the for-each statement with a
> value that is outside of the element being looped through ?
>
> This is the xml:
>
> <employee_name>
> </employee_name>
> <employee_number>
> </employee_number>
>
> <employee_name>
> </employee_name>
> <employee_number>
> </employee_number>
>
> This is the output I want to have:
> Employee Name: Test1                  Employee Number: 123
> Employee Name: Test2                  Employee Number: 456
>
>
> <xsl:for-each select="employee_name">
>    <tr>
>       <td> Employee Name: <xsl:value-of select="employee_name"></td>
>       <td>Employee Number: ______________________________ </td>
>   </tr>
> </xsl:for-each>
>
> Any help would be appreciated
>
> _________________________________________________________________
> Protect your PC - get McAfee.com VirusScan Online
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+

Current Thread