Well, here is code that will work with your example data. This may not be the best way to handle this, but the appendToSubList
function I made that is included here does the bulk of the work.
-- DESIRED OUTPUT:
--{{"ID1", "Red-1", "Black-1", "Green-1", "White-1"}, {"ID2", "Red-2", "Black-2", "Green-2", "White-2"}, {"ID3", "Red-3", "Black-3", "Green-3", "White-3"}}
set outputList to {}
set {attrArray, row1Array, row2Array} to DataFromSource1()
-- SAMPLE: {{"ID1", "ID2", "ID3"}, {"Red-1", "Red-2", "Red-3"}, {"Black-1", "Black-2", "Black-3"}}
set itemCount to length of attrArray
appendToSubList(outputList, attrArray)
appendToSubList(outputList, row1Array)
appendToSubList(outputList, row2Array)
set {attrArray, row1Array, row2Array} to DataFromSource2()
-- SAMPLE: {{"ID1", "ID2", "ID3"}, {"Green-1", "Green-2", "Green-3"}, {"White-1", "White-2", "White-3"}}
appendToSubList(outputList, row1Array)
appendToSubList(outputList, row2Array)
return outputList
on appendToSubList(nestedList, subList)
-- Where nestedList is a list of lists (or should be!), takes each item from subList and appends it to the matching-index sub-list in nestedList.
-- If the sublist does not yet exist in nestedList, create it.
repeat with i from 1 to length of subList
set oneItem to item i of subList
if length of nestedList is less than i then copy {} to end of nestedList
copy oneItem to end of item i of nestedList
end repeat
return nestedList
end appendToSubList
on DataFromSource1()
set attrKey to "ID"
set row1 to "Red-"
set row2 to "Black-"
set attrArray to {}
set row1Array to {}
set row2Array to {}
repeat with i from 1 to 3
set attrKeyNew to attrKey & i
set end of attrArray to attrKeyNew
set valuerow1 to row1 & i
set end of row1Array to valuerow1
set valuerow2 to row2 & i
set end of row2Array to valuerow2
end repeat
return {attrArray, row1Array, row2Array}
end DataFromSource1
on DataFromSource2()
set attrKey to "ID"
set row3 to "Green-"
set row4 to "White-"
set attrArray to {}
set row3Array to {}
set row4Array to {}
repeat with i from 1 to 3
set attrKeyNew to attrKey & i
set end of attrArray to attrKeyNew
set valuerow3 to row3 & i
set end of row3Array to valuerow3
set valuerow4 to row4 & i
set end of row4Array to valuerow4
end repeat
return {attrArray, row3Array, row4Array}
end DataFromSource2