选择使用XSL样式表

时间:2013-07-10 03:05:58

标签: xml xslt

<?xml version = "1.0" encoding = "UTF-8"?>
<?xml-stylesheet type="text/xsl" href="student-stylesheet.xsl"?>
<students>
    <student student-number = "1625344">
        <program> BIT </program>
        <study-model> on-campus </study-model>
        <student-type> domestic </student-type>
    </student>
    <student student-number = "2341235">
        <program> MIT </program>
        <study-model> distance </study-model>
        <student-type> international </student-type>
    </student>
    <student student-number = "1234567">
        <program> BMM </program>
        <study-model> on-campus </study-model>
        <student-type> domestic </student-type>
    </student>
    <student student-number = "8899009">
        <program> MIT </program>
        <study-model> on-campus </study-model>
        <student-type> domestic </student-type>
    </student>
    <student student-number = "0987654">
        <program> BIT </program>
        <study-model> on-campus </study-model>
        <student-type> domestic </student-type>
    </student>
</students>

我试图选择底部学生编号并将其显示为没有标题的表格,只包含学生编号,课程,学习模式和学生类型。

    <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Program</th>
        <th>Student Model</th>
        <th>Student Type</th>
      </tr>
      <tr>
        <td><xsl:value-of select="students/student/program"/></td>
        <td><xsl:value-of select="students/student/study-model"/></td>
        <td><xsl:value-of select="students/student/student-type"/></td>
      </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

这是我目前的sylesheet,它选择了第一个学生,而不是最后一个,也缺少学生编号

1 个答案:

答案 0 :(得分:1)

要获取学生编号,您应将新的TD设为<td><xsl:value-of select="students/student/@student-number"/></td>。如果您只想获取上一个学生的信息,您应该使用类似<xsl:value-of select="students/student[last()]/@student-number"/>

的谓词