Simple Mapper Question

Home Page Forums BizTalk 2004 – BizTalk 2010 Simple Mapper Question

Viewing 1 reply thread
  • Author
    Posts
    • #16460

      I'm sure the solution is a simple one, but I just can't figure it out. I have a flatfile with data that looks like this:

      A,1
      A,2
      A,3
      B,4
      C,5
      C,6

      And the XML that I want as output is:

      <Parent Value="A">
          <Child Value="1"/>
          <Child Value="2"/>
          <Child Value="3"/>
      </Parent>
      <Parent Value="B"/>
          <Child Value="4"/>
      </Parent>
      <Parent Value="C">
          <Child Value="5"/>
          <Child Value="6"/>
      </Parent>

      I have the document specifications, but I just can't think of how to make this work in the mapper. Can you clue me in?

    • #16462

      Depends on what type of data A,B and C are.

      If they are a small set of known data items that seldom changes then you could use condition functoids
      e.g. if firstfield = "A"
      This would hardcode the values A, B, and C into the map.

      If A,B, and C are part of a large set that does change, i.e. you don't want to hardcode them into the map,
      then you need to use a custom Xslt with Muenchian grouping
      e.g.

      <?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" exclude-result-prefixes="msxsl" version="1.0">
      <xsl:output indent="yes" omit-xml-declaration="yes" version="1.0" method="xml" />
      <xsl:key name="recordkey" match="/root/record" use="firstfield"/>
      <xsl:template match="/">
      <xsl:apply-templates select="/root" />
      </xsl:template>
      <xsl:template match="/root">
       <root>
        <xsl:for-each select="record">
         <xsl:variable name="group" select="key('recordkey', firstfield)"/>
         <xsl:if test="generate-id($group[1]) = generate-id()">
          <Parent>
           <xsl:attribute name="Value">
            <xsl:value-of select="firstfield"/>
           </xsl:attribute>
           <xsl:for-each select="$group">
            <Child>
             <xsl:attribute name="Value">
              <xsl:value-of select="secondfield"/>
             </xsl:attribute>
            </Child>
           </xsl:for-each>
          </Parent>
         </xsl:if>
        </xsl:for-each>
       </root>
      </xsl:template>
      </xsl:stylesheet>

       

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.