这将工作,假设每一行都有相同数量的属性:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/root">
<table>
<tbody>
<tr>
<xsl:apply-templates select="row[1]" mode="header"/>
</tr>
<xsl:apply-templates select="row" mode="rows"/>
</tbody>
</table>
</xsl:template>
<xsl:template match="row" mode="header">
<xsl:for-each select="attribute::*">
<th><xsl:value-of select="local-name(.)" /></th>
</xsl:for-each>
</xsl:template>
<xsl:template match="row" mode="rows">
<tr>
<xsl:for-each select="attribute::*">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
如果有可能不代表列值额外的属性,你需要通过检查,以过滤掉那些名字什么的。
谢谢@G_H ....这个工程完全像我想要的! – smh0427