Please enable JavaScript to view this site.

Altova MapForce 2020 Professional Edition

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.

mf_group-into-blocks

 

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).

block-size

xs:integer

Specifies the size of each group.

 

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 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.

mf_group-into-blocks_map

The mapping result is as follows:

 

<groups>
  <group>
    <record key="Administration" value="Vernon Callaby"/>
    <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>

 

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\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