Querying & XML Documents  
by Giuseppe Naccarato 	

Listing One 
//  The employee.xml file
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee id="10808">
  <surname>White</surname>
  <name>Liza</name>
  <birthday>02/28/1976</birthday>
  <attendance>
    <date>01/02/2002</date>
    <starttime>9:08 am</starttime>
    <endtime>18:45 pm</endtime>
  </attendance>
  <attendance>
    <date>01/03/2002</date>
    <starttime>8:54 am</starttime>
    <endtime>17:55 pm</endtime>
  </attendance>
  <attendance>
    <date>01/04/2002</date>
    <starttime>9:13 am</starttime>
    <endtime>19:21 pm</endtime>
  </attendance>
</employee>

<employee id="10990">
  <surname>Hill</surname>
  <name>James</name>
  <birthday>01/16/1979</birthday>
  <attendance>
    <date>01/02/2002</date>
    <starttime>7:43 am</starttime>
    <endtime>17:25 pm</endtime>
  </attendance>
  <attendance>
    <date>01/03/2002</date>
    <starttime>8:02 am</starttime>
    <endtime>17:11 pm</endtime>
  </attendance>
  <attendance>
    <date>01/04/2002</date>
    <starttime>8:11 am</starttime>
    <endtime>17:41 pm</endtime>
  </attendance>  
</employee>
<employee id="11145">
  <surname>Hill</surname>
  <name>Marion</name>
  <birthday>03/04/1968</birthday>
  <attendance>
    <date>01/02/2002</date>
   <starttime>7:50 am</starttime>
    <endtime>17:12 pm</endtime>
  </attendance>
  <attendance>
    <date>01/03/2002</date>
    <starttime>8:45 am</starttime>
    <endtime>17:54 pm</endtime>
  </attendance>
  <attendance>
    <date>01/04/2002</date>
    <starttime>8:34 am</starttime>
    <endtime>17:34 pm</endtime>
  </attendance>  
</employee>
</employees>


Listing Two  
// The employee.xsl file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
  <html>
  <body>    
    <xsl:for-each select="$">
     <h2>
     <xsl:value-of select="@id"/>
     <xsl:text> </xsl:text>
     <xsl:value-of select="name"/>
     <xsl:text> </xsl:text>
     <xsl:value-of select="surname"/>
     <xsl:text> </xsl:text>   
     <xsl:value-of select="birthday"/>     
     </h2>
     <table border="2" width="50%">
     <tr bgcolor="yellow">
     <td width="34%"><b>Date</b></td>
     <td width="33%"><b>Start Time</b></td>
     <td width="33%"><b>End Time</b></td>
     </tr>
     <xsl:for-each select="attendance">
       <tr>
       <td><xsl:value-of select="date"/></td>
       <td><xsl:value-of select="starttime"/></td>
       <td><xsl:value-of select="endtime"/></td>
       </tr>
     </xsl:for-each>    
    </table>
    <br/><br/> 
    </xsl:for-each>    
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

Listing Three
// HTML code accepting the query
    <HTML><BODY>
 <CENTER><FORM action=http://MYSERVER/servlets/EmployeeServlet METHOD=GET>
  <text>Surname </text><INPUT TYPE = "text" NAME = "surname" SIZE = 20>    
  <INPUT TYPE = submit>
  </FORM></CENTER>  
</BODY></HTML>






3


