你也可以试试这个(基于 muenchian 分组):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" />
<xsl:key name="kEntryAttr" match="entry/@*" use="name()" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="entry">
<xsl:variable name="e" select="." />
<tr>
<xsl:for-each select="//entry/@*[count(. | key('kEntryAttr', name() )[1] ) = 1]" >
<td>
<xsl:value-of select="$e/@*[name() = name(current() )]"/>
</td>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template match="*">
<table>
<tr>
<xsl:for-each select="//entry/@*[count(. | key('kEntryAttr', name() )[1] ) = 1]" >
<th>
<xsl:value-of select="name()"/>
</th>
</xsl:for-each>
</tr>
<xsl:apply-templates select="entry" />
</table>
</xsl:template>
</xsl:stylesheet>
这将生成以下输出。
<?xml version="1.0"?>
<table>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td/>
</tr>
<tr>
<td>2</td>
<td/>
<td>3</td>
</tr>
<tr>
<td/>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>