I have tl;dr a bit, but it occurs to me that you need programatic control of a rather intricate visual layout. I would look into Cairo under Python control. You can then output images, pdfs or svgs as needed. You would have control over every last pixel and never have to touch a line of xml.

Hth.