我想從定義爲一個XML文件diplay一組表如下:如何提取「爲eached」元素的子元素,只用XSLT
<reportStructure>
<table>
<headers>
<tableHeader>Header 1.1</tableHeader>
<tableHeader>Header 1.2</tableHeader>
</headers>
<tuples>
<tuple>
<tableCell>1.1.1</tableCell>
<tableCell>1.2.1</tableCell>
</tuple>
<tuple>
<tableCell>1.1.2</tableCell>
<tableCell>1.2.2</tableCell>
</tuple>
</tuples>
</table>
<table>
...
我使用XSLT和XPath轉換成數據,但在foreach不工作,我希望它的方式:
<xsl:template match="reportStructure">
<xsl:for-each select="table">
<table>
<tr>
<xsl:apply-templates select="/reportStructure/table/headers"/>
</tr>
<xsl:apply-templates select="/reportStructure/table/tuples/tuple"/>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="headers">
<xsl:for-each select="tableHeader">
<th>
<xsl:value-of select="." />
</th>
</xsl:for-each>
</xsl:template
<xsl:template match="tuple">
<tr>
<xsl:for-each select="tableCell">
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>
</tr>
</xsl:template>
雖然我希望它可以輸出每個表標籤一個表,它輸出的所有表頭和單元格中的每個表標籤。
+1一個去答案。 – 2010-11-11 20:26:48
+1好答案。 – 2010-11-11 20:59:27