我有这样XSL分组通过嵌套参数
<fruits>
<fruit>
<name>banana</name>
<country>Morocco</country>
</fruit>
<fruit>
<name>orange</name>
<country>Morocco</country>
</fruit>
<fruit>
<name>grape</name>
<country>Egypt</country>
</fruit>
</fruits>
一个XML文件,我需要将其组以另一种方式:
<fruits>
<country name="Morocco">
<fruit>
<name>banana</name>
</fruit>
<fruit>
<name>orange</name>
</fruit>
</country>
<country name="Egypt">
<fruit>
<name>grape</name>
</fruit>
</country>
</fruits>
我试图使它与for-each-group
从XSLT 2.0,但它并不好:我不知道如何通过嵌套参数来处理分组,所以我的.xsl文件没有任何好处。
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:for-each-group select="fruits/fruit" group-by="fruits/fruit/country">
<country name="{country}">
<xsl:for-each select="current-group()">
<fruit>
<name> '{name}'/</name>
</fruit>
</xsl:for-each>
</country>
</xsl:for-each-group>
</xsl:stylesheet>
你接近 - 在'组by'表达是相对于'select'ed节点的XPath,所以你只需要'组通过=“国家”' – 2013-04-04 20:12:04