Это преобразование :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kTrans" match="transaction"
use="concat(Policy_Type,
'+',
Policy_Date,
'+',
State,
'+',
Zip)"/>
<xsl:template match=
"transaction
[generate-id()
=
generate-id(key('kTrans',
concat(Policy_Type,
'+',
Policy_Date,
'+',
State,
'+',
Zip)
)[1]
)
]
">
<transaction>
<xsl:copy-of select="*[not(self::AmountPaid)]"/>
<TotalAmountPaid>
<xsl:value-of select=
"sum(key('kTrans',
concat(Policy_Type,
'+',
Policy_Date,
'+',
State,
'+',
Zip)
)
/AmountPaid
)
"/>
</TotalAmountPaid>
</transaction>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
при применении к следующему документу XML (поскольку исходный документ XML не предоставляется!):
<transactions>
<transaction>
<Policy_Type>A</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>WA</State>
<Zip>98004</Zip>
<AmountPaid>189.32</AmountPaid>
</transaction>
<transaction>
<Policy_Type>B</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>NY</State>
<Zip>111111</Zip>
<AmountPaid>111.11</AmountPaid>
</transaction>
<transaction>
<Policy_Type>A</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>WA</State>
<Zip>98004</Zip>
<AmountPaid>223.05</AmountPaid>
</transaction>
<transaction>
<Policy_Type>B</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>NY</State>
<Zip>111111</Zip>
<AmountPaid>111.11</AmountPaid>
</transaction>
<transaction>
<Policy_Type>C</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>NY</State>
<Zip>111111</Zip>
<AmountPaid>111.11</AmountPaid>
</transaction>
</transactions>
дает требуемый, правильный результат :
<transaction>
<Policy_Type>A</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>WA</State>
<Zip>98004</Zip>
<TotalAmountPaid>412.37</TotalAmountPaid>
</transaction>
<transaction>
<Policy_Type>B</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>NY</State>
<Zip>111111</Zip>
<TotalAmountPaid>222.22</TotalAmountPaid>
</transaction>
<transaction>
<Policy_Type>C</Policy_Type>
<Policy_Date>2012-01-11</Policy_Date>
<State>NY</State>
<Zip>111111</Zip>
<TotalAmountPaid>111.11</TotalAmountPaid>
</transaction>
Объяснение: Группировка мюнхенцев .