Nesting XSL For-Each Statements

admin

Administrator
Staff member
Forgive me for asking an XSL question in an XML newsgroup, but I couldn'tfind an XSL specific ng (anyone know of any?). I am new to XML/XSL so I'msorry if this seems like a daft question. I have an XML file that I amtrying to apply an XSL File to. It currently works ok if I put theEmployeeID, Surname and Forenames into a single table, but what I would liketo do ideally is have multiple tables. Ideally there would be a title foreach Sites SiteOffice, and then a table detailing all the employees at thatSites SiteOffice. The only way I could think of to do that was to trynesting my xsl:for-each statements. However, when I try that, I just get anerror. Is this feasible, or am I going about this totally the wrong way?CheersJames E(Xml and XSL files are as follows:)My Xml File is as follows:<Sites><Site SiteNumber = "100"><SiteOffice SiteOfficeID = "A"><Employee><EmployeeID>1234</EmployeeID><Surname>Jones</Surname><Forenames>Fred</Forenames></Employee><Employee><EmployeeID>4567</EmployeeID><Surname>Smith</Surname><Forenames>Bill</Forenames></Employee></SiteOffice ><SiteOffice SiteOfficeID = "B"><Employee><EmployeeID>9876</EmployeeID><Surname>Doe</Surname><Forenames>John</Forenames></Employee><Employee><EmployeeID>5432</EmployeeID><Surname>Walker</Surname><Forenames>Alan</Forenames></Employee></SiteOffice ></Site><Site SiteNumber = "200"><SiteOffice SiteOfficeID = "A"><Employee><EmployeeID>9182</EmployeeID><Surname>Lewis</Surname><Forenames>Lennox</Forenames></Employee></SiteOffice ></Site></Sites>My XSL File is as follows:<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"><xsl:template match="/"><HTML><HEAD><DIV ALIGN="Center"><H3>MY TITLE</H3></DIV></HEAD><BODY><TABLE><TR><TH>Employee ID</TH><TH>Surname</TH><TH>Forenames</TH></TR><xsl:for-each select="Sites/Site/SiteOffice/Employee"><TR><TD><xsl:value-of select="EmployeeID"/></TD><TD><xsl:value-of select="Surname"/></TD><TD><xsl:value-of select="Forenames"/></TD></TR></xsl:for-each></TABLE></BODY></HTML></xsl:template></xsl:stylesheet>
 
Back
Top