【问题标题】:BizTalk mapping issueBizTalk 映射问题
【发布时间】:2012-06-14 13:22:39
【问题描述】:

我有一个映射问题,我正试图在 BizTalk 的映射工具中解决。

考虑以下输入文件:

<person>
    <ID>APersonID</ID>
    <relatives>
        <relative>
            <name>Relative name 1</name>
        </relative>
        <relative>
            <name>Relative name 2</name>
        </relative>
    </relatives>
</person>

注意:相关元素的minOccurs设置为0,相关元素的ma​​xOccurs设置为unbounded。

此输入应映射到以下输出:

<relatives>
    <person>
        <ID>APersonID</ID>
        <relative>Relative name 1</relative>
    </person>
    <person>
        <ID>APersonID</ID>
        <relative>Relative name 2</relative>
    </person>
<relatives>

注意:person 元素的 minOccurs1ma​​xOccursunbounded

我已经将映射与 Looping functoid 一起使用,它将输入文件的相对元素链接到输出文件中的 person 元素。但是现在有一种情况,我得到了以下输入文件:

<person>
    <ID>APersonID</ID>
    <relatives />
</person>

应该映射到哪个

<relatives>
    <person>
        <ID>APersonID</ID>
    </person>
<relatives>

我当前的映射无法处理这种情况。有人可以就如何制作/编辑映射提供建议,以便这两种情况都能奏效吗?

【问题讨论】:

    标签: mapping biztalk


    【解决方案1】:

    事情比起初看起来要复杂一些,因为我们需要在继续之前测试至少存在一个relatives/relative。除了使用 XSLT,我想不出任何其他方法 - 请参阅 here,了解如何从地图中提取 XSLT 并将 BTM 更改为使用 XSLT 而不是视觉函数映射。

    以下 XSLT

    <?xml version="1.0" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
        exclude-result-prefixes="msxsl var"
        version="1.0"
        xmlns:ns0="http://BizTalk_Server_Project5.Schema1">
        <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
        <xsl:template match="/">
            <xsl:apply-templates select="/ns0:person" />
        </xsl:template>
        <xsl:template match="/ns0:person">
            <relatives>
                <xsl:variable name="personId" select="ns0:ID/text()" />
                <xsl:choose>
                    <xsl:when test="not(ns0:relatives) or not(ns0:relatives/ns0:relative)">
                        <person>
                            <ID>
                                <xsl:value-of select="$personId" />
                            </ID>
                        </person>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:for-each select="ns0:relatives/ns0:relative">
                            <person>
                                <ID>
                                    <xsl:value-of select="$personId" />
                                </ID>
                                <relative>
                                    <xsl:value-of select="ns0:name/text()" />
                                </relative>
                            </person>
                        </xsl:for-each>
                    </xsl:otherwise>
                </xsl:choose>
            </relatives>
        </xsl:template>
    </xsl:stylesheet>
    

    产生您描述的输出。 (显然改变你的命名空间来匹配,我假设你有elementFormDefault="qualified"(如果没有,删除ns0前缀)

    【讨论】:

    • 您好,感谢您的回答,制作自定义 XSLT 解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多