Quantcast
Channel: Mapping – SANDRO PEREIRA BIZTALK BLOG
Viewing all articles
Browse latest Browse all 36

BizTalk Training – Mapping – How to implement multi-level Muenchian grouping in BizTalk Maps

$
0
0

I already talked about Muenchian Grouping in BizTalk Maps in the past:

Inspired by a question in BizTalk Server Forums: XSLT Mapping Question (Summing Values)… I decided to solved this problem and publish this sample to help this user… what can I say… I simply love mapping problems!!!

So how can we can we perform multi-level Muenchian grouping in BizTalk Maps and perform some mathematical operations on this group?

You can read more about the problem in the thread, nut basically the problem is: To sum all records and create a unique record for records having same account type and city!

Solution

multi-level-Muenchian-grouping-sample1

Add two scripting functoids to the map:

  • In the first, configure to an “Inline XSLT Call Template” and put key expression
    <xsl:key name="groups" match="Record" use="concat(City, '|', AccountType)"/>
    
  • In the second, configure to an “Inline XSLT” and the rest of the XSL
    <xsl:for-each select="Record[generate-id(.)=generate-id(key('groups',concat(City, '|', AccountType)))]">
       <Record>
          <xsl:variable name="city" select="City/text()" />
          <xsl:variable name="type" select="AccountType/text()" />
    
          <AccountType>
             <xsl:value-of select="$type" />
          </AccountType>
          <City>
             <xsl:value-of select="$city" />
          </City>
    
          <xsl:variable name="negativeTotal" select="sum(//Record[(City = $city) and (AccountType = $type) and (Sign = '-')]/Price)" />
          <xsl:variable name="positiveTotal" select="sum(//Record[(City = $city) and (AccountType = $type) and (Sign = '+')]/Price)" />
          <xsl:choose>
             <xsl:when test="$positiveTotal &gt; $negativeTotal">
                <Sign>+</Sign>
                <Price>
                   <xsl:value-of select="$positiveTotal - $negativeTotal" />
                </Price>
             </xsl:when>
             <xsl:otherwise>
                <Sign>-</Sign>
                <Price>
                   <xsl:value-of select="$negativeTotal - $positiveTotal" />
                </Price>
             </xsl:otherwise>
          </xsl:choose>
       </Record>
    </xsl:for-each>
    
  • Drag a link from the Second Scripting Functoid to the record “Record” in the destination schema;

How to implement multi-level Muenchian grouping in BizTalk Maps (34.9 KB)
Microsoft | MSDN Code Gallery



Viewing all articles
Browse latest Browse all 36

Trending Articles