私は以下のようなxmlを持っています(xslt 1.0を使用):
<?xml version="1.0" encoding="utf-8"?>
<receives>
<receive>
<Year>2013</Year>
<money>120</money>
</receive>
<receive>
<Year>2013</Year>
<money>150</money>
</receive>
<receive>
<Year>2014</Year>
<money>130</money>
</receive>
<receive>
<Year>2011</Year>
<money>120</money>
</receive>
</receives>
年ごとにお金でグループ化したいのですが、年がリストにない場合(上記のxmlのように、2011はありません)、次のようにtotalamount=0で結果に2012を入れる必要があります。
<year>2011</year>
<totalamount>120</totalamount>
<year>2012</year>
<totalamount>0</totalamount>
<year>2013</year>
<totalamount>270</totalamount>
<year>2014</year>
<totalamount>130</totalamount>
現在、私は次のようにxsltを終了しました。
<xsl:key name="receive-key" match="receive" use="Year" />
<xsl:template match="/receives">
<xsl:for-each
select="receive[generate-id() = generate-id(key('receive-key', Year))]">
<xsl:sort select="../receive[Year = current()/Year]/Year"></xsl:sort>
<year>
<xsl:value-of select="../receive[Year = current()/Year]/Year" />
</year>
<totalamount>
<xsl:value-of select="sum(../receive[Year = current()/Year]/money)" />
</totalamount>
</xsl:for-each>
</xsl:template>
これは、既存の年でのみお金をグループ化できます。
<year>2011</year>
<totalamount>120</totalamount>
<year>2013</year>
<totalamount>270</totalamount>
<year>2014</year>
<totalamount>130</totalamount>
挿入する方法についてのアイデア
<year>2012</year>
<totalamount>0</totalamount>
結果に?
どうもありがとう!