我想对每个国家/地区的城市人口进行总和。鉴于下面的示例代码,它不起作用。你能帮我让它工作吗
输入是
<cities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org file:/D:/Oracle/JDev11116/jdeveloper/jdev/MyWork/TelenorFTPIssueApp/XSLTGroupProj/MySchema.xsd" xmlns="http://www.example.org">
<city name="Milano" country="Italia" pop="5"/>
<city name="Paris" country="France" pop="7"/>
<city name="München" country="Deutschland" pop="4"/>
<city name="Lyon" country="France" pop="2"/>
<city name="Venezia" country="Italia" pop="1"/>
</cities>
期望输出是
<?xml version = '1.0' encoding = 'UTF-8'?>
<ns1:Out xmlns:ns1="http://www.example.org" >
<ns1:line>
<ns1:position>1</ns1:position>
<ns1:country>Italia</ns1:country>
<ns1:city>Milano, Venezia</ns1:city>
<ns1:population>6</ns1:population>
</ns1:line>
<ns1:line>
<ns1:position>2</ns1:position>
<ns1:country>France</ns1:country>
<ns1:city>Paris, Lyon</ns1:city>
<ns1:population>9</ns1:population>
</ns1:line>
<ns1:line>
<ns1:position>3</ns1:position>
<ns1:country>Deutschland</ns1:country>
<ns1:city>München</ns1:city>
<ns1:population>4</ns1:population>
</ns1:line>
</ns1:Out>
我正在工作的 XSL 是
<xsl:stylesheet version="1.0" xmlns:ns1="http://www.example.org" >
<xsl:key match="ns1:city" name="count_name" use="@country"/>
<xsl:template match="/">
<ns1:Out>
<xsl:for-each select="ns1:cities/ns1:city[count(. | key('count_name', @country)[1]) = 1]" >
<ns1:line>
<ns1:position>
<xsl:value-of select="position()"/>
</ns1:position>
<ns1:country>
<xsl:value-of select="@country"/>
</ns1:country>
<ns1:city>
<xsl:for-each select="key('count_name', @country)">
<xsl:value-of select="key('count_name',@city)" separator=", "/>
</xsl:for-each>
</ns1:city>
<ns1:population>
<xsl:for-each select="key('count_name', @country)">
<xsl:value-of select="sum(key('count_name', @population))" />
</xsl:for-each>
</ns1:population>
</ns1:line>
</xsl:for-each>
</ns1:Out>
</xsl:template>
</xsl:stylesheet>