printData.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
 
 <!-- 中心模板 -->
 <xsl:template match="/">
  <head>
   <title>学生信息动态加入表中(xsl方式)</title>
  </head>
 
  <body>
   <center>
    我来测试来啦, 请打开门吧,让我进来, 小兔乖乖
    <hr color="blue"/>
    <xsl:apply-templates select="school"/>
    
   </center>
  </body>
 </xsl:template>

    <!--定义模板-->
 <xsl:template match="school">
  <table border="1">
   <caption>学生成绩单</caption>
    <th>学号</th>
    <th>姓名</th>
    <th>java成绩</th>
    <th>oracle成绩</th>
    <th>VB成绩</th>
    <th>备注</th>
         
   <xsl:for-each select="student">
    <xsl:sort order="ascending" select="@id"/>
    
    <xsl:choose>
    <xsl:when test="javaGrade[.&gt;=85][.&lt;=100]"> 
     <tr bgcolor="gray">
      <td><xsl:value-of select="@id"/></td>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="javaGrade"/></td>
      <td><xsl:value-of select="oracleGrade"/></td>
      <td><xsl:value-of select="vbScore"/></td>
      <td>
       <xsl:if test="javaGrade[.&gt;=85][.&lt;=100]">
        <font color="blue">优秀</font>
       </xsl:if>
       <xsl:if test="javaGrade[.&gt;=60][.&lt;85]">
        <font color="gray">良好</font>
       </xsl:if>
       <xsl:if test="javaGrade[.&gt;=0][.&lt;60]">
        <font color="red">不及格</font>
       </xsl:if>
      
      </td>
     </tr>
    </xsl:when>
    <xsl:when test="javaGrade[.&gt;=60][.&lt;85]"> 
     <tr bgcolor="#abcdef">
      <td><xsl:value-of select="@id"/></td>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="javaGrade"/></td>
      <td><xsl:value-of select="oracleGrade"/></td>
      <td><xsl:value-of select="vbScore"/></td>
      <td>
       <xsl:if test="javaGrade[.&gt;=85][.&lt;=100]">
        <font color="blue">优秀</font>
       </xsl:if>
       <xsl:if test="javaGrade[.&gt;=60][.&lt;85]">
        <font color="gray">良好</font>
       </xsl:if>
       <xsl:if test="javaGrade[.&gt;=0][.&lt;60]">
        <font color="red">不及格</font>
       </xsl:if>
      
      </td>
     </tr>
    </xsl:when>
    <xsl:otherwise>
     <tr bgcolor="blue">
      <td><xsl:value-of select="@id"/></td>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="javaGrade"/></td>
      <td><xsl:value-of select="oracleGrade"/></td>
      <td><xsl:value-of select="vbScore"/></td>
      <td>
       <xsl:if test="javaGrade[.&gt;=85][.&lt;=100]">
        <font color="blue">优秀</font>
       </xsl:if>
       <xsl:if test="javaGrade[.&gt;=60][.&lt;85]">
        <font color="gray">良好</font>
       </xsl:if>
       <xsl:if test="javaGrade[.&gt;=0][.&lt;60]">
        <font color="red">不及格</font>
       </xsl:if>
      
      </td>
     </tr>
    </xsl:otherwise>
    
   </xsl:choose>
   </xsl:for-each> 
  </table>
 </xsl:template>


</xsl:stylesheet>

 

Test.xml

<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE connection[
 <!--实体定义区,引用  &add; 同html 的实体引用: &nbsp; 代表空格  -->
 <!ENTITY add "湖南师范大学南校区德智园2-408">
]>

<?xml-stylesheet type="text/xsl" href="printData.xsl"?>
<school>
 <student id="2008180501">
  <name>Joho</name>
  <javaGrade>87</javaGrade>
  <oracleGrade>59</oracleGrade>
  <vbScore>98.3</vbScore>
 </student>
 <student id="2008180502">
  <name>Peter</name>
  <javaGrade>85</javaGrade>
  <oracleGrade>59</oracleGrade>
  <vbScore>98.3</vbScore>
 </student>
 <student id="2008180503">
  <name>finey</name>
  <javaGrade>95</javaGrade>
  <oracleGrade>63</oracleGrade>
  <vbScore>78</vbScore>
 </student>
 <student id="2008180504">
  <name>Fairy</name>
  <javaGrade>69</javaGrade>
  <oracleGrade>59</oracleGrade>
  <vbScore>98.3</vbScore>
 </student>
 <student id="2008180505">
  <name>zhangsan</name>
  <javaGrade>69</javaGrade>
  <oracleGrade>59</oracleGrade>
  <vbScore>80.3</vbScore>
 </student>
    <student id="2008180506">
  <name>lishi</name>
  <javaGrade>55</javaGrade>
  <oracleGrade>59</oracleGrade>
  <vbScore>98.3</vbScore>
 </student> 
</school>