1

I have an input schema (input_schema) as such:

    ...
<ContactNo>
    <Contact_1>
        <Contact-Type>MOBILE|HOME|WORK</Contact-Type>
        <Contact-SubType>UK|OVERSEAS</Contact-SubType>
        <Contact-CountyCode>44</Contact-CountyCode>
        <Contact-No>01443788800</Contact-No>
        <Contact-Ex>85000</Contact-Ex>
    </Contact_1>
    <Contact_2>
        <Contact-Type>MOBILE|HOME|WORK</Contact-Type>
        <Contact-SubType>UK|OVERSEAS</Contact-SubType>
        <Contact-CountyCode>44</Contact-CountyCode>
        <Contact-No>01443788800</Contact-No>
        <Contact-Ex>85000</Contact-Ex>
    </Contact_2>
    <Contact_3>
        <Contact-Type>MOBILE|HOME|WORK</Contact-Type>
        <Contact-SubType>UK|OVERSEAS</Contact-SubType>
        <Contact-CountyCode>44</Contact-CountyCode>
        <Contact-No>01443788800</Contact-No>
        <Contact-Ex>85000</Contact-Ex>
    </Contact_3>
    ...
</ContactNo>
...

Each one of child nodes to the ContactNo can only occur once (one Contact_1, one Contact_2 and one Contact_3). I need to apply some business logic for the Contact-Type, SubType to construct the Contact-No, but my question is how best would you map this structure across to the relevant out_put schema nodes (these nodes are max occurs 20) but can only have a max of three based on the input_schema schema structure below:

...
<HomeTelephone>
<WorkTelephone>
<MobileTelephone>
...

Sample Input/Output

...
<ContactNo>
    <Contact_1>
        <Contact-Type>HOME</Contact-Type>
        <Contact-SubType>UK</Contact-SubType>
        <Contact-CountyCode />
        <Contact-No>01443788800</Contact-No>
        <Contact-Ex/>
    </Contact_1>
    <Contact_2>
        <Contact-Type>WORK</Contact-Type>
        <Contact-SubType />
        <Contact-CountyCode />
        <Contact-No>01743788800</Contact-No>
        <Contact-Ex>86000</Contact-Ex>
    </Contact_2>
    <Contact_3>
        <Contact-Type>WORK</Contact-Type>
        <Contact-SubType>UK</Contact-SubType>
        <Contact-CountyCode />
        <Contact-No>01443788800</Contact-No>
        <Contact-Ex>85000</Contact-Ex>
    </Contact_3>
    ...
</ContactNo>
...

...
<HomeTelephone>01443788800</HomeTelephone>
<WorkTelephone>0174378880086000</WorkTelephone>
<WorkTelephone>0144378880085000</WorkTelephone>
<MobileTelephone />
...

Currently I am checking Contact-Type (=Home) then mapping the output through a value mapper to a script functoid for data confirmation before mapping the output. This seems to be causing duplicate nodes.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
PuffTMD
  • 63
  • 9

1 Answers1

1

Have you considered using XSLT in your mapping? Not only a lot easier to use than the BizTalk mapper, also a lot more flexible and widely used (you can use XSLT natively in a lot of products).

An appropriate XSLT would result in something like the following:

<xsl:for-each select="ContactNo/*">
  <xsl:if test="position() &lt; 4">
    <xsl:choose>
      <xsl:when test="Contact-Type/text() = 'WORK'">
        <WorkTelephone>
          <xsl:value-of select="Contact-No/text()" />
        </WorkTelephone>
      </xsl:when>
      <xsl:when test="Contact-Type/text() = 'HOME'">
        <HomeTelephone>
          <xsl:value-of select="Contact-No/text()" />
        </HomeTelephone>
      </xsl:when>
      <xsl:when test="Contact-Type/text() = 'MOBILE'">
        <MobileTelephone>
          <xsl:value-of select="Contact-No/text()" />
        </MobileTelephone>
      </xsl:when>
    </xsl:choose>
  </xsl:if>
</xsl:for-each>

This should loop through the first 3 contacts and list them accordingly.

Let me know if this suits your needs.

Disclaimer: haven't tested this out due to time constraints, beware of syntax and typing mistakes. Also I know you were asking for the mapper, I just am convinced the mapper is utterly inferior to the native xslt approach.

zurebe-pieter
  • 3,246
  • 21
  • 38
  • Thank you for your response. Could you explain the test= position() < 4. The map has mainly been completed with functoids, script nodes etc. this is a minor updated that we need to cater for so was looking for a solution within the map. – PuffTMD Mar 11 '16 at 13:26
  • This is to iterate over the first 3 contacts only, which is one of the requirements as far as I can see. the '<' sign does not translate well into xml, so I escape it. I know you prefer a mapper solution, hence the disclaimer. It is possible however to include this, but you would need to convert your mapper to XSLT (Use "validate map" > output xslt). So in fact, a valid answer in my humble opinion. For you to decide. – zurebe-pieter Mar 11 '16 at 13:29