1

I have a flat file coming in where each record is a customer and it has a shipto and billto address in that record. The output schema has a customer record with an address child node. I don't know how to map the 2 addresses from the incoming record to sibiling child nodes of the customer record.

I have an input file that is defined like:

<customer>
    <customernum/>
    <shipaddrcity/>
    <shipaddrstate/>
    <shipaddrzip/>
    <billaddrcity/>
    <billaddrstate/>
    <billaddrzip/>
</customer>

The output needs to end up looking like:

<customer>
    <customernum/>
    <addr>
        <type/>
        <city/>
        <state/>
        <zip/>
    </addr> 
    <addr>
        <type/>
        <city/>
        <state/>
        <zip/>
    </addr>
</customer>

I'm quite new to biztalk and have been unable to find any decent examples of how to complete this using the Biztalk Mapper. I'm also willing to listen to how to do this with xslt.

aintnoprophet
  • 489
  • 4
  • 8
  • "* I'm also willing to listen to how to do this with xslt.*" Doing this in XSLT is trivial. Spending an hour with an online tutorial and you will know how. – michael.hor257k Nov 10 '15 at 18:39
  • 2
    What have you tried and what were the results? Here is a blog that shows one example http://hestia.typepad.com/flatlander/2007/01/mapping_fixed_e.html – Dijkgraaf Nov 10 '15 at 19:19
  • Thanks Dijkgraaf. The table looping is what I've been trying to get to work. My actual mapping schemas are more complicated but I just needed to get some examples of the simpler schemas first. I really have to start simple at this point because I don't know enough about Biztalk yet to ask useful questions. – aintnoprophet Nov 10 '15 at 20:17

1 Answers1

3

You probably want something specific to BizTalk, and I don't know anything about BizTalk, but this might be helpful to you any way.

Given an input document of ...

<customers>
<customer>
    <customernum>1</customernum>
    <shipaddrcity>Cairns</shipaddrcity>
    <shipaddrstate>QLD</shipaddrstate>
    <shipaddrzip>b</shipaddrzip>
    <billaddrcity>Sydney</billaddrcity>
    <billaddrstate>NSW</billaddrstate>
    <billaddrzip>c</billaddrzip>
</customer>
<customer>
    <customernum>2</customernum>
    <shipaddrcity>d</shipaddrcity>
    <shipaddrstate>WA</shipaddrstate>
    <shipaddrzip>e</shipaddrzip>
    <billaddrcity>Melbourne</billaddrcity>
    <billaddrstate>Vic</billaddrstate>
    <billaddrzip>f</billaddrzip>
</customer>
</customers>

... this XSLT 1.0 stylesheet ...

<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

<xsl:output omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="customer">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()[not(
      self::shipaddrstate|
      self::shipaddrzip  |
      self::billaddrstate|
      self::billaddrzip   )]"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="shipaddrcity">
  <addr>
    <type>ship</type>
    <city><xsl:value-of select="." /></city>
    <xsl:apply-templates select="../(shipaddrstate|shipaddrzip)" />
  </addr> 
</xsl:template>

<xsl:template match="billaddrcity">
  <addr>
    <type>bill</type>
    <city><xsl:value-of select="." /></city>
    <xsl:apply-templates select="../(billaddrstate|billaddrzip)" />
  </addr> 
</xsl:template>

<xsl:template match="shipaddrstate|billaddrstate">
  <state><xsl:value-of select="." /></state>
</xsl:template>

<xsl:template match="shipaddrzip|billaddrzip">
  <zip><xsl:value-of select="." /></zip>
</xsl:template>

</xsl:transform>

... when applied to the input document, will yield ...

<customers>
   <customer>
      <customernum>1</customernum>
      <addr>
         <type>ship</type>
         <city>Cairns</city>
         <state>QLD</state>
         <zip>b</zip>
      </addr>
      <addr>
         <type>bill</type>
         <city>Sydney</city>
         <state>NSW</state>
         <zip>c</zip>
      </addr>
   </customer>
   <customer>
      <customernum>2</customernum>
      <addr>
         <type>ship</type>
         <city>d</city>
         <state>WA</state>
         <zip>e</zip>
      </addr>
      <addr>
         <type>bill</type>
         <city>Melbourne</city>
         <state>Vic</state>
         <zip>f</zip>
      </addr>
   </customer>
</customers>
Sean B. Durkin
  • 12,659
  • 1
  • 36
  • 65