I couldn't find an existing method to do this, so this was my solution:
1) Create temporary documents from the second template for every set of repeating data
2) In my main template I have a variable $SECTIONS$ which I replace with a list of variables — $SECTION1$ $SECTION2$ $SECTION3$... etc.
3) Replace each $SECTIONn$ variable in the main document with its respective temporary document from step 1.
This works fine for documents that don't have a lot of repeating data, but for larger documents it isn't practical to create several hundred temporary documents.
Is there another way to accomplish this?