transforming a xml to fill in a table with rows and cols
Posted: Mon Mar 16, 2009 3:20 pm
Hey all,
I have an xml doc with a list of courses their times and days as follows :-
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="XSLTFile.xsl"?>
<school xmlns="http://www.mydomain.com/project"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mydomain.com/project XMLSchema2.xsd">
<courses>
<course>
<title>Discrete Mathematics</title>
<code>COMP2300</code>
<day>Monday</day>
<time>9:00</time>
<location>313</location>
<lecturer>Mr.Arvind Mohais</lecturer>
</course>
<course>
<title>Discrete Mathematics</title>
<code>COMP2300</code>
<day>Wednesday</day>
<time>11:00</time>
<location>313</location>
<lecturer>Mr.Arvind Mohais</lecturer>
</course>
<course>
<title>Discrete Mathematics</title>
<code>COMP2300</code>
<day>Friday</day>
<time>11:00</time>
<location>313</location>
<lecturer>Mr.Arvind Mohais</lecturer>
</course>
<course>
<title>Object Oriented Programming</title>
<code>COMP2200</code>
<day>Monday</day>
<time>11:00</time>
<location>C1</location>
<lecturer>Ms.P.Mohammed</lecturer>
</course>
<course>
<title>Object Oriented Programming</title>
<code>COMP2200</code>
<day>Wednesday</day>
<time>10:00</time>
<location>C1</location>
<lecturer>Ms.P.Mohammed</lecturer>
</course>
<course>
<title>Operating Systems</title>
<code>COMP3100</code>
<day>Tuesday</day>
<time>10:00</time>
<location>312</location>
<lecturer>Ms.N.Atwaroo</lecturer>
</course>
I am trying to put the courses in a week table with the days of the week as the columns and rows with the times. However what is happening it is not leaving blank cells when no course is at that time. Eg. the 10:00 row it have no course on Monday at 10:00 however their are at Wed and Tues but when it is filling it in the table Monday gets fills in with Wed and Tues with Tues etc. so how could i leave out blank cells cause it seems to be happening anytime a write happens it goes to the first cell of that row.
Below is piece of the xslt doc.
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mp="http://www.mydomain.com/project">
<xsl:template match="mp:school/mp:courses">
<html>
<body>
<table>
<tr style="background-color:#ccff00">
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thrusday</th>
<th>Friday</th>
<tr style="background-color:#ccccc">
<td>10:00</td>
<xsl:for-each select="mp:course[mp:time='10:00']">
<!--<xsl:value-of select="child::mp:day='Monday'"/>-->
<xsl:if test="mp:day='Monday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Tuesday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Wednesday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Thrusday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Friday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
</xsl:for-each>
</tr> </tr>
Anyone could lend some help pleaseeee
I have an xml doc with a list of courses their times and days as follows :-
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="XSLTFile.xsl"?>
<school xmlns="http://www.mydomain.com/project"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mydomain.com/project XMLSchema2.xsd">
<courses>
<course>
<title>Discrete Mathematics</title>
<code>COMP2300</code>
<day>Monday</day>
<time>9:00</time>
<location>313</location>
<lecturer>Mr.Arvind Mohais</lecturer>
</course>
<course>
<title>Discrete Mathematics</title>
<code>COMP2300</code>
<day>Wednesday</day>
<time>11:00</time>
<location>313</location>
<lecturer>Mr.Arvind Mohais</lecturer>
</course>
<course>
<title>Discrete Mathematics</title>
<code>COMP2300</code>
<day>Friday</day>
<time>11:00</time>
<location>313</location>
<lecturer>Mr.Arvind Mohais</lecturer>
</course>
<course>
<title>Object Oriented Programming</title>
<code>COMP2200</code>
<day>Monday</day>
<time>11:00</time>
<location>C1</location>
<lecturer>Ms.P.Mohammed</lecturer>
</course>
<course>
<title>Object Oriented Programming</title>
<code>COMP2200</code>
<day>Wednesday</day>
<time>10:00</time>
<location>C1</location>
<lecturer>Ms.P.Mohammed</lecturer>
</course>
<course>
<title>Operating Systems</title>
<code>COMP3100</code>
<day>Tuesday</day>
<time>10:00</time>
<location>312</location>
<lecturer>Ms.N.Atwaroo</lecturer>
</course>
I am trying to put the courses in a week table with the days of the week as the columns and rows with the times. However what is happening it is not leaving blank cells when no course is at that time. Eg. the 10:00 row it have no course on Monday at 10:00 however their are at Wed and Tues but when it is filling it in the table Monday gets fills in with Wed and Tues with Tues etc. so how could i leave out blank cells cause it seems to be happening anytime a write happens it goes to the first cell of that row.
Below is piece of the xslt doc.
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mp="http://www.mydomain.com/project">
<xsl:template match="mp:school/mp:courses">
<html>
<body>
<table>
<tr style="background-color:#ccff00">
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thrusday</th>
<th>Friday</th>
<tr style="background-color:#ccccc">
<td>10:00</td>
<xsl:for-each select="mp:course[mp:time='10:00']">
<!--<xsl:value-of select="child::mp:day='Monday'"/>-->
<xsl:if test="mp:day='Monday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Tuesday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Wednesday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Thrusday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
<xsl:if test="mp:day='Friday'">
<td>
<xsl:value-of select="mp:title"/>
<xsl:element name="br"/>
<xsl:value-of select="mp:location"/>
</td>
</xsl:if>
</xsl:for-each>
</tr> </tr>
Anyone could lend some help pleaseeee