PDA

View Full Version : XSL nested For Each


ScottInTexas
08-11-2004, 03:52 PM
I am trying to get this nested for-each to work but only one item shows up. It has to do with the for-each statement but I don't see what is wrong.

<xsl:for-each select="resume/experience/company">
<xsl:value-of select="companyName" /><br />
<div class="date">
<xsl:value-of select="start/date/month" />
<xsl:value-of select="start/date/year" /> To
<xsl:value-of select="end/date/month" />
<xsl:value-of select="end/date/year" /><br />
<xsl:value-of select="title" /><br />
<xsl:for-each select="resume/experience/company/duties">
<xsl:value-of select="dutyItem" /><br />
</xsl:for-each>
</div>
<br />
</xsl:for-each>

The outer loop works, the inner loop does not. It's the select path. But what about it?

Here is some sample data

<duties>
<dutyItem>Researching mineral titles on land in several Texas counties Including Panola, Shelby, Buffalo, Liberty and Harris.</dutyItem>
<dutyItem>Prepared run sheets for attorneys.</dutyItem>
<dutyItem>Prepared affidavits of heirship.</dutyItem>
</duties>

jkd
08-11-2004, 05:13 PM
The context node has changed.
<xsl:for-each select="resume/experience/company/duties">

Try using:
<xsl:for-each select="duties">

ScottInTexas
08-12-2004, 12:54 PM
Thanks for your reply JKD,

I tried that as well. That returns only one of the three or four items.

<xsl:for-each select="duties">
<xsl:value-of select="dutyItem" /><br />
</xsl:for-each>


Here, maybe the entire xsl and xml is required. I just hate posting so much stuff.

XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="resume.xsl" ?>
<resume>
<name class="name">James S. Stewart</name>
<street>125 Sunflower Lane</street>
<city>Lake Jackson</city><state>Texas</state><zip>77566</zip>
<phone>979 297-5790</phone>
<email>napua@swbell.net</email>
<qualifications>Skilled web site and web based application developer writing support tools for
a global team in a multi billion dollar corporation.</qualifications>
<education>
<school>
<school_name>University of Houston, Clearlake</school_name>
<start>
<date>
<month>05</month>
<day>01</day>
<year>1985</year>
</date>
</start>
<end>
<date>
<month>05</month>
<day>01</day>
<year>1989</year>
</date>
</end>
</school>
<school>
<school_name>Brazosport College</school_name>
<start>
<date>
<month>05</month>
<day>01</day>
<year>1982</year>
</date>
</start>
<end>
<date>
<month>05</month>
<day>01</day>
<year>1985</year>
</date>
</end>
</school>
</education>
<experience>
<company>
<companyName>
Kelly Services/Dow Chemical, Freeport, TX
</companyName>
<start>
<date>
<month>September</month>
<year>2001</year>
</date>
</start>
<end>
<date>
<month>August</month>
<year>2004</year>
</date>
</end>
<title>IT Programmer</title>
<duties>
<dutyItem>Designed interactive ASP web sites and web pages for the Light Hydrocarbon Tech Center.</dutyItem>
<dutyItem>Developed various tools in Visual Basic.</dutyItem>
<dutyItem>Developed Event database in MS Access.</dutyItem>
<dutyItem>Developed interactive reporting web pages with live charts.</dutyItem>
</duties>
</company>
<company>
<companyName>
Self Employed, Lake Jackson, TX
</companyName>
<start>
<date>
<month>October</month>
<year>2000</year>
</date>
</start>
<end>
<date>
<month>September</month>
<year>2001</year>
</date>
</end>
<title>
Independent Petroleum Land Man
</title>
<duties>
<dutyItem>Researching mineral titles on land in several Texas counties Including Panola, Shelby, Buffalo, Liberty and Harris.</dutyItem>
<dutyItem>Prepared run sheets for attorneys.</dutyItem>
<dutyItem>Prepared affidavits of heirship.</dutyItem>
</duties>
</company>
<company>
<companyName>Specialty Equipment, Houston, TX</companyName>
<start>
<date>
<month>July</month>
<year>1996</year>
</date>
</start>
<end>
<date>
<month>October</month>
<year>2000</year>
</date>
</end>
<title>National Accounts Manager</title>
<duties>
<dutyItem>Designed drum-filling machines including embedded PC controls, pneumatics and mechanical design.</dutyItem>
<dutyItem>Designed complete automated packaging systems for customers and worked at the corporate level of companies such as Dow Chemical, BASF, Pennzoil and Du Pont to establish purchasing and design guidelines for industrial material handling systems.</dutyItem>
<dutyItem>Co-signer of Liquid Filling machine Patent. </dutyItem>
<dutyItem>Writing proposals to meet customer specifications. </dutyItem>
</duties>
</company>
<company>
<companyName>Velcon, Freeport, TX</companyName>
<start>
<date>
<month>September</month>
<year>1987</year>
</date>
</start>
<end>
<date>
<month>June</month>
<year>1996</year>
</date>
</end>
<title>Sales Engineer </title>
<duties>
<dutyItem>Built liquid filling machines for industrial uses such as drum and pail filling.</dutyItem>
<dutyItem>Field Service on manufactured equipment.</dutyItem>
<dutyItem>Designed the first automated industrial Liquid Dispensing Systems for lube oil and greases blending. Now used world wide in a number of applications.</dutyItem>
<dutyItem>Designed overall material handling systems including conveyors, fillers, pallet dispensers, palletizers and controls.</dutyItem>
<dutyItem>National and International sales including India, Australia, South America and the Pacific Rim.</dutyItem>
<dutyItem>Writing purchasing contracts and bid specifications.</dutyItem>
</duties>
</company>
</experience>
<compSkills>
Visual Basic, VBA, VBScript, HTML, DHTML, XML/XSL, Javascript, Java, C++, Fortran IV
</compSkills>
<personal_info>
Scott is married to his wife of 23 years and has one child. Together he and his wife
started and manage the Lake Jackson 4-H club. He is an active member of the Brazoria
County Fair Association. His other hobbies include scuba diving, riding horses, wood working and stained glass.
</personal_info>
</resume>


