Altova MapForce 2024 Basic Edition

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.

 

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.

bool

Provides the Boolean condition that starts a new group when true.

 

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

 

<records>
  <record key="heading" value="Intro"/>
  <record key="line" value="A"/>
  <record key="line" value="B"/>
  <record key="heading" value="Body"/>
  <record key="line" value="C"/>
</records>

 

The business requirement is to create groups for each "heading" record. Each group must also include any "line" records that follow the "heading" record. To achieve this, the following mapping invokes the group-starting-with function. In the mapping below, whenever the key name is equal to "heading", the argument supplied to bool becomes true, and a new group is created.

mf_group-starting-with_map

The mapping result is as follows:

 

<groups>
  <group>
    <record key="heading" value="Intro"/>
    <record key="line" value="A"/>
    <record key="line" value="B"/>
  </group>
  <group>
    <record key="heading" value="Body"/>
    <record key="line" value="C"/>
  </group>
</groups>

 

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 mf_ic_preview button applicable to the function you want to preview, before clicking the Output pane.

© 2017-2023 Altova GmbH