The correct XPath expression to select the required contact
element is contactdatabase/contact[id = $currentID]
.
Rather than a for-each
I would use apply-templates
to format the contact
element with the given ID, and write a separate template to match contact
elements. It would look like this.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="url"/>
<xsl:variable name="currentID" select="substring-after($url, 'id=')"/>
<xsl:template match="/">
<html>
<head>
<title>Contact Database - Contact Viewer</title>
<style>
h1 {
color:white;
background-color:black;
border-style:solid;
border-color:#981b1e;
padding-left:10px;
font-weight:bold;
}
</style>
</head>
<body>
<h1>Contact Viewer</h1>
<xsl:value-of select="$currentID"/>
<xsl:apply-templates select="contactdatabase/contact[id = $currentID]"/>
<a href="contactList">Contact List</a>
</body>
</html>
</xsl:template>
<xsl:template match="contact">
<table cellspacing="5" border="3">
<tr height="60">
<td width="70px">
<xsl:value-of select="firstName"/>
</td>
<td width="100px">
<xsl:value-of select= "lastName"/>
</td>
<td width="120px">
<xsl:value-of select="firstName"/>
</td>
<td width="90px">
<xsl:value-of select="firstName"/>
</td>
<td width="35px">
<xsl:value-of select="state"/>
</td>
<td width="44px">
<xsl:value-of select="zipcode"/>
</td>
<td width="60px">
<xsl:value-of select="country"/>
</td>
<td width="80">
<xsl:value-of select="email"/> <br></br>
<xsl:value-of select="home"/> <br></br>
<xsl:value-of select="mail"/>
</td>
<td width="80">
<xsl:value-of select="phonenum"/>
</td>
<td width="180">
<xsl:value-of select="emailaddress"/>
</td>
<td width="120px">
<a href="contactViewer?contactid={id}">view</a> / edit / delete
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>