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>