Skip to main content

I have attributes in this fashion (simplified to make sense)

Attribute: Value

Fruit: Apple

DesiredColor:Red

Color_Of_Fruit:Green

Return_Value: IloveLeaf

Color{1}_Of_Fruit: Yellow

Return{1}_Value:IloveBanana

Color{2}_Of_Fruit: Red

Return{2}_Value:ILoveStrawberries

...

..

Note that I don't know in advance the number of occurrence of
Color{x}_Of_Fruit and the corresponding Return{x}_Value. However,
x should be less than 10. Also, this is not a list. This is how I get data when
parsed by JXL.

What I want to do is I want to find the return{x}_Value
where the value of DesiredColor matches the value of the Color{x}_Of_Fruit.

So in this example, I would return like a match on
IloveStrawberries

Any ideas on how to accomplish this in an elegant fashion?

Interestingly enough the ListSearcher can handle a list in the form of x{}_y, but the ListIndexer doesn't.

 

Attached is a quick and dirty transform of the attributes into an fme list and then a list searcher and list indexer

 

jxl-list.fmw

I think @jdh's solution is probably easiest.

The other way I would investigate is to set up a custom transformer loop with a loopcount attribute. Then run a Tester to see if DesiredColor = Color{loopcount}_Of_Fruit

You'd need to experiment in the Tester to get the exact syntax on the right hand side. Probably:

@Value(Color{@Value(loopcount)}_Of_Fruit)

Hope this helps

Mark


I think @jdh's solution is probably easiest.

The other way I would investigate is to set up a custom transformer loop with a loopcount attribute. Then run a Tester to see if DesiredColor = Color{loopcount}_Of_Fruit

You'd need to experiment in the Tester to get the exact syntax on the right hand side. Probably:

@Value(Color{@Value(loopcount)}_Of_Fruit)

Hope this helps

Mark

You would still need to rename the first two attributes to match the rest, or test for them separately in the first iteration of the loop


In fact, thinking about it, an easier method (with two variations) would be:

- Use a TestFilter with 10 comparisons.

- Use an AttributeManager with 10 conditional values

Not elegant, but no looping and no worries about lists or @Value() syntax


Thank you JDH and Mark for your prompt replies! I am going to try with listindexer and see how it turns out.


Reply