Question

merge list elements by index and concatenate

  • 21 January 2019
  • 4 replies
  • 59 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

Badge +3

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.

Userlevel 1
Badge +10

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]) 

 

Userlevel 2
Badge +17

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

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

Reply