Joining data from multiple sources onto one record

Hi! Not sure this is possible, but…

…I have a local collection that gets indexed nightly. The ingested files consist of XML generated from one of our systems (let’s call it PRIMARY).
I have xml data from another system (SECONDARY) that is linked to a certain key/field in the PRIMARY system (the field is mapped metadata with an xpath), so for example:

PRIMARY:

<record>
<id>123456</id>
<title>title</title>
</record>

SECONDARY :

    <record>
    <ref_id>123456</ref_id>
    <extra>extra data here</extra>
    </record>

Is there any easy way to ingest/index the SECONDARY data and somehow map the contents to the correct record in PRIMARY based on the linked field? Or will it be a case of doing some sort of fancy XML manipulation before it even hits funnelback to get the data in?

Thanks!