Mapping related repeating node to a repeating node on BizTalk Mapper

905 Views Asked by At

I'm trying to do a map on BizTalk 2013, and I'm blocked at this mapping problem (using mapper):

Input message:

<DetailsResponse>
    <HeaderDetails>
        <DocumentNumber>322</DocumentNumber>
    </HeaderDetails>
    <ItemDetails>
        <item>
            <DocumentNumber>322</DocumentNumber>
            <ItemNumber>1</ItemNumber>
            <MaterialNumber>40</MaterialNumber>
            <Description>random description 1</Description>
        </item>
        <item>
            <DocumentNumber>322</DocumentNumber>
            <ItemNumber>2</ItemNumber>
            <MaterialNumber>41</MaterialNumber>
            <Description>random description 2</Description>
        </item>
    </ItemDetails>
    <ScheduleDetails>
        <item>
            <DocumentNumber>322</DocumentNumber>
            <ItemNumber>1</ItemNumber>
            <ConfirmedQuantity>2.000</ConfirmedQuantity>
        </item>
        <item>
            <DocumentNumber>322</DocumentNumber>
            <ItemNumber>2</ItemNumber>
            <ConfirmedQuantity>3.000</ConfirmedQuantity>
        </item>
    </ScheduleDetails>
</DetailsResponse>

Intended output message:

<Response>
    <Data>
        <Items>
            <Item>
                <LineNumber>
                    <Internal>1</Internal>
                </LineNumber>
                <ConfirmedQuantity>
                    <Value>2</Value>
                </ConfirmedQuantity>
                <Article>
                    <Number>40</Number>
                    <Description>random description 1</Description>
                </Article>
            </Item>
            <Item>
                <LineNumber>
                    <Internal>2</Internal>
                </LineNumber>
                <ConfirmedQuantity>
                    <Value>3</Value>
                </ConfirmedQuantity>
                <Article>
                    <Number>41</Number>
                    <Description>random description 2</Description>
                </Article>
            </Item>
        </Items>
    </Data>
</Response>

I want to map ItemsDetails and ScheduleDetails to Item, by "merging" their data based on ItemNumber. I already tried a lots of things but wasn't able to do it yet.

I couldn't find any example about this.Does this pattern have any particular name?

If anyone has any idea that they can share, it would be appreciated.

2

There are 2 best solutions below

0
On

If you convert your map to vanilla XSLT, then the mapping becomes straightforward :

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">

   <xsl:output method="xml" indent="yes"/>

   <xsl:key name="itemSchedules" 
            match="/DetailsResponse/ScheduleDetails/item" 
            use="concat(DocumentNumber,'-',ItemNumber)" />

   <xsl:template match="/DetailsResponse">
      <Response>
         <Data>
            <Items>
               <xsl:apply-templates select="ItemDetails/item" />
            </Items>
         </Data>
      </Response>
   </xsl:template>

   <xsl:template match="item">
      <Item>
         <LineNumber>
            <Internal>
               <xsl:value-of select="ItemNumber"/>
            </Internal>
         </LineNumber>
         <ConfirmedQuantity>
            <Value>
               <xsl:value-of select="format-number(key('itemSchedules', 
                concat(DocumentNumber,'-',ItemNumber))/ConfirmedQuantity,0)" />
            </Value>
         </ConfirmedQuantity>
         <Article>
            <Number>
               <xsl:value-of select="MaterialNumber"/>
            </Number>
            <Description>
               <xsl:value-of select="Description"/>
            </Description>
         </Article>
      </Item>
   </xsl:template>
</xsl:stylesheet>

The xsl:key retains an index of references to the schedule details 'part' of the puzzle, and we create a catenated key of DocumentNumber and ItemNumber.

0
On

The only way I can think to maybe get this working with Functoids is to link ItemDetails and ScheduleDetails with one or more Looping Functoids and using an Equal Functoid to filter the ScheduleDetails based on the current ItemDetail ItemNumber.

It that doesn't work out, your only other option is custom Xslt. A Call Template would be pretty straight forward.