cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use loop in graphical message mapping

Former Member
0 Kudos

The source input XML is like:

<bookstore>

<book>

<item1>xxx</item1>

<item2>yyy</item2>

</book>

<book>

<item1>zzz</item1>

<item2>www</item2>

</book>

........

</bookstore>

I want to create an output XML like

<output>

<item>

<item1>xxx</item1>

<item2>yyy</item2>

</item>

<item>

<item1>xxx</item1>

<item2>www</item2>

</item>

<item>

<item1>zzz</item1>

<item2>www</item2>

</item>

<item>

<item1>xxx</item1>

<item2>yyy</item2>

</item>

.....

</output>

That means I want to do permutation and combination for all <item1> <item2> under <book>.

Of course I can write a customer function to do it, but I want to basically use the buildin functions to do the graphical message mapping for this.

Any idea? thank you.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Which do you want to do Permutation or Combination?

Former Member
0 Kudos

well, I'm not very clear of those 2 English words

What I want is to list all possible combination of item1 and item2 (and in fact, we have item3, item4, ....etc).

example

input:

<item>

<item1> 111 </item1>

<item2> 222 </item2>

<item3> 333 </item3>

</item>

<item>

<item1> aaa </item1>

<item2> bbb </item2>

<item3> ccc </item3>

</item>

I want to get

<item><Item1>111>/item1> <item2>222</item2> <item3>333</item3> </item>

<item><Item1>111>/item1> <item2>222</item2> <item3>ccc</item3> </item>

<item><Item1>111>/item1> <item2>bbb</item2> <item3>333</item3> </item>

<item><Item1>111>/item1> <item2>bbb</item2> <item3>ccc</item3> </item>

<item><Item1>aaa>/item1> <item2>222</item2> <item3>333</item3> </item>

<item><Item1>aaa>/item1> <item2>222</item2> <item3>ccc</item3> </item>

<item><Item1>aaa>/item1> <item2>bbb</item2> <item3>333</item3> </item>

<item><Item1>aaa>/item1> <item2>bbb</item2> <item3>ccc</item3> </item>

Former Member
0 Kudos

Hi.

I think that your requeriment it's no posible with standard functions., because the permutation that you need is not common in your requeriment. Why don't you write a UDF function.?

Regards.

Former Member
0 Kudos

Can you explain it more clearly you requeriment ?

Because on your 3st target the Item1 is ZZZ and the and the 4th is XXX I guess maybe has a specific rule.

In other case if value is "XXX" you need to write an UDF function to replicate the value ,however your target Item is generated in based your mapping or is a static structure.

Former Member
0 Kudos

oh, sorry, I did a typo.

the 4th <item1> should be "zzz".

What I expect is:

<output>

<item>

<item1>xxx</item1>

<item2>yyy</item2>

</item>

<item>

<item1>xxx</item1>

<item2>www</item2>

</item>

<item>

<item1>zzz</item1>

<item2>www</item2>

</item>

<item>

<item1>zzz</item1>

<item2>yyy</item2>

</item>

.....

</output>

I tried useOneAsmany, but it did not work out my request.

Former Member
0 Kudos

Hi

You can try to use this code


   //write your code here
int rep = Integer.parseInt(repeat[0]);
 for(int i = 0 ; i < list.length;i++){
       for (int j = 0 ; j < rep;j++)   {
          result.addValue(list<i>);
       }       
}

the parameters repeat is the value how many time you need to repeat the value. for this case (2)

for you root node use this Source>> UDF >>RemoveContext>>Target

for you field use this Source>> UDF >>SplitByValue>>Target

Former Member
0 Kudos

thanks. but as I mentioned in my first post, I want use only build-in function, no UDF.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi WuDao,

This is not possible without using UDF because you would need to combine the contexts i.e item a has two, item b has two..so the output should have four contexts (item a1, item a1, item a2, item a2) for item1

hope this helps,

prasannakrishna_mynam
Contributor
0 Kudos

Hi,

try to use UseOneAsMany or FormatByExample standard node functions, to achive this with out using UDF. All the best

Regards,

Prasanna