Compute the complement of a list in Tibco BusinessWorks
Facts - Tibco
Tuesday, 11 December 2012 20:10

This note has been tested with Tibco BusinessWorks 5.6.

Tibco BusinessWorks (BW) has a built-in mapper in any step of a BW process. Within this mapper xml data can be transformed. The BW mapper offers XPath 1.0 functions, some custom functions and XSLT constructs for these tranformations.

Suppose we have two lists in the Start task of a BW process, which serves as our input. The lists are called A and B. Each list consists of a sequence of string elements. Each element has the same name, which is content. List B is overlapping with list A but not the other way around. So all values in list B also occur in list A but list A can contain elements with values that are not in list B. My problem was to get the elements in list A that have values that don't occur in list B. So I had to compute the complement of list B in list A.

Unfortunately the BW mapper does not have a function that provides all values in a list that don't occur in a second input list. But this problem can be easiliy solved using two Mapper tasks.

The first mapper, Mapper1, simply concatenates the two lists into list C. The second mapper, Mapper2, produces a fourth list D, which will contain the requested complement list. The structure of this list D is the same as the structure of list A, B and C.

This list D is filled using a for-each XSLT statement on the elements of list A. Within the for-each statement the element content of list C is created depending on an XSLT if-clause. Below is the condition for the if-clause in pseudo XPath code:


So an element is only created in the resulting list D if the concatenated list C doesn't contain any duplicate elements with the same value. The content of the new element was set to the current element of list A in the for-each iteration.