This topic explains how to look up data about employees and present this information in a suitable way. To test the look-up implementation, you will need the following mapping: MapForceExamples\PersonListByBranchOffice.mfd.
Our goals are as follows:
•To look up data about each employee (their phone extension, email address, and title) in a separate XML file.
•To present this data as a comma-separated list and map this list to the Details element of the target XML file.
•To extract information about employees only from one branch office called Nanonull, Inc.
To achieve these goals, we have designed our mapping in the following way:
•To filter only employees from Nanonull, Inc., the mapping uses the Office filter.
•To look up information about employees in a different XML file, the mapping calls the LookupPerson UDF. The implementation of this UDF is described in the subsection below.
•To process employee data, the LookupPerson function internally calls other functions that retrieve and concatenate information about each employee. All these operations are in the function's mapping and not visible in the main mapping. The LookupPerson function then maps the employee data to the Details element in PersonList.
The look-up functionality is provided by the LookupPerson function, whose definition is illustrated below. To see the internal implementation of the UDF, double-click its header in the main mapping.
The UDF is defined as follows:
•The data is retrieved from the XML file Altova_Hierarchical.xml: (i) the name of the office and first and last names of employees, which are used to select employees only from Nanonull, Inc., and (ii) the email, title, and phone extension that are concatenated into one string. The definitions of the EqualAnd and Person2Detail functions are described below.
•The UDF also has three input parameters that provide the look-up values Office_Name, First_Name, and Last_Name. The value of the Office_Name parameter is retrieved from the OfficeName input from the main mapping, and the values of First_Name and Last_Name are supplied by the BranchOffices component from the main mapping.
•The value of the EqaulAnd function (true or false) is passed to the Details filter each time a new employee's details (title, email, phone) are processed. When the Details filter gets the value true, the look-up operation is successful and the employee's details are retrieved and returned to the main mapping. Otherwise, the next item in the context is examined, and this procedure continues until the loop finishes.
The EqualAnd function (see below) is a separate UDF defined inside the LookupPerson UDF. To see the internal structure of the EqualAnd UDF, double-click the function's header.
The EqualAnd UDF first checks whether a equals b; if the result is true, it is passed as the first parameter of the logical-and function. If both values are true in the logical-and function, the result is also true and is passed on to the next EqualAnd function. The result of the third EqaulAnd function (see LookupPerson UDF above) is passed on to the Details filter.
The Person2Details UDF is another function inside the LookupPerson UDF. The Person2Details UDF (see below) concatenates three values (retrieved from Altova_Hierarchical.xml) and two text constants.
When you click the Output pane, MapForce will display first and last names, and details of employees only from Nanonull, Inc (see extract below).
<Details>Office Manager, EMail:firstname.lastname@example.org, Phone: 582</Details>
<Details>Accounts Receivable, EMail:email@example.com, Phone: 471</Details>