IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

mapping using if-then does not work as expected Options · View
Presente
Posted: Monday, October 20, 2014 4:09:31 PM
Rank: Newbie

Joined: 5/22/2012
Posts: 5
I want to map a simple xml with 2 levels, a & b, each one containing 1 attribute , to a simple text file with a single field.
When I map: 'a' --> 'rows', 'val1' -->'Field1' , result is 2 lines with a1 & a2 , as expected.
When I map: 'b' --> 'rows', 'val2' -->'Field1' , result is 5 lines with the b values, as expected.

The problem is that I want the mapping to map EITHER 'a' values OR 'b' values, depending on a condition.
I tried to use 2 'if-else' , one connected to 'rows' , and one to 'Field1'. See attached mapping. This does NOT work as expected, and result in 2 empty lines, regardless if condition is true or false. Why is that ? How can I fix my mapping?

Thanks a lot in advance!

We use MapForce 2012.

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2012 rel. 2 sp1 (https://www.altova.com)-->
<MyRoot xsi:noNamespaceSchemaLocation="ab.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a val1="a1">
<b val2="b1"/>
<b val2="b2"/>
<b val2="b3"/>
</a>
<a val1="a2">
<b val2="b4"/>
<b val2="b5"/>
</a>
</MyRoot>

File Attachment(s):
ab.xsd (1kb) downloaded 198 time(s).
ab.xml (1kb) downloaded 208 time(s).
a or b.mfd (6kb) downloaded 355 time(s).


vlad
Posted: Monday, October 20, 2014 5:01:43 PM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
Your attached mapping doesn't make much sense. It uses "equal" function with two constants "2" which are always the same, which means it is always true. Because of this it is also completely unclear what you are actually trying to do.
Presente
Posted: Monday, October 20, 2014 8:24:40 PM
Rank: Newbie

Joined: 5/22/2012
Posts: 5
Vlad, thanks for the quick response.
Think of the 'equal' with (2,2) as an input variable with value 'true'. If changed to equal (1,2) the variable value is 'false'. Perhaps it was clearer if written as input variable.
I'll try to explain again what the mapping needs to to.
When the boolean is 'true', the result should be all values of the 'a' elements. (2 lines: a1,a2 in my example.
When he boolean value is changed to 'false' the result should be all values of the 'b' elements (5 lines: b1,b2,b3,b4,b5).

Hope it is clear now.

Ofer
that
Posted: Tuesday, October 21, 2014 8:45:24 AM
Rank: Advanced Member

Joined: 6/16/2006
Posts: 487
Location: AT
Presente wrote:
When the boolean is 'true', the result should be all values of the 'a' elements. (2 lines: a1,a2 in my example.
When he boolean value is changed to 'false' the result should be all values of the 'b' elements (5 lines: b1,b2,b3,b4,b5).


This won't work with "if" because you want multiple values and from different source contexts which are dependent on each other. Instead, use two filter components, duplicate the "Rows" target and connect one filter to each (one from "a", one from "b").
Presente
Posted: Tuesday, October 21, 2014 12:54:13 PM
Rank: Newbie

Joined: 5/22/2012
Posts: 5
Thanks a lot! We tried your suggestion and it works.

However, I don't understand why the simple 'if-else' doesn't work.

You wrote:
"This won't work with "if" because you want multiple values and from different source contexts which are dependent on each other".

I conclude that there are limitations to using 'if-else' structure, but I couldn't find more information about it in the documentation.

If you have a link that explains it , I would appreciate it.

and thanks again!

Ofer
vlad
Posted: Tuesday, October 21, 2014 1:21:24 PM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
"if-else" works on single value basis.
"filter" is able to process whole sequences.

So if you want to choose between two values based on condition, "if-else" is just fine. But in your case you want to either pass one sequence of values or another to output, where "filter" is a must. You could use "filter" for all tasks, though "if-else" is a little more lightweight for single values.
Presente
Posted: Tuesday, October 21, 2014 4:25:00 PM
Rank: Newbie

Joined: 5/22/2012
Posts: 5
Thanks for the clarification.

Ofer
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.