I'm trying to display a university courses timetable using XSLT. My DTS looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT timetable (day,day,day,day,day,day,day)>
<!ELEMENT day (session)*>
<!ELEMENT session (begin,end,(course?))>
<!ELEMENT course (#PCDATA)>
<!ELEMENT begin (#PCDATA)>
<!ELEMENT end (#PCDATA)>
I want to display all the courses in a Day/Hour table that looks something like this (excuse the horrible design):
Trouble is, I want to do a for each
clause, but just on regular numbers, not on parts of the xml. Is that possible with XSLT? For example, it would probably look something like this:
/* for each time = 8..17, do: */
<xsl:for-each select="timetable/day">
<xsl:value-of select="session[[begin</*time*/ or begin=/*time*/]/course" />
</xsl:for-each>
You would require to have 2 for each loops. one to iterate over the days of week and one for the hours of the day. The hours of the day could be solved with XSLT 2.0 easily like this:
See this for a complete coverage of sequences and ranges.
in XSLT 2.0:
plus a bit of work on the formatting.
You can use recursion:
Output:
You can use recursion
(slightly adapted from xsl-list@mulberrytech.com)