2

Imagine I have the following xml files that I need to map.

Source

<Persons>
    <Person>
        <Id>2</Id>
        <ParentId>3</ParentId>
        <Name>Some dude</Name>
    </Person>
    <Person>
        <Id>3</Id>
        <ParentId></ParentId>
        <Name>Some dude2</Name>
    </Person>
</Persons>

Destination

<Persons>
    <Person>
        <Name>Some dude</Name>
        <Parent>
            <Name>Some dude2</Name>
        </Parent>
    </Person>
</Persons>

Now, how should I correspond the right parent to the person in biztalk map?

Thanks

Davita
  • 8,928
  • 14
  • 67
  • 119

1 Answers1

1

If you change your BizTalk BTM map to use xslt directly instead of the visual spiderweb, and then apply the following xslt (obviously BizTalk will typically require a namespace as well).

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="Persons">
        <Persons>
            <xsl:apply-templates select="Person[normalize-space(ParentId/text()) != '']" />
        </Persons>
    </xsl:template>

    <xsl:template match="Person">
        <Person>
            <Name>
                <xsl:value-of select="Name/text()"/>
            </Name>
            <Parent>
                <Name>
                    <xsl:variable name="parentId" select="ParentId/text()" />
                    <xsl:value-of select="/Persons/Person[Id=$parentId]/Name/text()" />
                </Name>
            </Parent>
        </Person>
    </xsl:template>
</xsl:stylesheet>

If you want to include persons who don't have a parent as well, then change the first apply-templates to:

<xsl:apply-templates select="Person" />
Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285