这是我的xml:
<countries>
<country>
<name> .....</name>
<capital>....</capital>
<continent>....</continent>
</country>
.
.
.(a lot of countries)..
<countries>
我创建了一个包含2列的html表(使用xslt(,表示每个国家的名称和首都。但现在我想为每个大陆创建一个表,每个表都包含属于该大陆的所有国家的列表,我不知道如何进行!谢谢你的帮助!这是我的XSLT:的快速视图
<table border="3" width="100%" align="center">
<tr>
<th>Name</th>
<th>Capital</th>
</tr>
<xsl:for-each select="countries/country">
<tr>
<td >
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="capital"/>
</td>
</tr>
</xsl:for-each>
试试这个XSLT1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:key name="Continent" match="country" use="continent"/>
<xsl:template match="countries">
<countries>
<xsl:for-each
select="//country[generate-id(.) = generate-id(key('Continent', continent)[1])]">
<continent><xsl:value-of select="continent"/></continent>
<table border="3" width="100%" align="center">
<tr>
<th>Name</th>
<th>Capital</th>
</tr>
<xsl:for-each select="key('Continent', continent)">
<tr>
<td >
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="capital"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</countries>
</xsl:template>
</xsl:stylesheet>
XSLT 1.0请参阅https://xsltfiddle.liberty-development.net/naZXVEE
XSLT 2.0请参阅https://xsltfiddle.liberty-development.net/naZXVEE/1