Merging XML Results

I am preparing an XSLT report of Parts + action ECR objects. The Parts are found by two levels of BOM expansion, and the ECN objects by querying for all non-Released ECN.

The client Java script so far is

const report_query = '<Item type="Part" action="get"' +
' select=" item_number, major_rev, state, name, classification, unit"' +
' id="'+inDom.getAttribute('id')+'">' +
' <Relationships>' +
' <Item type="Part Changes" action="get">' +
' </Item>' +
' <Item type="Part BOM" orderby="sort_order" select="sort_order,quantity,related_id(item_number,name)">' +
' <related_id>' +
' <Item type="Part"' +
' select="item_number, major_rev, state, name, classification, unit">' +
' <Relationships>' +
' <Item type="Part Changes" action="get">' +
' </Item>' +
' <Item type="Part BOM" orderby="sort_order" select="sort_order,quantity,related_id(item_number,name)">' +
' <related_id>' +
' <Item type="Part"' +
' select="item_number, major_rev, state, name, classification, unit ">' +
' <Relationships>' +
' <Item type="Part Changes" action="get">' +
' </Item>' +
' </Relationships>' +
' </Item>' +
' </related_id>' +
' </Item>' +
' </Relationships>' +
' </Item>' +
' </related_id>' +
' </Item>' +
' </Relationships>' +
' </Item>' ;

const report_query1 = ' <Item type="ECN" action="get">' +
' <state condition="ne">Released</state>' +
' <Relationships>' +
' <Item type="ECN Affected Item" action="get">' +
' </Item>' +
' </Relationships>' +
' </Item> ';

let query = this.newItem();
query.loadAML(report_query);
query = query.apply();

let query1 = this.newItem();
query1.loadAML(report_query1);
query1 = query1.apply();

I wish to generate XML that can be used to populate an XSLT report. The code is to:
- Iterate through result (the output from the first query that lists the BOM hierarchy)

- for each Part found, output the part's data
- get the part's <id>

- iterate over all the ECN
- for each ECN Affected Item that has the Part <id> as a <new_item_id> or <affected_id>, insert in the xml the ECN's <item_number>

- output the Part XML


After the ECN XMLhas been interleaved with the Part XML, the resulting XML data set will be used as input to an XSLT report.

The XML should look like

<Results>
<Item type='Part'>
...
<!-- Part properties -->
</Item>
<Item type='Part'>
...
<!-- Part properties -->
<Item type='ECN'>
...
<!-- ECN properties -->
</Item>
<Item type='ECN'>
...
<!-- ECN properties if more than one ECN -->
</Item>
</Part>
</Results>

Thanks in advance