Whenever it is required to flatten all values of a context/queue into a single string, this UDF makes life easy. It even allows for embedded newline characters as separator between context values....

Here is a UDF that does it all: It takes as first input parameter the queue of values to be concatenated and as second parameter the separator. If the separator matches the string "nl" an embedded newline is inserted. The UDF uses the system property for line separator to find the appropriate newline character:

public void cntxtConcat(String[] var1, String[] sep, ResultList result, Container container) throws StreamTransformationException{
int i,j=0;
String line="";

for (i=0; i<var1.length; i++) {
  if ( !(var1[i].equals(ResultList.CC)) && !(var1[i].equals(ResultList.SUPPRESS)) ) {

    if ( (j>0) && (sep.length() > 0) ) {
        if (sep == "nl")
            line = line + System.getProperty("line.separator") ;
        else
            line = line + sep;
    }
    j++;

    line = line + var1[i];

  } // if var1[i] != CC
} // for

result.addValue(line);
}