I've been looking for the best way to do this, but I can't seem to find a clear answer how this should be done.

I have an Arraylist of Files in my Java code, representing a list of xml files which should be merged and written to a new XML file. This is not a fixed length list, I'm estimating it would be between 2-10 files. All these files have a very similar document structure, but some attributes should be summed while merging. For example:

File1

```
<events>
  <commandEvents date="2013-07-16">
    <commandEvent count="1" commandId="update"/>
    <commandEvent count="1" commandId="debug"/>
    <commandEvent count="3" commandId="resume"/>
  </commandEvents>
</events>

```

File 2

```
<events>
  <commandEvents date="2013-07-16">
    <commandEvent count="2" commandId="resume"/>
  </commandEvents>
  <commandEvents date="2013-07-15">
    <commandEvent count="2" commandId="resume"/>
    <commandEvent count="1" commandId="update"/>
  </commandEvents>
</events>

```

Result

```
<events>
  <commandEvents date="2013-07-16">
    <commandEvent count="1" commandId="update"/>
    <commandEvent count="1" commandId="debug"/>
    <commandEvent count="5" commandId="resume"/>
  </commandEvents>
  <commandEvents date="2013-07-15">
    <commandEvent count="2" commandId="resume"/>
    <commandEvent count="1" commandId="update"/>
  </commandEvents>
</events>

```

To clarify, the merging should occur on commandEvents[@date]/commandEvent[@commandId].The commandEvent elements have some more attributes, but these are the same for each element so I've omitted them here. Not all dates will be available in each document.

I first found some answers to go the XSLT route, but I'm quite confused about the XSLT syntax to do this. 
Although I'm not entirely sure about the size that these files may reach, but I would be highly suprised they would be >1mb, so a Java DOM parser as JDOM or XOM might work as well, but I'd have to load all these files at the same time or iterate in pairs.

What is regarded as the best way to do this? And if XSLT is regarded as the best solution, would it be possible to give me some tips for this?