XSL

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<link rel="stylesheet" href="ResumeStyles.css" type="text/css" />
<body>
<div id="NameDiv">
<xsl:value-of select="resume/name" />
<div id="addressDiv" >
<xsl:value-of select="resume/street" /> <br />
<xsl:value-of select="resume/city" />,
<xsl:value-of select="resume/state" />
<xsl:value-of select="resume/zip" /><br />
<xsl:value-of select="resume/phone" /><br />
<xsl:value-of select="resume/email" />
</div>
</div>
<div id="qualificationsDiv">
<xsl:value-of select="resume/qualifications" />
</div>
<div id="education">
<xsl:for-each select="resume/education/school">
<xsl:value-of select="school_name" /><br />
<xsl:value-of select="start/date/month" />-
<xsl:value-of select="start/date/day" />-
<xsl:value-of select="start/date/year" /> To
<xsl:value-of select="end/date/month" />-
<xsl:value-of select="end/date/day" />-
<xsl:value-of select="end/date/year" /><br />
</xsl:for-each>
</div><br />
<div id="experienceDiv">
<xsl:for-each select="resume/experience/company">
<h3><xsl:value-of select="companyName" /></h3>
<div class="date">
<xsl:value-of select="start/date/month" />
<xsl:value-of select="start/date/year" /> To
<xsl:value-of select="end/date/month" />
<xsl:value-of select="end/date/year" /><br />
<xsl:value-of select="title" /><br />
<xsl:for-each select="duties">
<xsl:value-of select="dutyItem" /><br />
</xsl:for-each>
</div>
</xsl:for-each>
</div>
<div id="compSkillsDiv" >
<xsl:value-of select="compSkills" />
</div>
<div id="persInfoDiv">
<xsl:value-of select="personal_info" />
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Thanks for your help.

SodaBob
01-13-2005, 08:25 PM
Using your first post's example xml and xsl, your nested for-each loop should look like this:

<xsl:for-each select="resume/experience/company/duties/dutyItem">
<xsl:value-of select="." /><br />
</xsl:for-each>

Strange, but true! :p

glenngv
01-14-2005, 05:10 AM
Strange, but true! :p
Not actually strange. Come to think of it, you only loop through the repeating elements which is <dutyItem> in this case and not <duties>