Skip to main content
Question

merge list elements by index and concatenate

  • January 21, 2019
  • 4 replies
  • 337 views

This might rather be a simple task, but so far i have no clue how it works to merge and concatenate joined_list elements.

I want to concatenate the two element values into one string and at the end write all the list elements out into one attribute.

Result should be {KA:28,KA:12,KA:4}

4 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • January 21, 2019

if you like to stick to transformers (rather then diving into some snaky script)

you could just explode the list and string-concatenate depthto and strat. As every index in the list is a record.

Then rebuild the list (list builder, no group by) with these concatenated items and use listconcatenator to create one attribute.

Finally, stringconcatenator to get the curly braces on.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • January 21, 2019

But if you did want to dive into some snaky script, something like this in a python caller would work

import fme
import fmeobjects

def concat_list(feature):
    depthto = feature.getAttribute('_join_list{}.depthto')
    strat = feature.getAttribute('_join_list{}.strat')
    for i, val in enumerate(depthto):
         feature.setAttribute('newlist{'+str(i)+'}.newattribute',depthto[i]+strat[i]) 

 


takashi
Influencer
  • January 22, 2019

Alternatively, XQuery can also be used, although it's not XML operation.

XQuery expression:

let $start := fme:get-list-attribute('_join_list{}.start')
let $depthto := fme:get-list-attribute('_join_list{}.depthto')
for $i in (1 to count($start))
return $start[$i]||':'||$depthto[$i]

0684Q00000ArLREQA3.png


  • Author
  • January 22, 2019

thanks for the two variants, both of which work great - have to try out also the xquery...


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