group-adjacent
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.
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> |
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.
The mapping result is as follows:
<groups> |
This example, together with other grouping examples, is part of the following mapping file: <Documents>\Altova\MapForce2025\MapForceExamples\Tutorial\GroupingFunctions.mfd. Remember to click the Preview button applicable to the function you want to preview, before clicking the Output pane.