Months later I reply... please don't think you're wasting your breath...
I have used a variation on your scripts to generate the general structure of the document, and that works great.
However, I have a script which takes a BPMN diagram and generates a "scenarios" style set of steps. It mostly works very well, but it is very slow when it comes to actually constructing the steps list.
Because in custom fragments you can a) only have a single dataset, and b) the hiding via bookmark doesn't work, I have to have several templates for each type of row, which I call once per table entry, which is inordinately slow.
I've stared using this script from within RTF DocumentFragments, which is great for small diagrams, but more than a handful of steps and they fall foul of the 60sec timeout on custom scripts.
I guess I could generate a virtual document down to the level of individual table entries, but I suspect that would also be extremely slow, as I'd have hundreds of virtual document entries, and even with a small handful, my document takes a long time to generate.
I guess that's what lunchtimes are for... :-)