1

I am trying to do a BizTalk map with some kind of looping over LoopingNode, where if Cond1 is false, create Type1. If Cond1 is true then create Type2. It looks like this:

Input:

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

Output:

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

And the output should look something like this

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

I have tried with 2 table loopings with column 1 as gate, but that didn't work. And my recent attempt was to do a value mapping with cond as a condition. The generated xslt became this:

<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>

And since the xsl:if only surrounds the id-tag and not the <xsl:attribute name="xsi:type"> tag, the value will always be Type2 since that is last in the xslt.

I rather have a non-custom xslt solution but maybe that isn't possible. The real issue is much more complex than this (around 20 more attributes, 3 equivalent types and 2 conditions). But the solution should probably be the same.

Any ideas how to do a conditional looping over equivalent nodes?

UPDATE: Here is an schema (xsd) that corresponds to my problem:

<?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>
Nings
  • 355
  • 1
  • 2
  • 12

1 Answers1

3

You're looking for conditional looping. The map should have:

  • Direct links between the id nodes
  • A looping functoid going from the LoopingNode the TargetNode
  • Logical functoids to do conditional looping based on Cond1 and outputting to Type1 and Type2

That'd look something like this:

enter image description here

Where those logical functoids have configuration like this:

Functoid config

Both can have the same config if you use equals and not equals - or use two equals and set Condition2 to false in one of them.

You can read more about conditional looping at MSDN.

Based on this XML input:

<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>

I get this output:

<?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>
Dan Field
  • 20,885
  • 5
  • 55
  • 71
  • Unfortunately this is not what I am looking for. You made the Target schema too simple (great answer with pictures though). I have updated the question with an example of the target schema file. – Nings Jan 25 '17 at 15:30
  • Your updated schema is significantly different from how I understood the initial question, but I think the general approach should still work. I can update the answer... – Dan Field Jan 25 '17 at 15:39
  • Updated - does that help? – Dan Field Jan 25 '17 at 15:42
  • Yup, that worked. Fantastic solution. Didn't even know you could do this. Thanks! – Nings Jan 26 '17 at 07:34