It sounds like you need to do nested repeats where you repeat for 5 idocs, add GS & ISA envelope, send then the outer repeat brings you right back in for the next 5 idocs to be grouped together then enveloped and sent using the outer repeat to bring you through this process until all you idocs are processed.
We did something similar but a bit more difficult since the canonicals received for processing were all individual document yet we needed to group them all into a single ISA envelope. To do this we used TN and queueing to batch up the canonicals. A scheduled service then drained the queue with a similar nested repeat as stated above. This allowed us to batch the immediate delivery canonicals all day and then drain the queue at a scheduled time and send in a batched mode. For our other trading partners that didn’t want the same document batched we just have them attached to processing rules that do not queue but instead do immediate delivery. A fully function option that covers both types of delivery all controlled by processing rules and delivery queues.