【问题标题】:Conditional BizTalk mapping for equivalent nodes等效节点的条件 BizTalk 映射
【发布时间】:2017-06-09 11:08:11
【问题描述】:

我正在尝试使用某种循环在 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 个表循环,将第 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-tag 而不是&lt;xsl:attribute name="xsi:type"&gt; 标签,因此该值将始终为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>

【问题讨论】:

    标签: xml xslt mapping biztalk biztalk-mapper


    【解决方案1】:

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

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

    看起来像这样:

    那些逻辑 functoid 的配置如下:

    如果您使用等于和不等于,则两者可以具有相同的配置 - 或者使用两个等于并在其中一个中将 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>
    

    【讨论】:

    • 不幸的是,这不是我想要的。您使目标模式太简单了(不过,图片的答案很好)。我已经用目标架构文件的示例更新了问题。
    • 您更新的架构与我对最初问题的理解有很大不同,但我认为一般方法应该仍然有效。我可以更新答案...
    • 已更新 - 有帮助吗?
    • 是的,这行得通。很棒的解决方案。甚至不知道你能做到这一点。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 2017-04-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多