我很难根据需要应用的某些合并规则对一组XML进行排序。我在XQuery 1.0中这样做,并且一直在玩独特值函数,但却很难将我需要的所有记录联系起来。在XQUERY中排序和合并
我尝试应用的逻辑是
- 需要有存在的频率和付款人和地方贡献类型是一样的每个组合中的一种发生。
- 出现一次时是具有最近的日期是组合的实例
- 如果细节出现在使用相同的,最近的日期,日期,付款人和频率则需要对它们进行合并,使得同一记录显示该频率和该特定日期的付款人的金额是该日期支付的总金额。
- 如果列表中存在超过记录,则需要合并详细信息以得出具有最近日期的组合的实例。
任何帮助将非常感激。
<transaction_history>
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employer</payer>
<amount>5042.38</amount>
<frequency>Quarterly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employer</payer>
<amount>4676.94</amount>
<frequency>Monthly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type B" currency="GBP">
<date>2015-09-08</date>
<payer>Employer</payer>
<amount>4317.52</amount>
<frequency>Monthly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employer</payer>
<amount>9393.11</amount>
<frequency>Quarterly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-10-02</date>
<payer>Employee</payer>
<amount>3944.49</amount>
<frequency>Monthly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type B" currency="GBP">
<date>2015-12-31</date>
<payer>Employee</payer>
<amount>3675.85</amount>
<frequency>Monthly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type B" currency="GBP">
<date>2015-10-02</date>
<payer>Employee</payer>
<amount>3385.69</amount>
<frequency>Monthly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employee</payer>
<amount>7369.64</amount>
<frequency>Monthly</frequency>
</contribution_transaction>
</transaction_history>
在
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employer</payer>
<amount>5042.38</amount>
<frequency>Quarterly</frequency>
</contribution_transaction>
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employer</payer>
<amount>5042.38</amount>
<frequency>Quarterly</frequency>
</contribution_transaction>
的例子会导致:
<contribution_transaction contribution_type="Type A" currency="GBP">
<date>2015-12-31</date>
<payer>Employer</payer>
<amount>10084.76</amount>
<frequency>Quarterly</frequency>
</contribution_transaction>
应该发生什么如果有多个'contribution_transaction'具有相同的'frequency','payer'和'date'? –
嗨,Leo,那么金额将需要加总,然后导致只有一个contribution_transaction。实际上我需要考虑贡献类型属性,我已经意识到我忘了包含这些属性。 – user1905307