none
BizTalk Map and XSLT Grouping using Muenchian Method - Help with sample? RRS feed

  • Question

  • Hello,

    I have been trying to understand how to a certain kind of mapping. I'm providing an example below. Basically, in the below example, each order can have multiple items, and each item can have multiple tracking codes:

    I have read that a way is to use XSLT using the Muenchian method. But I am not totally sure on how to accomplish that. Would anyone be able to help me with this?

    Sample input:

    <OrdersFF xmlns="http://BizTalk.MapTest">
      <Order>
        <OrderID>O1</OrderID>
        <ItemID>I1</ItemID>
        <TrackingID>T1</TrackingID>
      </Order>
      <Order>
        <OrderID>O1</OrderID>
        <ItemID>I2</ItemID>
        <TrackingID>T2</TrackingID>
      </Order>
      <Order>
        <OrderID>O1</OrderID>
        <ItemID>I2</ItemID>
        <TrackingID>T3</TrackingID>
      </Order>
      <Order>
        <OrderID>O2</OrderID>
        <ItemID>I3</ItemID>
        <TrackingID>T4</TrackingID>
      </Order>
      <Order>
        <OrderID>O2</OrderID>
        <ItemID>I3</ItemID>
        <TrackingID>T5</TrackingID>
      </Order>
      <Order>
        <OrderID>O3</OrderID>
        <ItemID>I4</ItemID>
        <TrackingID>T6</TrackingID>
      </Order>
    </OrdersFF>

    Expected output:

    <ns0:orders xmlns:ns0="http://BizTalk.MapTest">
      <order>
        <orderid>O1</orderid>
        <items>
          <item>I1</item>
          <shippingdetails>
            <trackingcode>T1</trackingcode>
          </shippingdetails>
        </items>
        <items>
          <item>I2</item>
          <shippingdetails>
            <trackingcode>T2</trackingcode>
          </shippingdetails>
          <shippingdetails>
            <trackingcode>T3</trackingcode>
          </shippingdetails>
        </items>
      </order>
      <order>
        <orderid>O2</orderid>
        <items>
          <item>I3</item>
          <shippingdetails>
            <trackingcode>T4</trackingcode>
          </shippingdetails>
          <shippingdetails>
            <trackingcode>T5</trackingcode>
          </shippingdetails>
        </items>
      </order>
      <order>
        <orderid>O3</orderid>
        <items>
          <item>I4</item>
          <shippingdetails>
            <trackingcode>T6</trackingcode>
          </shippingdetails>
        </items>
      </order>
    </ns0:orders>

    Wednesday, February 3, 2016 8:43 PM

Answers

All replies

  • There's an excellent sample on this from Sandro Pereira at https://sandroaspbiztalkblog.wordpress.com/2009/10/28/biztalk-training-mapping-muenchian-grouping-and-sorting-in-biztalk-maps-without-losing-map-functionalities/

    Also be sure to read his awesome ebook with this and many more samples and explanation on mappings.
    http://www.biztalk360.com/biztalk-mapping-patterns/

    Wednesday, February 3, 2016 8:49 PM
  • Hi Steven,

    In addition to what Eldert suggested, also have look to following articles to have more clarification

    http://www.jenitennison.com/xslt/grouping/muenchian.html

    http://social.technet.microsoft.com/wiki/contents/articles/17985.xslt-muenchian-grouping-biztalk-complex-transformation.aspx

    http://social.technet.microsoft.com/wiki/contents/articles/18845.biztalk-server-2010-grouping-and-debatchingsplitting-inbound-messages-typedpolled-from-wcf-sql-adapter.aspx

    _____

    Maheshkumar S Tiwari|User Page|Blog|Installing Microsoft Azure BizTalk Services SDK

    Thursday, February 4, 2016 5:25 AM
  • I have been trying several times but unfortunately I am unable to get the correct mapping. My last unsuccessful attempt looks like this, which outputs an XML but records are missing. Again, I am new to XSLT so I do appreciate the patience and the help.

    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:s0="http://Romp.BizTalk.MapTest" xmlns:ns0="http://Romp.BizTalk.MapTest">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
    
      <!-- Create a key to match against groups in source schema -->
      <xsl:key name="k1" match="Order" use="OrderID"/>
    
      <xsl:key name="k2" match="Order" use="concat(OrderID,'|',ItemID)"/>
    
      <xsl:key name="k3" match="Order" use="concat(OrderID,'|',ItemID,'|',TrackingID)"/>
    
    
      <xsl:template match="/">
        <xsl:apply-templates select="/s0:OrdersFF" />
      </xsl:template>
    
      <xsl:template match="/s0:OrdersFF">
        <ns0:orders>
    
          <!-- This will loop through our key ("OrderID") -->
          <xsl:for-each select="Order[generate-id(.)=generate-id(key('k1',OrderID))]">
    
            <order>
              <orderid>
                <xsl:value-of select="OrderID/text()" />
              </orderid>
    
              <!-- Another loop... -->
              <xsl:for-each select="Order[generate-id(.)=generate-id(key('k2',concat(OrderID,'|',ItemID)))]">
                <items>
                  <item>
                    <xsl:value-of select="ItemID" />
                  </item>
    
                  <!-- Another loop... -->
                  <xsl:for-each select="Order[generate-id(.)=generate-id(key('k3',concat(OrderID,'|',ItemID,'|',TrackingID)))]">
                    <shippingdetails>
                      <trackingcode>
                        <xsl:value-of select="TrackingID"/>
                      </trackingcode>
                    </shippingdetails>
                  </xsl:for-each>
    
                </items>
              </xsl:for-each>
    
    
    
            </order>
    
          </xsl:for-each>
    
        </ns0:orders>
      </xsl:template>
    </xsl:stylesheet>

    Thursday, February 4, 2016 9:00 PM