In the other comment I found it is even simpler, unless I missed something:
```
if (!id) {
    listIdCounter += 1;
    id = "X" + listIdCounter;
} else {
    id = "Y" + id;
}
```
Assumes that the xml:id are unique, as well as the listIdCounter. Together with the prefixes there should be no clash (due to the namespacing).