我很難根據需要應用的某些合併規則對一組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