Altova MapForce 2023 Enterprise Edition

When your mapping must group nodes or rows, you can achieve this with the help of the following MapForce built-in functions:

 

group-by

group-adjacent

group-into-blocks

group-starting-with

group-ending-with

 

To use any of these functions on the mapping, drag them from the Libraries window onto the mapping area. See also Add a Function to the Mapping.

 

Note:Grouping functions are available in the following languages: XSLT 2.0, XSLT 3.0, C++, C#, Java, Built-In.

 

The following sections provide typical examples of use for grouping functions. These examples are accompanied by the following demo mapping: <Documents>\Altova\MapForce2023\MapForceExamples\Tutorial\GroupingFunctions.mfd. Note that the demo mapping contains multiple transformations, one for each function. Since only one output can be previewed at a time, remember to click the Preview mf_ic_preview button applicable to the desired transformation before clicking the Output pane.

 

group-by

The group-by function creates groups of records according to some grouping key that you specify.

mf-func-group-by

For example, in the abstract transformation illustrated below, the grouping key is "Department". Since there are three unique departments in total, applying the group-by function would create three groups:

mf_group-by

For more information, see the reference to the group-by function.

 

group-adjacent

The group-adjacent function requires a grouping key as argument, similar to group-by function. Unlike group-by, this function creates a new group whenever the next key is different. If two adjacent records have the same key, they will be 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

For more information, see the reference to the group-adjacent function.

 

group-into-blocks

The group-into-blocks function creates equal groups that contain exactly N items, where N is the value you supply to the block-size argument. Note that the last group may contain N items or less, depending on the number of items in the source.

mf-func-group-into-blocks

In the example below, block-size is 2. Since there are five items in total, each group contains exactly two items, except for the last one.

mf_group-into-blocks

For more information, see the reference to the group-into-blocks function.

 

group-starting-with

The group-starting-with function takes a Boolean condition as argument. If the Boolean condition is true, a new group is created, starting with the record that satisfies the condition.

mf-func-group-starting-with

In the example below, the condition is that "Key" must be equal to "heading". This condition is true for the first and fourth records, so two groups are created as a result:

mf_group-starting-with
Note:One additional group is created if records exist before the first one that satisfies the condition. For example, if there were more "line" records before the first "heading" record, these would all be placed into a new group.

 

For more information, see the reference to the group-starting-with function.

 

group-ending-with

The group-ending-with function takes a Boolean condition as argument. If the Boolean condition is true, a new group is created, ending with the record that satisfies the condition.

mf-func-group-ending-with

In the example below, the condition is that "Key" must be equal to "trailing". This condition is true for the third and fifth records, so two groups are created as a result:

mf_group-ending-with
Note:One additional group is created if records exist after the last one that satisfies the condition. For example, if there were more "line" records after the last "trailing" record, these would all be placed into a new group.

 

For more information, see the reference to the group-ending-with function.

© 2017-2023 Altova GmbH