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.
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.
Built-in, C++, C#, Java, XSLT 2.0, XSLT 3.0.
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.
Specifies the size of each group
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).
The business requirement is to group person records into blocks of two items each. To achieve this, the following mapping invokes the group-into-blocks function, and supplies the integer value "2" as block-size.
The mapping result is as follows:
Note that the last group contains only one item, since the total number of items (5) cannot be divided evenly by 2.
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 button applicable to the function you want to preview, before clicking the Output pane.