transforming a xml to fill in a table with rows and cols
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Mon Mar 16, 2009 3:12 pm
transforming a xml to fill in a table with rows and cols
Post by Trini_NAtwaroo »
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
-
- Posts: 14
- Joined: Tue Feb 10, 2009 1:50 pm
Re: transforming a xml to fill in a table with rows and cols
Post by JohnBampton »
put the td tags on the outside of the xsl:if statements, that way you will always get a table cell
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service