Altova MapForce 2025 Professional Edition

Processes the sequence of values connected to the values input and returns only the distinct values, as a sequence. This is useful when you need to remove duplicate values from a sequence and copy only the unique items to the target component.

mf-func-distinct-values

 

Languages

Built-in, C++, C#, Java, XQuery, XSLT 2.0, XSLT 3.0.

 

Parameters

Name

Description

values

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.

 

Example

The following XML file contains information about employees of a demo company. Some employees have the same role; therefore, the "role" attribute role contains duplicate values. For example, both "Loby Matise" and "Susi Sanna" have the role "Support".

 

<?xml version="1.0" encoding="UTF-8"?>
<KeyValueList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="KeyValueList.xsd">
  <Item>
    <Property Key="role">Manager</Property>
    <Property Key="First">Vernon</Property>
    <Property Key="Last">Callaby</Property>
  </Item>
  <Item>
    <Property Key="role">Programmer</Property>
    <Property Key="First">Frank</Property>
    <Property Key="Last">Further</Property>
  </Item>
  <Item>
    <Property Key="role">Support</Property>
    <Property Key="First">Loby</Property>
    <Property Key="Last">Matise</Property>
  </Item>
  <Item>
    <Property Key="role">Support</Property>
    <Property Key="First">Susi</Property>
    <Property Key="Last">Sanna</Property>
  </Item>
</KeyValueList>

 

Let's suppose that you need to extract a list of all unique role names that occur in this XML file. This can be achieved with a mapping like the one below:

mf-func-distinct-values-example

In the mapping above, the following happens:

 

Each Property element from the source XML file is processed by a filter.

The connection to the filter's bool input ensures that only Property elements where the Key attribute is equal to "role" are supplied to the target component. The string "role" is provided by a constant. Note that the filter's output still produces duplicates at this stage (since there are two "Support" properties that meet the filter's condition).

The sequence produced by the filter is processed by the distinct-values function, which excludes any duplicate values.

 

As a result, the mapping output is as follows (excluding the XML and schema declarations):

 

<items>
  <item>Manager</item>
  <item>Programmer</item>
  <item>Support</item>
</items>

© 2018-2024 Altova GmbH