Altova MapForce 2025 Professional Edition

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.

mf_udf_19

Goals

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.

 

LookupPerson: Internal structure

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.

mf_udf_20

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.

 

EqualAnd implementation

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.

mf_udf_22

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.

 

Person2Detail implementation

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.

mf_udf_21

 

Output

When you click the Output pane, MapForce will display first and last names, and details of employees only from Nanonull, Inc (see extract below).

 

<PersonList>

 <Person>

         <First>Vernon</First>

         <Last>Callaby</Last>

         <Details>Office Manager, EMail:v.callaby@nanonull.com, Phone: 582</Details>

 </Person>

 <Person>

         <First>Frank</First>

         <Last>Further</Last>

         <Details>Accounts Receivable, EMail:f.further@nanonull.com, Phone: 471</Details>

 </Person>

 ...

</PersonList>

 

© 2018-2024 Altova GmbH