Skip to main content
Solved

Dynamic attributes and find values


Forum|alt.badge.img

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?

Best answer by jdh

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
View original
Did this help you find an answer to your question?

5 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • Best Answer
  • March 17, 2016

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

mark2atsafe
Safer
Forum|alt.badge.img+47
  • Safer
  • March 18, 2016

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


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • March 18, 2016
mark2atsafe wrote:

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


mark2atsafe
Safer
Forum|alt.badge.img+47
  • Safer
  • March 18, 2016

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


Forum|alt.badge.img
  • Author
  • March 18, 2016

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings