View Single Post
  #1 (permalink)  
Old May 26th, 2007, 06:18 PM
miccipynewbie miccipynewbie is offline
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to populate a table with xml data in xslt

hi

im a newbie as my name suggests and ive been trying to populate a table for a time table.

Code:
<timetable>
 <university universityName="nottingham University">
   <startDate>05-02-2007</startDate>
   <endDate>11-05-2007</endDate>
   <startWeek>124</startWeek>
   <endWeek>138</endWeek>
 </university>
 <campus campusName="Wisteria"/>
 <Semester semesterNumber="1"/>
 <student studentNumber="2321557">
   <name>
     <firstName>Molly</firstName>
     <middleName>Collwen</middleName>
     <lastName>Caldwell</lastName>
   </name>
   <registeredModules>
     <studentsModules>3021</studentsModules>
     <studentsModules>3052</studentsModules>
     <studentsModules>3994</studentsModules>
   </registeredModules>
 </student>
 <modules>
   <module Crn="x73236">
     <moduleCrn>73236</moduleCrn>
     <moduleCode>3021</moduleCode>  
     <moduleName>Enterprise Database Systems</moduleName>
     <moduleTutor>
       <title/>
       <firstName>Patricia</firstName>
       <middleName/>
       <lastName>Ward</lastName>
       </moduleTutor>
   </module>
 </modules>
 <startTime>
   <st ID="s1">09:00 AM</st>
   <st ID="s2">09:30 AM</st>
   <st ID="s3">10:00 AM</st>
   <st ID="s4">10:30 AM</st>
   <st ID="s5">11:00 AM</st>
   <st ID="s6">11:30 AM</st>
 </startTime>
 <endTime>
   <et ID="e1">09:29 AM</et>
   <et ID="e2">09:59 AM</et>
   <et ID="e3">10:29 AM</et>
   <et ID="e4">10:59 AM</et>
   <et ID="e5">11:29 AM</et>
   <et ID="e6">11:59 AM</et>
   <et ID="e7">12:29 PM</et>
   <et ID="e8">12:59 PM</et>
 </endTime>
 <building buildingName="COLLB">
   <buildingRoom roomId="collb1">C114</buildingRoom>
   <buildingRoom roomId="collb2">C120</buildingRoom>
   <buildingRoom roomId="collb3">C121</buildingRoom>
   <buildingRoom roomId="collb4">CG76</buildingRoom>
 </building>
 <week weekNumber="124">
   <day dayOfWeek="Monday">
     <allocation allocationCrn="83488">
       <registeredModule moduleRef="x73245"/>
       <class classNumber="C01" classType="Lecture"/>
       <assignedRoom buildingRef="collb1"/>
       <starts startTimeRef="s1"/>
       <ends endTimeRef="e4"/>
     </allocation>
     <allocation allocationCrn="83490">
       <registeredModule moduleRef="x73245"/>
       <class classNumber="L02" classType="Laboratory"/>
       <assignedRoom buildingRef="collb3"/>
       <starts startTimeRef="s4"/>
       <ends endTimeRef="e8"/>
     </allocation>
  </day>
  <day dayOfWeek="Tuesday"/>
  <day dayOfWeek="Wednesday"/>
  <day dayOfWeek="Thursday">
     <allocation allocationCrn="83476">
       <registeredModule moduleRef="x73236"/>
       <class classNumber="C01" classType="Lecture"/>
       <assignedRoom buildingRef="collb4"/>
       <starts startTimeRef="s5"/>
       <ends endTimeRef="e8"/>
     </allocation>
  </day>
  <day dayOfWeek="Friday">
     <allocation allocationCrn="83476">
       <registeredModule moduleRef="x73236"/>
       <class classNumber="L05" classType="Laboratory"/>
       <assignedRoom buildingRef="collb2"/>
       <starts startTimeRef="s3"/>
       <ends endTimeRef="e5"/>
     </allocation>
  </day>
  <day dayOfWeek="Saturday"/>
  <day dayOfWeek="Sunday"/>
 </week>
</timetable>
so thats my basic gyst. there is obviously more than one week in a university calendar etc etc. now i need to make the weekly information in to a readable time table with the days on the x-axis as headers and the time on the y-axis. the university day starts at 9am and ends at 9pm (im only showing the abbreviated version). ive managed to get the header of the time table, and the times. but im so hopelessly lost with the populating of the table. PLEASE HELP. ive tried tutorials but and i understand them but i have no idea how to apply the functions etc. the xslt is shown below.

Code:
<xsl:template match="/">
 <html>
   <head>
     <title>Student TimeTable</title>
     <xsl:call-template name="style"/>
   </head>
   <body>
     <div id="wrapper">
       <table border="1">
         <xsl:apply-templates select="timetable"/>
       </table>
     </div>
   </body>
  </html>
</xsl:template>

<xsl:template name="style">
 <style type="text/css">
   <xsl:comment>
     a:hover { background: #9fc; }
     .header { background: #ccc; }
     .activity { background: #ff9; }
     .small { font-size: 70%; }
     .link { font-size: 120%; font-family: sans-serif; }
     .note{font-size: x-small; font-weight:bold;}
     a{text-decoration:none;}
     #wrapper {width:1200px;height:700px;}
   </xsl:comment>
 </style>
</xsl:template>

<xsl:template match="timetable">
 <thead>
   <tr>
     <td colspan="3">Student Timetable</td>
     <td colspan="4"><xsl:apply-templates select="student"/></td>
     <td><xsl:apply-templates select="student/name"/></td>
   </tr>
   <tr>
     <td colspan="8" align="right"></td>            
   </tr>
   <tr>
     <td colspan="8">
       <p>Any modules shown at the bottom of the page with a
       zero after it is not timetabled.</p>
     </td>
   </tr>
   <tr><td colspan="8"/></tr>
   <tr>
     <td colspan="8">
    <p>The current week is displayed by default. If this is not 
        a teaching week you will need to click on Next Week or 
        Previous Week to view the timetable.</p>
     </td>
   </tr>
   <tr>
     <td colspan="8">
    Go to (DD/MM/YYYY):<input type="text" name="date"/> 
                           <input type="submit" value="Submit"/>
     </td>
   </tr>
   <tr>
     <td colspan="2"><a href="">Previous Week</a></td>
     <td colspan="4">Week Of 07 May 2007 (137 of 138)</td>
     <td colspan="2" align="right"><a href="">Next Week</a></td>
   </tr>
   <tr>
     <th class="header"/>
     <xsl:apply-templates select="week[1]/day" mode="header"/>
   </tr>
 </thead>
 <tfoot>
   <xsl:apply-templates select= "student/registeredModules/studentsModules"/>
 </tfoot>
 <tbody>
   <xsl:apply-templates select ="startTime/st"/>
 </tbody>
</xsl:template>

<xsl:template match="studentsModules">
 <tr>
   <td><a href=""><xsl:value-of select="text()"/>- 0</a></td>
<td>- <xsl:value-of select="../../../modules/module/moduleCrn"/></td>
   <td>TBA</td>
 </tr>
</xsl:template>

<xsl:template match="student">
  <xsl:value-of select="@studentNumber"/>
</xsl:template>

<xsl:template match="name">
  <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="day" mode="header">
 <th class="header">
   <xsl:value-of select="@dayOfWeek"/>
 </th>
</xsl:template>

 <xsl:template match="st">
   <xsl:if test="position( ) mod 2 > 0">
     <tr class="header">
       <td><xsl:value-of select="text()"/></td>
     </tr>
   </xsl:if>
 </xsl:template>
</xsl:stylesheet>
please help. im baffled and flumoxed :D

Reply With Quote