Concatenate child nodes into a field

We have an xml file with the following example structure.

<xml>
<address>
<line>HS Group</line>
<line>123 Evergreen Tce</line>
<line>Springfield ABC 1234</line>
</address>
<address>
<line>NF Inc.</line>
<line>125 Evergreen Tce.</line>
<line>Springfield ABC 1234</line>
<line>United States</line>
</address>
</xml>

How would you concatenate the line child nodes of the address node when the number of children is unknown?

Hi Nick,

Not sure why you want the entire address in one field but this is what I came up with. The first script in the template loops through the detail table and joins their values into a field separated by a comma. The detail table is their just for reference. Hope it helps.

Download

Regards,

S

Add an Extract step based on JavaScript and use the below script to loop through the line child nodes and concatenate them. I have used the <br> separator in this case:

var i = 1, addressBlock ="";

//Pick one of the below loop types:

/* with do while loop
do{
   addressBlock += data.extract('./address[1]/line[' + i + ']') + '<br>';
   i++;
}while(data.extract('./address[1]/line[' + i + ']'));
*/

/* with for loop
for(;data.extract('./address[1]/line[' + i + ']');){
    addressBlock += data.extract('./address[1]/line[' + i + ']') + '<br>';
    i++;    
}
*/

// with while loop
while(data.extract('./address[1]/line[' + i + ']')){
     addressBlock += data.extract('./address[1]/line[' + i + ']') + '<br>';
     i++;
}

addressBlock.replace(/^\s*<br\s*\/?>|<br\s*\/?>\s*$/g,'');