title: How to extract the "for eached" element's child elements only with XSLT
body: <p>I want to diplay a set of tables from an XML file defined as follows:</p>
  
  <pre><code>&lt;reportStructure&gt;
    &lt;table&gt;
      &lt;headers&gt;
        &lt;tableHeader&gt;Header 1.1&lt;/tableHeader&gt;
        &lt;tableHeader&gt;Header 1.2&lt;/tableHeader&gt;
      &lt;/headers&gt;
      &lt;tuples&gt;
        &lt;tuple&gt;
          &lt;tableCell&gt;1.1.1&lt;/tableCell&gt;
          &lt;tableCell&gt;1.2.1&lt;/tableCell&gt;
        &lt;/tuple&gt;
        &lt;tuple&gt;
          &lt;tableCell&gt;1.1.2&lt;/tableCell&gt;
          &lt;tableCell&gt;1.2.2&lt;/tableCell&gt;
        &lt;/tuple&gt;
      &lt;/tuples&gt;
    &lt;/table&gt;
    &lt;table&gt;
    ...
  </code></pre>
  
  <p>I am using XSLT and XPath to transform the data, but the foreach does not work the way I expect it to:</p>
  
  <pre><code>      &lt;xsl:template match="reportStructure"&gt;
          &lt;xsl:for-each select="table"&gt;
            &lt;table&gt;
              &lt;tr&gt;
                &lt;xsl:apply-templates select="/reportStructure/table/headers"/&gt;
              &lt;/tr&gt;
              &lt;xsl:apply-templates select="/reportStructure/table/tuples/tuple"/&gt;
            &lt;/table&gt;      
          &lt;/xsl:for-each&gt;
        &lt;/xsl:template&gt;
  
        &lt;xsl:template match="headers"&gt;
          &lt;xsl:for-each select="tableHeader"&gt;
            &lt;th&gt;
              &lt;xsl:value-of select="." /&gt;
            &lt;/th&gt;
          &lt;/xsl:for-each&gt;
        &lt;/xsl:template
  
        &lt;xsl:template match="tuple"&gt;
          &lt;tr&gt;
            &lt;xsl:for-each select="tableCell"&gt;
              &lt;td&gt;
                &lt;xsl:value-of select="." /&gt;
              &lt;/td&gt;
            &lt;/xsl:for-each&gt;
          &lt;/tr&gt;
        &lt;/xsl:template&gt;
  </code></pre>
  
  <p>While I would expect this to output one table per table-tag, it outputs all the table headers and cells for each table-tag.</p>