使用 xml 在页面上显示 table

Using xml to display a table on a page

我正在尝试在 html 页面上使用 xml 显示 table。

基本上是:

这是一项作业,我只是想学习和改进它。

在我上网查看的过程中,我看到了不同的教程,但 none 显示了我想要的完整步骤。

如果有人能告诉我如何使用我提到的步骤并显示在 table 中的逐步方法,我将不胜感激。

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

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

<xsl:template match="/">
    <html>
    <body>
    <table border="1" cellpadding="3">
        <tr>
          <td colspan="5" align="center">
            <!-- Filter for the project name and display it in a header.  -->
            <h2>
              <font face="tahoma" size="5">
                Status for: <xsl:value-of select="Project/Name" />
              </font>
            </h2>
          </td>
        </tr>
        <!-- Define headers for task information. -->
        <tr>
          <td colspan="5" align="center">
            Tasks:
          </td>
        </tr>
        <tr>
          <th>
            <font color="black">ID</font>
          </th>
          <th>
            <font color="black">Name</font>
          </th>
          <th>
            <font color="black">Priority</font>
          </th>
          <th>
            <font color="black">Start</font>
          </th>
          <th>
            <font color="black">Finish</font>
          </th>
        </tr>
        <!-- Filter for tasks -->
        <xsl:for-each select="Project/Tasks/Task">
          <!-- Exclude summary tasks -->
          <xsl:if test="Summary[.=0]">
            <xsl:choose>
              <!-- Display information for critical tasks with a colored background. -->
              <xsl:when test="Critical[.=1]">
                <tr>
                  <td>
                    <xsl:value-of select="ID"/>
                  </td>
                  <td>
                    <b>
                      <xsl:value-of select="Name"/>
                    </b>
                  </td>
                  <td>
                    <b>
                      <xsl:value-of select="Priority"/>
                    </b>
                  </td>
                  <td>
                    <b>
                      <xsl:value-of select="Start"/>
                    </b>
                  </td>
                  <td>
                    <b>
                      <xsl:value-of select="Finish"/>
                    </b>
                  </td>
                </tr>
              </xsl:when>
              <!-- Display information for noncritical tasks with a white background. -->
              <xsl:otherwise>
                <tr>
                  <td>
                    <xsl:value-of select="ID"/>
                  </td>
                  <td>
                    <xsl:value-of select="Name"/>
                  </td>
                  <td>
                    <xsl:value-of select="Priority"/>
                  </td>
                  <td>
                    <xsl:value-of select="Start"/>
                  </td>
                  <td>
                    <xsl:value-of select="Finish"/>
                  </td>
                </tr>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
        </xsl:for-each>
        <!-- Define headers for overallocated resource information. -->
        <tr>
          <td colspan="5" align="center">
            Overallocated Resources:
          </td>
        </tr>
        <tr>
          <th>
            <font color="black">ID</font>
          </th>
          <th colspan="2">
            <font color="black">Name</font>
          </th>
          <th colspan="2">
            <font color="black">Overtime Rate</font>
          </th>
        </tr>
        <!-- Filter for resources -->
        <xsl:for-each select="Project/Resources/Resource">
          <!-- Sort resources alphabetically by name -->
          <xsl:sort select="Name" />
          <!-- Display information for only resources that are overallocated. -->
          <xsl:if test="OverAllocated[.=1]">
            <tr>
              <td>
                <xsl:value-of select="ID"/>
              </td>
              <td  colspan="2">
                <xsl:value-of select="Name"/>
              </td>
              <td  colspan="2" align="center">
                $<xsl:value-of select="OvertimeRate"/>.00
              </td>
            </tr>
          </xsl:if>
        </xsl:for-each>
      </table>
    </body>
    </html>
</xsl:template>

</xsl:stylesheet>
     

也许你可以尝试这样的事情..填写数据字段并且..dtd 可以包含在xml 验证

以下是有用的教程:http://www.xmlmaster.org/en/article/d01/c07/http://www.codeproject.com/Articles/469723/Rendering-XML-Data-as-HTML-using-XSL-Transformatio