看起来musikk比我解释得更清楚了,但是这里有一个演示xslt,它实现了我理解的您想要的功能。一般来说,避免xsl:for-each for 大多数你认为你应该为每个for使用的东西(例如,在其他语言中你会为每个for使用的东西)。相反,如musikk所说,使用apply templates或call templates。如果您必须多次处理同一内容(例如,生成目录,然后生成正文,然后生成索引),请阅读modes(mode=“foo”)。
  
      <?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="ROW[./PROJECT_CODE='WBS']">
    <h1><xsl:value-of select="PROJECT_CODE"/></h1>
    <table>
      <tr>
        <th>Task Code</th>
        <th>Description</th>
      </tr>
      <xsl:apply-templates/>
    </table>
  </xsl:template>
  <xsl:template match="TASK">
    <tr>
      <td><xsl:value-of select="TASK_CODE"/></td>
      <td><xsl:value-of select="TASK_DESCRIPTION"/></td>
    </tr>
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="text()"/>
</xsl:stylesheet>
  
   这将产生:
  
      <html>
   <body>
      <h1>WBS</h1>
      <table>
         <tr>
            <th>Task Code</th>
            <th>Description</th>
         </tr>
         <tr>
            <td>1</td>
            <td>Customer 1</td>
         </tr>
         <tr>
            <td>1.1</td>
            <td>Product A</td>
         </tr>
         <tr>
            <td>1.2</td>
            <td>Product B</td>
         </tr>
         <tr>
            <td>2</td>
            <td>Customer 2</td>
         </tr>
         <tr>
            <td>2.1</td>
            <td>Product W</td>
         </tr>
      </table>
   </body>
</html>