为什么 for-each 在我的 xslt 文件中不起作用

Why for-each is not working in my xslt file

我不知道为什么我的 for-each 语句不是 working.I 检查了其他帖子,但我没有找到 reason.If 有人可以帮助我吗?
这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="Student.xslt"?>
<students xmlns = "urn:students">
  <student>
    <name>Pesho</name>
    <sex>Both</sex>
    <birthdate>1990-01-01</birthdate>
    <phone>0888112233</phone>
    <email>azsympesho@mail.bg</email>
    <course>Beginners For Dummies</course>
    <specialty>Dummy</specialty>
    <facultyN>99</facultyN>
    <exams>
      <name>Math</name>
      <tutor>Gosho</tutor>
      <score>90</score>
    </exams>
    <enrollment>
      <date>2015-11-01</date>
      <examScore>5</examScore>
    </enrollment>
    <endorsements>some</endorsements>
  </student>
  <student>
    <name>Gosho</name>
    <sex>Female</sex>
    <birthdate>1970-01-01</birthdate>
    <phone>0888332211</phone>
    <email>azsymgosho@mail.bg</email>
    <course>Beginners For Dummies</course>
    <specialty>Beginner</specialty>
    <facultyN>66</facultyN>
    <exams>
      <name>Biology</name>
      <tutor>Pesho</tutor>
      <score>90</score>
    </exams>
    <enrollment>
      <date>2015-12-01</date>
      <examScore>4</examScore>
    </enrollment>
    <endorsements>other</endorsements>
  </student>
</students>

这是 xslt 文件:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
      <html>
        <body>
          <h1>Students Info</h1>
          <table bgcolor="#E0E0E0" cellspacing="1">
            <tr bgcolor="#EEEEEE">
              <td>Name</td>
              <td>Sex</td>
              <td>Birth Date</td>
              <td>Phone</td>
              <td>Email</td>
              <td>Course</td>
              <td>Specialty</td>
              <td>Faculty №</td>
              <td>Exams
                <td>Name</td>
                <td>Tutor</td>
                <td>Score</td>
              </td>                
              <td>Enrollment
                <td>Date</td>
                <td>Exam Score</td>
              </td>
              <td>Endorsement</td>
              </tr>
           <xsl:for-each select ="/students/student">
          <tr>
            <td>
              <xsl:value-of select="name"/>
            </td>
            <td>
              <xsl:value-of select="sex"/>
            </td>
            <td>
              <xsl:value-of select="birthdate"/>
            </td>
            <td>
              <xsl:value-of select="phone"/>
            </td>
            <td>
              <xsl:value-of select="email"/>
            </td>
            <td>
              <xsl:value-of select="course"/>
            </td>
            <td>
              <xsl:value-of select="specialty"/>
            </td>
            <td>
              <xsl:value-of select="facultyN"/>
            </td>
            <td>
              <xsl:for-each select="exams">
                <td>
                  <xsl:value-of select="name"/>
                </td>
                <td>
                  <xsl:value-of select="tutor"/>
                </td>
                <td>
                  <xsl:value-of select="score"/>
                </td>
              </xsl:for-each>
            </td>
            <td>
              <xsl:for-each select="enrollment">
                <td>
                  <xsl:value-of select="date"/>
                </td>
                <td>
                  <xsl:value-of select="examScore"/>
                </td>
              </xsl:for-each>
            </td>
            <td>
              <xsl:value-of select="endorsement"/>
            </td>
          </tr>
        </xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>

................................................ ..................................................... ......

这是一个命名空间问题。

urn:students 的名称空间前缀声明添加到您的样式表:

<xsl:stylesheet version="2.0"
                xmlns:s="urn:students"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

然后在您的 xsl:for-each/@select XPath 中使用它:

       <xsl:for-each select ="/s:students/s:student">

对样式表中的所有 XPath 全面执行此操作。