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


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

 <university universityName="nottingham University">
 <campus campusName="Wisteria"/>
 <Semester semesterNumber="1"/>
 <student studentNumber="2321557">
   <module Crn="x73236">
     <moduleName>Enterprise Database Systems</moduleName>
   <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>
   <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>
 <building buildingName="COLLB">
   <buildingRoom roomId="collb1">C114</buildingRoom>
   <buildingRoom roomId="collb2">C120</buildingRoom>
   <buildingRoom roomId="collb3">C121</buildingRoom>
   <buildingRoom roomId="collb4">CG76</buildingRoom>
 <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 allocationCrn="83490">
       <registeredModule moduleRef="x73245"/>
       <class classNumber="L02" classType="Laboratory"/>
       <assignedRoom buildingRef="collb3"/>
       <starts startTimeRef="s4"/>
       <ends endTimeRef="e8"/>
  <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"/>
  <day dayOfWeek="Friday">
     <allocation allocationCrn="83476">
       <registeredModule moduleRef="x73236"/>
       <class classNumber="L05" classType="Laboratory"/>
       <assignedRoom buildingRef="collb2"/>
       <starts startTimeRef="s3"/>
       <ends endTimeRef="e5"/>
  <day dayOfWeek="Saturday"/>
  <day dayOfWeek="Sunday"/>
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.

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

<xsl:template name="style">
 <style type="text/css">
     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;}
     #wrapper {width:1200px;height:700px;}

<xsl:template match="timetable">
     <td colspan="3">Student Timetable</td>
     <td colspan="4"><xsl:apply-templates select="student"/></td>
     <td><xsl:apply-templates select="student/name"/></td>
     <td colspan="8" align="right"></td>            
     <td colspan="8">
       <p>Any modules shown at the bottom of the page with a
       zero after it is not timetabled.</p>
   <tr><td colspan="8"/></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 colspan="8">
    Go to (DD/MM/YYYY):<input type="text" name="date"/> 
                           <input type="submit" value="Submit"/>
     <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>
     <th class="header"/>
     <xsl:apply-templates select="week[1]/day" mode="header"/>
   <xsl:apply-templates select= "student/registeredModules/studentsModules"/>
   <xsl:apply-templates select ="startTime/st"/>

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

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

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

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

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

Reply With Quote