hallo
not use for_each.
for-each is for node set
when you have a big xml file to sort or display by for-each than many memory is use in your pc
a template disccribt what is doing when the parser found the node
in this example
think not as programmer language think in xslt
i make a sample to show you how it works
xml to test
<?xml version="1.0"?>
<employees>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
<employee>
<user_id>6</user_id>
<profile_name>Developer</profile_name>
<profile_id>2</profile_id>
<user_status>1</user_status>
<gender>1</gender>
<first_name>Anulesh</first_name>
<last_name>Gupta</last_name>
<address>106/B, 1st Floor, 46th Cross, 4th Block, Rajajinagar,</address>
<pswd>password</pswd>
<pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
<email_addr>anulesh.gupta@effone.com</email_addr>
<phone>91-080-22445281</phone>
<dob>1981-09-18T00:00:00+05:30</dob>
<join_date>2008-11-20T00:00:00+05:30</join_date>
<receive_email_notification>true</receive_email_notification>
<last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
<emp_id>1001</emp_id>
<full_name>Anulesh Gupta</full_name>
<skill_set />
<city>Bangalore</city>
<state>Karnataka</state>
<country>India</country>
<zip_code>560010</zip_code>
<mobile_number>22445281</mobile_number>
<pwd_flag>1</pwd_flag>
<reports_to>5</reports_to>
</employee>
</employees>
xsl use css with style tag see there color
define the to colors with id(odd even) in css this mean (#odd #even)
his will describt in tag style
http://www.w3schools.com/css/css_colornames.asp
to make two colors use modulo xpath command mod
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html"/>
<xsl:template match="/">
<html>
<style>
<!-- http://www.w3schools.com/css/css_colornames.asp -->
table{
border: 2px solid black;
}
th{
border: 2px solid black;
background-color:#efefef;
}
td{
border: 2px solid black;
}
#odd
{
background-color:#ff0000;
}
#even
{
background-color:#00ff00;
}</style>
<body>
<xsl:apply-templates select="employees"/>
</body>
</html>
</xsl:template>
<xsl:template match="employees">
<table>
<tr>
<th>pos</th>
<th>firstname</th>
<th>lastname</th>
<th>profilename</th>
<th>emailaddr</th>
<th>phone</th>
</tr>
<xsl:apply-templates select="employee"/>
</table>
<!-- works also in does not reflect xsl-->
<table>
<tr>
<th>pos</th>
<th>firstname</th>
<th>lastname</th>
<th>profilename</th>
<th>emailaddr</th>
<th>phone</th>
</tr>
<xsl:for-each select="employee">
<tr>
<xsl:choose>
<xsl:when test="(position() mod 2) = 0">
<xsl:attribute name="id">odd</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="id">even</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<td>
<xsl:value-of select="position()"/>
</td>
<td>
<xsl:value-of select="first_name"/>
</td>
<td>
<xsl:value-of select="last_name"/>
</td>
<td>
<xsl:value-of select="profile_name"/>
</td>
<td>
<xsl:value-of select="email_addr"/>
</td>
<td>
<xsl:value-of select="phone"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="employee">
<tr>
<xsl:choose>
<xsl:when test="(position() mod 2) = 0">
<xsl:attribute name="id">odd</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="id">even</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<td>
<xsl:value-of select="position()"/>
</td>
<td>
<xsl:value-of select="first_name"/>
</td>
<td>
<xsl:value-of select="last_name"/>
</td>
<td>
<xsl:value-of select="profile_name"/>
</td>
<td>
<xsl:value-of select="email_addr"/>
</td>
<td>
<xsl:value-of select="phone"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet> result tow table one create by template and the other by for-each
<html>
<style>
table{
border: 2px solid black;
}
th{
border: 2px solid black;
background-color:#efefef;
}
td{
border: 2px solid black;
}
#odd
{
background-color:#ff0000;
}
#even
{
background-color:#00ff00;
}
</style>
<body>
<table>
<tr>
<th>pos</th>
<th>firstname</th>
<th>lastname</th>
<th>profilename</th>
<th>emailaddr</th>
<th>phone</th>
</tr>
<tr id="even">
<td>1</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>2</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="even">
<td>3</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>4</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="even">
<td>5</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>6</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="even">
<td>7</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>8</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
</table>
<table>
<tr>
<th>pos</th>
<th>firstname</th>
<th>lastname</th>
<th>profilename</th>
<th>emailaddr</th>
<th>phone</th>
</tr>
<tr id="even">
<td>1</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>2</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="even">
<td>3</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>4</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="even">
<td>5</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>6</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="even">
<td>7</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
<tr id="odd">
<td>8</td>
<td>Anulesh</td>
<td>Gupta</td>
<td>Developer</td>
<td>anulesh.gupta@effone.com</td>
<td>91-080-22445281</td>
</tr>
</table>
</body>
</html> i hope this will help you
soory for my bad english