I'm afraid a sample that would demonstrate what I'm talking about would be too big to post here. I've narrowed it down now and believe that what's happening relates to having to flush a twig after the document is parsed in order to obtain the last element. For some reason the last Item is just one huge concatenated block of text. How big can your code get before it's just too big to post?