Please enable JavaScript to view this site.

Altova MapForce 2020 Professional Edition

The group-adjacent function groups the items connected to the nodes/rows input by the key connected to the key input. Note that this function places items that share the same key into separate groups if they are not adjacent. If multiple consecutive (adjacent) items share the same key, they are placed into the same group.

 

For example, in the abstract transformation illustrated below, the grouping key is "Department". The left side of the diagram shows the input data while the right side shows the output data after grouping. The following takes place when the transformation runs:

 

Initially, the first key, "Administration", creates a new group.

The next key is different, so a second group is created, "Marketing".

The third key is also different, so another group is created, "Engineering".

The fourth key is the same as the third; therefore, this record is placed in the already existing group.

Finally, the fifth key is different from the fourth, and this creates the last group.

 

As illustrated below, "Michelle Butler" and "Fred Landis" were grouped together because they have the same key and are adjacent. However, "Vernon Callaby" and "Frank Further" are in separate groups because they are not adjacent, even though they have the same key.

mf_group-adjacent

 

Arguments

Name

Type

Description

nodes/rows

A sequence of items

A sequence of nodes or rows (for example, the connection may originate from a source XML node with child items, a CSV record, and so on).

key

A variable type

The key by which to group items.

 

Example

Let's assume that your source data is an XML file with the following content (note that, in the code listing below, the namespace and XML declarations were removed for simplicity).

 

<company>
  <person department="Administration" name="Vernon Callaby"/>
  <person department="Marketing" name="Susi Sanna"/>
  <person department="Engineering" name="Michelle Butler"/>
  <person department="Engineering" name="Fred Landis"/>
  <person department="Administration" name="Frank Further"/>  
</company>

 

The business requirement is to group person records by department, provided they are adjacent. To achieve this, the following mapping invokes the group-adjacent function, and supplies department as key.

mf_group-adjacent_map

The mapping result is as follows:

 

<groups>
  <group>
    <record key="Administration" value="Vernon Callaby"/>
  </group>
  <group>
    <record key="Marketing" value="Susi Sanna"/>
  </group>
  <group>
    <record key="Engineering" value="Michelle Butler"/>
    <record key="Engineering" value="Fred Landis"/>
  </group>
  <group>
    <record key="Administration" value="Frank Further"/>
  </group>
</groups>

 

This example, together with other grouping examples, is part of the following mapping file: <Documents>\Altova\MapForce2020\MapForceExamples\Tutorial\GroupingFunctions.mfd. Remember to click the Preview mf_ic_preview button applicable to the function you want to preview, before clicking the Output tab.

© 2019 Altova GmbH