2012-09-17 73 views
2

想象一下,我有以下需要映射的xml文件。將非分層數據映射到分層數據

來源

<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> 

目標

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

現在,我應該如何對應的父權的人在BizTalk地圖?

感謝

回答

1

如果您更改您的BizTalk BTM地圖使用xslt directly,而不是視覺蜘蛛網,然後應用下面的XSLT(明顯的BizTalk通常需要一個命名空間爲好)。

<?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> 

如果要包括沒有父母誰以及個人,然後更改第一apply-templates到:

<xsl:apply-templates select="Person" />