PuffTMD
PuffTMD

Reputation: 63

BizTalk Mapping Single and Multiple elements

I am trying to transform via the map a single birth name node and multiple surname nodes into a repeating other surname nodes. I'm running into some difficulties that when the birth name node is not present then multiple surname nodes fail to be written.

I've attempted multiple implementations around functoids and xslt call template neither appear to be working, as soon as the birth name is missing no surname elements are output.

Can this be done in functoids from the map ? or does this have to be done via a xslt call template?

Schema Input

<root>
  <Subject>
    <birthname>
      <name>Birthname</name>
    </birthname>
    <multiplesurname>
      <name>surname</name>
    </multiplesurname>
    <multiplesurname>
      <name>surname2</name>
    </multiplesurname>
    <multiplesurname>
      <name>surname3</name>
    </multiplesurname>
  </Subject>
  <Mother></Mother>
  <Farther></Farther>
  <Other></Other>
</root>

Schema Output

<root>
  <persona>
    <Othername>Birthname</Othername>
    <Othername>surname</Othername>
    <Othername>surname2</Othername>
    <Othername>surname3</Othername>
  </persona>
  <personb></personb>
</root>

Upvotes: 0

Views: 907

Answers (3)

PuffTMD
PuffTMD

Reputation: 63

After running into further difficulties with XSLT call-template I found that a solution using functoids was possible and achieved using a combination of looping functoids from the birthname and multiplesurname along with straight link from the source node to the destination node.

Upvotes: 0

Dan Field
Dan Field

Reputation: 21641

You could probably do this with a table looper, but a XSLT call template for it shouldn't be too bad - something like this should work for you:

<xsl:template name="nameFlattener">
    <xsl:param name="birthname"/>
    <xsl:element name="Othername">
        <xsl:value-of select="$birthname"/>
    </xsl:element>
    <xsl:for-each select="//multiplesurname">
        <xsl:element name="Othername">
            <xsl:value-of select="name"/>
        </xsl:element>
    </xsl:for-each>
</xsl:template>

Have your name node from birthname going into that template as the first parameter, and output it to the Othername repeating node on the destination.

Upvotes: 0

John Ernst
John Ernst

Reputation: 1235

I think your problems may be caused by having a name node and then an descendant node also named name. This might be causing an infinite loop for you. Here is some XSLT code that will get the job done for you.

  <xsl:template match="name">
    <xsl:copy>
      <xsl:apply-templates select=".//name" mode="secondName"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="name" mode="secondName">
    <xsl:element name="Othername">
      <xsl:value-of select="."/>
    </xsl:element>
  </xsl:template>

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

Upvotes: 1

Related Questions