实现效果图:
下面是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="chengjidan.xslt"?>
<score>
<student>
<number>001</number>
<hearing>17</hearing>
<collo>24</collo>
<reading>18</reading>
</student>
<student>
<number>002</number>
<hearing>29</hearing>
<collo>35</collo>
<reading>30</reading>
</student>
<student>
<number>003</number>
<hearing>13</hearing>
<collo>18</collo>
<reading>15</reading>
</student>
<student>
<number>004</number>
<hearing>19</hearing>
<collo>26</collo>
<reading>29</reading>
</student>
<student>
<number>005</number>
<hearing>30</hearing>
<collo>32</collo>
<reading>27</reading>
</student>
</score>
这里是我写的xslt代码,实现上图的效果:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:template match="/">
<html>
<head>
<title>英语成绩单</title>
</head>
<body>
<h2 align="center">英语成绩单</h2>
<table border="2" align="center">
<tr align="center">
<td>学号</td>
<td>听力</td>
<td>口语</td>
<td>阅读</td>
<td>总分</td>
</tr>
<xsl:for-each select="score/student">
<tr align="center">
<td>
<xsl:value-of select="number"/>
</td>
<xsl:choose>
<xsl:when test="hearing < 18">
<td bgcolor="#ffff00">
<xsl:value-of select="hearing"/>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:value-of select="hearing"/>
</td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="collo < 20">
<td bgcolor="#ffff00">
<xsl:value-of select="collo"/>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:value-of select="collo"/>
</td>
</xsl:otherwise>
</xsl:choose>