Stuck a bit with the following and would love some ideas/pointers in the right direction. I have the following XML:
<RecordsCollection>
<CustomerRecord>
<customerId>12345</customerId>
<currency>USD</currency>
</CustomerRecord>
<CustomerRecord>
<customerId>12345</customerId>
<currency>USD</currency>
</CustomerRecord>
<CustomerRecord>
<customerId>90210</customerId>
<currency>USD</currency>
</CustomerRecord>
</RecordsCollection>
What I need to accomplish is to simply produce a single value containing the count of unique currency elements contained with a unique account number. To explain further, the example above contains two entries with the same currency (USD) for the same account number (12345), so they’re counted as 1 and another entry which is also counted as 1. Hence, the example above should result in:
<totalCount>2</totalCount>
Any idea as to how to achieve it? I know how to select distinct account numbers, but what I don’t seem to be able to wrap my head around is how to count the distinct currencies within each account.
Lastly, this has to be done using XSLT 1.0 … any thoughts would be greatly appreciated!
This stylesheet:
Output:
Note: Just grouping by
customerIdandcurrencystring value.Edit: Sorry, miss the
customerIdbefore.