group-by

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Functions > Function Library Reference > core | sequence functions >

group-by

The group-by function creates groups of records according to some grouping key that you specify. 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

 

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

key

A variable type

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. To achieve this, the following mapping invokes the group-by function, and supplies department as key.

mf_group-by_map

The mapping result is as follows:

 

<groups>
  <group>
    <record key="Administration" value="Vernon Callaby"/>
    <record key="Administration" value="Frank Further"/>
  </group>
  <group>
    <record key="Marketing" value="Susi Sanna"/>
  </group>
  <group>
    <record key="Engineering" value="Michelle Butler"/>
    <record key="Engineering" value="Fred Landis"/>
  </group>
</groups>

 

This example, together with other grouping examples, is part of the following mapping file: <Documents>\Altova\MapForce2019\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