在 BizTalk Server 中,映射字段时避免父作用域中的重复项是一个重要的任务,以确保数据的准确性和一致性。以下是一些基础概念和相关解决方案:
假设我们有两个 XML 消息,需要将其中一个消息的字段映射到另一个消息,并且要确保没有重复项。
源消息 (Source.xml):
<Root>
<Records>
<Record>
<ID>1</ID>
<Name>Alice</Name>
</Record>
<Record>
<ID>2</ID>
<Name>Bob</Name>
</Record>
<Record>
<ID>1</ID>
<Name>Alice</Name>
</Record>
</Records>
</Root>
目标消息 (Target.xml):
<Root>
<UniqueRecords>
<!-- Mapped records will go here -->
</UniqueRecords>
</Root>
映射 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Template to match the root element -->
<xsl:template match="/">
<Root>
<UniqueRecords>
<xsl:apply-templates select="//Record"/>
</UniqueRecords>
</Root>
</xsl:template>
<!-- Template to match each Record -->
<xsl:template match="Record">
<!-- Check if this record already exists in the output -->
<xsl:if test="not(preceding-sibling::Record[ID=current()/ID and Name=current()/Name])">
<Record>
<ID><xsl:value-of select="ID"/></ID>
<Name><xsl:value-of select="Name"/></Name>
</Record>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<xsl:if test="not(preceding-sibling::Record[ID=current()/ID and Name=current()/Name])">
:Record
是否在其前面的兄弟节点中已经存在具有相同 ID
和 Name
的记录。通过这种方式,可以在 BizTalk Map 中有效地避免父作用域中的重复项,确保数据的准确性和一致性。
领取专属 10元无门槛券
手把手带您无忧上云