【问题标题】:Mapping non-hierarchical data to hierarchical one将非分层数据映射到分层数据
【发布时间】:2012-09-09 18:17:21
【问题描述】:

假设我有以下需要映射的 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 地图中的人对应起来?

谢谢

【问题讨论】:

    标签: xml map mapping biztalk


    【解决方案1】:

    如果您将 Bi​​zTalk 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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-30
      • 2018-11-01
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2014-01-13
      相关资源
      最近更新 更多