Altova MapForce 2024 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.

mf-func-group-adjacent

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

 

Languages

Built-in, C++, C#, Java, XSLT 2.0, XSLT 3.0.

 

Parameters

Name

Description

nodes/rows

This input must receive a connection from a mapping item that provides a sequence of zero or more values. For example, the connection may originate from a source XML item, a CSV field, a database record, and so on.

key

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\MapForce2024\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 pane.

© 2017-2023 Altova GmbH