Hi, I have the following XML file:
<phonebook>
<departments>
<department id="1" parent="" title="Rabit Hole" address="" email="" index=""/>
<department id="2" parent="" title="Big Pond" address="" email="" index=""/>
</departments>
<employees>
<employee id="1" fname="Daffy" lname="Duck" title="Admin" email="[email protected]" department="2" room="" />
<employee id="2" fname="Bugs" lname="Bunny" title="Programmer" email="[email protected]" department="1" room="" />
</employees>
</phonebook>
When displaying it, I want to show the contact details for an employee as well as the title of the department where he works. Here's what I've got in the template:
<xsl:for-each select="phonebook/employees/employee">
<xsl:sort select="@lname" />
<tr>
<td>
<span class="lname"><xsl:value-of select="@lname"/></span>
<xsl:text> </xsl:text>
<span class="fname"><xsl:value-of select="@fname"/></span>
</td>
<td><xsl:value-of select="@title"/></td>
<td>
<xsl:value-of select="/phonebook/departments/department[@id='{@department}']/@title"/>
</td>
<td><a href="mailto:{@email}"><xsl:value-of select="@email"/></a></td>
</tr>
</xsl:for-each>
The problem is that the following rule doesn't seem to work:
<xsl:value-of select="/phonebook/departments/department[@id='{@department}']/@title"/>
I guess this is because the XSLT engine looks for the department
property in the department
element, and not in the employee
element. However, I don't have an idea how to fix it. Could anyone give me a hint on that?