well, let me outline a way of implementing that:
firstly, make sure you have an exhaustive list of versions.
secondly, make sure you have a list of generated items for each version.
next, iterate through each version and add it to a version list.
what you would do now is iterate through each version, pick the first item literal, remove it from alls the other version item lists
if the item is part of all of the version lists, you print a string that basically does what you did before "list.add(x)", where x is the literal.
if not, you add to a conditional list a sub string that conatins is an or operation along with the version.
now you can copy that string, which basically does what you asked for.