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 August 10th, 2012, 07:04 AM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default for-each loop in a for-each

I have an xml doc with somte tags like:

Quote:
<person>
<id>1</id>
<name>bigjo</name>
</person>
<person>
<id>2</id>
<name>user1</name>
</person>

<function>
<idperson>1</idperson>
<description>programmer</description>
</function>
<function>
<idperson>1</idperson>
<description>webdesigner</description>
</function>
<function>
<idperson>2</idperson>
<description>programmer</description>
</function>
now I want to do a for-each on the person and in that for-each make another for-each to take all the function where the id of the first for-each is equal to the idperson.

can someone help me here?
 
Old August 10th, 2012, 07:18 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The XML you show isn't a valid XML document as it has no single root element. Assuming a root element called "root" some XSLT might look like this:

Code:
<xsl:for-each select="/root/person">
   <xsl:variable name="id" select="id"/>
   Name = <xsl:value-of select="name"/>
   <xsl:for-each select="/root/function[idperson=$id]"> 
      Job Description = <xsl:value-of select="description"/>
    </xsl:for-each>
</xsl:for-each>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 10th, 2012, 08:01 AM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's exactly what i needed ! Thank you very much





Similar Threads
Thread Thread Starter Forum Replies Last Post
For loop with Floating Point Loop Counter - pp. 150 shivesh BOOK: Ivor Horton's Beginning Visual C++ 2010 1 March 28th, 2012 09:31 AM
Array Loop skipping loop in VBA jeskit Access VBA 5 March 20th, 2012 10:03 AM
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
loop crmpicco Classic ASP Basics 1 February 12th, 2005 09:12 PM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





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