【发布时间】:2021-02-24 15:03:06
【问题描述】:
大家好,我有这个 XML 文件:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="10_schedule.xsl"?>
<Schedule>
<Lesson>
<Title>Artificial Intelligence</Title>
<Lecture Classroom="BA">
<Day>Wednesday</Day>
<Time>09-11</Time>
</Lecture>
<Lecture Classroom="BA">
<Day>Thursday</Day>
<Time>09-11</Time>
</Lecture>
<Professor>Peter</Professor>
</Lesson>
<Lesson>
<Title>Constraint Satisfaction Problems</Title>
<Lecture Classroom="B3">
<Day>Monday</Day>
<Time>19-21</Time>
</Lecture>
</Lesson>
<Lesson>
<Title>Knowledge Representation in Web</Title>
<Lecture Classroom="P200">
<Day>Friday</Day>
<Time>15-17</Time>
</Lecture>
<Professor>David</Professor>
</Lesson>
还有这个 XSL 文件:
enter code here<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Schedule</h2>
<table border="1">
<tr bgcolor="#888888">
<th>Title</th>
<th>Professor</th>
<th>Day</th>
</tr>
<xsl:for-each select="Schedule/Lesson/Lecture">
<xsl:sort data-type="number" select="string-length(substringbefore('|Monday|Tuesday|Wednesday|Thursday|Friday|',@Day))"/>
<tr>
<td>
<xsl:value-of select="../Title" />
</td>
<td>
<xsl:value-of select="../Professor"/>
</td>
<xsl:choose>
<xsl:when test="Day = 'Monday' " >
<td bgcolor="#7d78fc">
<xsl:value-of select="Day"/>
<xsl:value-of select="Title"/>
<xsl:value-of select="Professor"/>
</td>
</xsl:when>
<xsl:when test="Day = 'Tuesday' ">
<td bgcolor="#f6fc78">
<xsl:value-of select="Day"/>
<xsl:value-of select="Title"/>
<xsl:value-of select="Professor"/>
<xsl:apply-templates select="Title"/>
</td>
</xsl:when>
<xsl:when test="Day = 'Wednesday' ">
<td bgcolor="#990033">
<xsl:value-of select="Day"/>
<xsl:value-of select="Title"/>
<xsl:value-of select="Professor"/>
</td>
</xsl:when>
<xsl:when test="Day = 'Friday' ">
<td bgcolor="#00ccff">
<xsl:value-of select="Day"/>
<xsl:value-of select="Title"/>
<xsl:value-of select="Professor"/>
</td>
</xsl:when>
<xsl:when test="Day = 'Thursday' ">
<td bgcolor="#ccccff">
<xsl:value-of select="Day"/>
<xsl:value-of select="Title"/>
<xsl:value-of select="Professor"/>
</td>
</xsl:when>
<xsl:otherwise>
<td bgcolor="#fcc678">
<xsl:value-of select="Day"/>
<xsl:value-of select="Title"/>
<xsl:value-of select="Professor"/>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我正在处理这些问题:首先,我想对一周中的日子进行排序,从星期一到星期五。我用完全不同的方式尝试了它,但似乎没有任何效果。 之后,我想简单地将元素做成表格形式,但我希望它们按天排序并按组着色。我不能为组着色(日、教授、标题、相同颜色),但只能为日列着色。 有什么建议吗?
【问题讨论】:
-
请一次问一个问题。