Вот метод, который использует функцию для каждой группы и переменную промежуточного итога.
<?for-each:record_set?>
<?xdoxslt:set_variable($_XDOCTX,'running_amount',0)?>
<?for-each-group:record;transaction_id?>
<?xdoxslt:set_variable($_XDOCTX,'running_amount', xdoxslt:get_variable($_XDOCTX,'running_amount')+amount)?>
<?end for each group?>
<?end for each?>
Non-Unique Sum:<?sum(record/amount)?>
Unique Sum<?xdoxslt:get_variable($_XDOCTX,'running_amount')?>
<?end for each?>
Пример данных
<record_set>
<record>
<transaction_id>1</transaction_id>
<amount>200</amount>
</record>
<record>
<transaction_id>1</transaction_id>
<amount>200</amount>
</record>
<record>
<transaction_id>2</transaction_id>
<amount>300</amount>
</record>
<record>
<transaction_id>3</transaction_id>
<amount>400</amount>
</record>
<record>
<transaction_id>1</transaction_id>
<amount>200</amount>
</record>
<record>
<transaction_id>4</transaction_id>
<amount>200</amount>
</record>
<record>
<transaction_id>2</transaction_id>
<amount>300</amount>
</record>
</record_set>