等效节点的条件 BizTalk 映射

Conditional BizTalk mapping for equivalent nodes

我正在尝试在 LoopingNode 上进行某种循环的 BizTalk 映射,如果 Cond1 为假,则创建 Type1。如果 Cond1 为真,则创建 Type2。它看起来像这样:

输入:

root
   - LoopingNode
        - id (string)
        - Cond1 (bool)

输出:

root
   - TargetNode
        <Equivalent>
           - Type1
                - id (string)
           - Type2
                - id (string)

输出应该是这样的

<root>
    <TargetNode type="Type2" id="a" />
    <TargetNode type="Type1" id="q" />
</root>

我已经尝试使用 2 table 循环将第 1 列作为门,但那没有用。我最近的尝试是以 cond 为条件进行值映射。生成的xslt变成了这样:

<xsl:attribute name="xsi:type">
  <xsl:value-of select="'ns0:Type1'" />
</xsl:attribute>
<xsl:if test="string($var:v6)='true'">
  <xsl:variable name="var:v7" select="string(s1:Id/text())" />
  <xsl:attribute name="id">
    <xsl:value-of select="$var:v7" />
  </xsl:attribute>
</xsl:if>
<xsl:attribute name="xsi:type">
  <xsl:value-of select="'ns0:Type2'" />
</xsl:attribute>
<xsl:if test="string($var:v6)='false'">
  <xsl:variable name="var:v10" select="string(s1:Id/text())" />
  <xsl:attribute name="id">
    <xsl:value-of select="$var:v10" />
  </xsl:attribute>
</xsl:if>

并且由于 xsl:if 仅包含 id 标签而不是 <xsl:attribute name="xsi:type"> 标签,因此该值将始终为 Type2,因为它在 xslt 中位于最后。

我宁愿有一个非定制的 xslt 解决方案,但也许这是不可能的。真正的问题比这复杂得多(大约 20 个属性、3 个等效类型和 2 个条件)。但是解决方案应该是一样的。

知道如何在等效节点上进行条件循环吗?

更新: 这是与我的问题相对应的架构 (xsd):

<?xml version="1.0" encoding="utf-16"?>
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns="http://demo.com/schema/" targetNamespace="http://demo.com/schema/" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
  <xs:element name="root" type ="Root">
  </xs:element>
  <xs:complexType name="Root">
    <xs:sequence>
      <xs:element name="TargetNode" type="TargetNode" maxOccurs="unbounded" />
    </xs:sequence>  
  </xs:complexType>
  <xs:complexType name="TargetNode" abstract="true">
    <xs:attribute name="id" type="xs:string" use="required" />
  </xs:complexType>
  <xs:complexType name="Type1">
    <xs:complexContent>
      <xs:extension base="TargetNode">
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="Type2">
    <xs:complexContent>
      <xs:extension base="TargetNode">
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

您正在寻找条件循环。地图应该有:

  • id 个节点之间的直接链接
  • LoopingNodeTargetNode
  • 的循环 functoid
  • 基于Cond1 进行条件循环并输出到Type1Type2
  • 的逻辑functoid

看起来像这样:

那些逻辑 functoid 的配置如下:

如果您使用 equals 而不是 equals,则两者可以具有相同的配置 - 或者使用两个 equals 并将其中一个中的 Condition2 设置为 false。

您可以在 MSDN 阅读更多关于条件循环的信息。

基于此 XML 输入:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Schema1">
    <LoopingNode Cond1="true" id="id_0"/>
    <LoopingNode Cond1="true" id="id_1"/>
    <LoopingNode Cond1="false" id="id_2"/>
    <LoopingNode Cond1="true" id="id_3"/>
</ns0:Root>

我得到这个输出:

<?xml version="1.0"?>
<ns0:root xmlns:ns0="http://demo.com/schema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ns0:TargetNode id="id_0" xsi:type="ns0:Type1"/>
  <ns0:TargetNode id="id_1" xsi:type="ns0:Type1"/>
  <ns0:TargetNode id="id_2" xsi:type="ns0:Type2"/>
  <ns0:TargetNode id="id_3" xsi:type="ns0:Type1"/>
</ns0:root>