During the weekend I spent some hours on this.
You can just save a separate *.mds file for each template.
But this does not take into account updates, so we ended up with a single *.mds file,
then using python's built in xml parser xml.etree.ElementTree and disable everything, then turn on all test that should be on and then turn on based on a template. so in case of Errors I can easily only run that subgroup of tests and save 3hours compared to the full test.
The only tricky part where tests that were parents but not groups, I needed to hardcode as both tests and group.
But what I would say this is pure xml and all xml libraries can surely edit and save it without missing any content.