RecordToDocument repeats parent for each detail

I am using a LOOP step to convert a recordList into another format of recordList.
The structure displays properly in B2B Integrator, however, when I do a recordToDocument,
I get repeated parent nodes that represent the recordList. To build the itemList recordList I do following:

LOOP (on /items input:/items output:/lineItems)
map (Resulting record looks great in B2B Integrator)

But when I use recordToDocument to convert to xmltext…
I’m getting:
…<detail>
…<lineItems>
…<lineItem>Item #1</lineItem>
…</lineItems>
…<lineItems>
…<lineItem>Item #2</lineItem
…</lineItems>
…</detail>

What I want is:
…<detail>
…<lineItems>
…<lineItem>Item #1</lineItem>
…<lineItem>Item #2</lineItem>
…</lineItems>
…</detail>
(dots added to preserve formatting)

Perhaps that’s just the way recordToDocument works ?
Apparently, recordToDocument does not know how to iterate through recordLists in the child nodes of the record to produce proper output ?

Regards,
Nick

Figured it out. Should not have had the <lineitems> element in the loop.