Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2006, 06:42 AM
Authorized User
 
Join Date: Nov 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default <xsl:for-each> inside another <xsl:for-each>

Following is my xml file.
<EMPLOYEES>
    <EMPLOYEE EmpId="194">
        <NAME>SURESH KUMAR</NAME>
        <EMPNO>E1001</EMPNO>
        <DESIGNATION>Developer</DESIGNATION>
        <PAY id="1">9500</PAY>
        <PAY id="2">4750</PAY>
        <PAY id="3">800</PAY>
        <PAY id="4">1000</PAY>
        <PAY id="5">650</PAY>
        <PAY id="6">1000</PAY>
        <PAY id="7">1140</PAY>
        <GROSS>17700.0</GROSS>
        <DEDUCTIONS>1140.0</DEDUCTIONS>
        <NETPAY>16560.0</NETPAY>
    </EMPLOYEE>
    <EMPLOYEE EmpId="196">
        <NAME>ANNAND KUMAR</NAME>
        <EMPNO>E1002</EMPNO>
        <DESIGNATION>Developer</DESIGNATION>
        <PAY id="1">7000</PAY>
        <PAY id="2">3500</PAY>
        <PAY id="3">800</PAY>
        <PAY id="4">800</PAY>
        <PAY id="5">500</PAY>
        <PAY id="6">800</PAY>
        <PAY id="7">840</PAY>
        <GROSS>13400.0</GROSS>
        <DEDUCTIONS>840.0</DEDUCTIONS>
        <NETPAY>12560.0</NETPAY>
    </EMPLOYEE>
          ---
          ---
    <EMPLOYEE EmpId="197">

</EMPLOYEES>

Using <xsl:for-each select="EMPLOYEES/EMPLOYEE">, I am iterating through each EMPLOYEE details and populating a table. Within each <EMPLOYEE>, how can I access all the <PAY> element and its data.

In my xsl, I have like this:
<xsl:for-each select="EMPLOYEES/EMPLOYEE">
<tr>
    <td><xsl:value-of select="EMPNO"/></td>
    <td><xsl:value-of select="NAME"/></td>
    <td><xsl:value-of select="DESIGNATION"/></td>
//Here I want iterate all the <PAY> elements within a <EMPLOYEE>
    <xsl:for-each select="/PAY">
             <td><xsl:value-of select="PAY"/></td>
    </xsl:for-each>
    <td><xsl:value-of select="GROSS"/></td>
    <td><xsl:value-of select="DEDUCTIONS"/></td>
    <td><xsl:value-of select="NETPAY"/></td>

</tr>
</xsl:for-each>

I think, I am wrong with the x-path!! Please help!

__________________
Cheers [-:]

Suresh!
 
Old December 28th, 2006, 07:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Read up about how xsl:for-each affects the context node, and how XPath path expressions depend on knowing the context node.

You want

<xsl:for-each select="PAY">
             <td><xsl:value-of select="."/></td>
    </xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 29th, 2006, 01:24 AM
Authorized User
 
Join Date: Nov 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you!!
Suresh.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
embedded <xsl:element> into <xsl:with-param> petergoodman XSLT 2 July 9th, 2008 06:36 AM
Performance for <xsl:import> and <xsl:include> vikkiefd XSLT 2 April 16th, 2008 08:06 AM
<xsl:choose> and <xsl:otherwise> problem djmarquette XSLT 4 January 21st, 2005 01:56 PM
HELP: XSL -> HTML <select selected=true> jedbartlett XSLT 4 October 7th, 2004 11:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.