xmlxsltmappingbiztalkedifact

Mapping record from inside a loop to destination record that is not part of the scope


Apologies for the confusing title, but I'm not sure how best to describe this. Basically I have a record in my source schema that is being looped to create 5 different records in the destination schema.

Each of these records is created based on the value of a field in the source schema, so that correct information can be mapped to each. In this case it is address information on buyer, supplier etc.

Each record in the destination schema also has a contact record, that has fields like name, telephone etc.

My task is to map fields from the source schema to the Contact record for the Buyer in the destination schema, but not the contact details from the Buyer in the source schema.

Structure of the Buyer (destination schema)

enter image description here

Structure of the record in the source schema that is being looped upon. I have marked the field which is being checked for a value before creating the different records in the destination schema in blue at the top, and the record that contains the contact details in blue at the bottom.

enter image description here

The reason I can't just map them as usual, is that the CTALoop1 is inside the scope of the current record being mapped. So when the Buyer is being mapped, I can't access the contact details from a different NADLoop1, as they are not inside the looping scope.

My input file contains the following: enter image description here

As you can see, only the NADLoop1 with NAD01 = PO contains the contact details and these aren't being mapped to the buyer as they are outside the scope.

How can I map the CTALoop1 details from another record other than the one that is being looped the destination schema? I won't using XSLT scripts, but it should be said the looping is currently done using the visual mapper and I know that can cause issues when adding XSLT.


Solution

  • I managed to solve it by the following inline XSLT:

    <Contact>
        <Name>
            <xsl:value-of select="/*[local-name()='EFACT_D01B_ORDERS']/*[local-name()='NADLoop1'][*[local-name()='NAD']/*[local-name()='NAD01']='PO']/*[local-name()='CTALoop1']/*[local-name()='CTA']/*[local-name()='C056']/*[local-name()='C05602']"/>
        </Name>
        <Telephone>
        <xsl:value-of select="/*[local-name()='EFACT_D01B_ORDERS']/*[local-name()='NADLoop1'][*[local-name()='NAD']/*[local-name()='NAD01']='PO']/*[local-name()='CTALoop1']/*[local-name()='COM']/*[local-name()='C076'][*[local-name()='C07602'] = 'TE']/*[local-name()='C07601']"/>
        </Telephone>
        <Email>
    <xsl:value-of select="/*[local-name()='EFACT_D01B_ORDERS']/*[local-name()='NADLoop1'][*[local-name()='NAD']/*[local-name()='NAD01']='PO']/*[local-name()='CTALoop1']/*[local-name()='COM']/*[local-name()='C076'][*[local-name()='C07602'] = 'EM']/*[local-name()='C07601']"/>
        </Email>
    </Contact>