Makeing a timetable with XSLT

pnr_dk
pnr_dk used Ask the Experts™
on
I am about to transform a timetable in XML to a nice looking timetable in HTML with XSLT. It shall render the times in the first colon, the next colon shall be Monday with the elements that belong to Monday, and so on. But I don't know how. I have attached an eksample of some XML

Can somone please helt med :-)
Thanks in advance!
<?xml version="1.0" encoding="utf-8" ?>
<Timetable>
    <TimetableEvent>
        <Date>2010-01-15</Date>
        <WeekdayNumber>5</WeekdayNumber>
        <Weekday>Frieday </Weekday>
        <StartTime>09:05</StartTime>
        <EndTime>09:50</EndTime>
        <FormDescription>Lesson... </FormDescription>
    </TimetableEvent>
    <TimetableEvent>
        <Date>2010-01-15</Date>
        <WeekdayNumber>5</WeekdayNumber>
        <Weekday>Frieday </Weekday>
        <StartTime>10:00</StartTime>
        <EndTime>10:45</EndTime>
        <FormDescription>Lesson... </FormDescription>
    </TimetableEvent>
    <TimetableEvent>
        <Date>2010-01-15</Date>
        <WeekdayNumber>5</WeekdayNumber>
        <Weekday>Frieday </Weekday>
        <StartTime>10:00</StartTime>
        <EndTime>10:45</EndTime>
        <FormDescription>Lesson... </FormDescription>
    </TimetableEvent>
    <TimetableEvent>
        <Date>2010-01-11</Date>
        <WeekdayNumber>1</WeekdayNumber>
        <Weekday>Monday </Weekday>
        <StartTime>8:15</StartTime>
        <EndTime>9:00</EndTime>
        <FormDescription>Lesson... </FormDescription>
    </TimetableEvent>
    <TimetableEvent>
        <Date>2010-01-12</Date>
        <WeekdayNumber>1</WeekdayNumber>
        <Weekday>Thuesday </Weekday>
        <StartTime>8:15</StartTime>
        <EndTime>9:00</EndTime>
        <FormDescription>Lesson... </FormDescription>
    </TimetableEvent>
</Timetable>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi pnr_dk,
Please look at the sample below.
If it not clear how does it work, please ask questions.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
	<xsl:key name="t" match="TimetableEvent" use="StartTime"/>
	<xsl:template match="/Timetable">
	  
	   <TABLE border="1" width="100%">
		<COL width="16%"/>
		<COL width="16%"/>
		<COL width="16%"/>
		<COL width="16%"/>
		<COL width="16%"/>
		<COL width="20%"/>
   
		<xsl:for-each select="TimetableEvent[generate-id(.) = generate-id(key('t', StartTime))]">
			<xsl:sort select="number(substring-before(StartTime,':'))*100+number(substring-after(StartTime,':'))" 
				data-type="number" order="ascending"/>
			<xsl:variable name="time" select="StartTime"/>  
	       <TR>
			<TD><xsl:value-of select="StartTime"/></TD>
		<TD><xsl:value-of select="../TimetableEvent[StartTime = $time and normalize-space(Weekday)='Monday']"/>&#xA0;</TD>
		<TD><xsl:value-of select="../TimetableEvent[StartTime = $time and normalize-space(Weekday)='Tuesday']"/>&#xA0;</TD>
		<TD><xsl:value-of select="../TimetableEvent[StartTime = $time and normalize-space(Weekday)='Wednesday']"/>&#xA0;</TD>
		<TD><xsl:value-of select="../TimetableEvent[StartTime = $time and normalize-space(Weekday)='Thuesday']"/>&#xA0;</TD>
		<TD><xsl:value-of select="../TimetableEvent[StartTime = $time and normalize-space(Weekday)='Frieday']"/>&#xA0;</TD>
	       </TR>
  		</xsl:for-each>
	   </TABLE>
	</xsl:template>
</xsl:stylesheet>

Open in new window

Author

Commented:
Perfect! Thanks very much!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial