用XML生成跨行跨列的表格
已有如下的XML
<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="style.xsl"?><Classes> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP211</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>数据库设计</name> <teacher>何家忠</teacher> <room>A205</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Monday</day> <start>11:30</start> <end>13:00</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP211</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>数据库设计</name> <teacher>何家忠</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Tuesday</day> <start>11:30</start> <end>13:00</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP212</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>程序设计II</name> <teacher>柯韦</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Tuesday</day> <start>14:30</start> <end>17:30</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP213</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>操作系统</name> <teacher>林灿堂</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Tuesday</day> <start>10:00</start> <end>11:30</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP213</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>操作系统</name> <teacher>林灿堂</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Thursday</day> <start>11:30</start> <end>13:00</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP214</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>计算机网络</name> <teacher>林灿堂</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Monday</day> <start>10:00</start> <end>11:30</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>COMP214</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>计算机网络</name> <teacher>林灿堂</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Friday</day> <start>11:30</start> <end>13:00</end> </Time> </Class> <Class> <grade>2</grade> <type>S</type> <LessonNumbering> <courseNumbering>MATH211</courseNumbering> <classNumbering>21121</classNumbering> </LessonNumbering> <name>统计学 I</name> <teacher>容佑江</teacher> <room>A309</room> <Duration> <start>2010/9/3</start> <end>2010/12/16</end> </Duration> <Time> <day>Monday</day> <start>14:30</start> <end>16:00</end> </Time> </Class> …………</Classes>
<?xml version="1.0" encoding="GB2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:key name="day" match="/Classes/Class/Time/day" use="."/> <xsl:template match="/Classes"> <table> <tbody> <tr> <xsl:for-each select="Class/Time/day[generate-id()=generate-id(key('day',.))]"> <td valign="top"> <table> <xsl:apply-templates select="/Classes/Class[Time/day=current()]"> <xsl:sort select="Time/start" order="ascending"/> </xsl:apply-templates> </table> </td> </xsl:for-each> </tr> </tbody> </table> </xsl:template> <xsl:template match="Class"> <xsl:variable name="Height" select="(number(substring-before(Time/end, ':') )-number(substring-before(Time/start, ':'))-1)*40" /> <tr> <th style="border: 1px solid black; height:{$Height}px"><xsl:value-of select="name"/> </th> </tr> </xsl:template></xsl:stylesheet>