Please enable JavaScript to view this site.

Altova MapForce 2020 Basic Edition

Repeats every item in the input sequence the number of times specified in the count argument. If you connect a single item to the node/row argument, the function returns N items, where N is the value of the count argument. If you connect a sequence of items to the node/row argument, the function repeats each individual item in the sequence count times, processing one item at a time. For example, if count is 2, then the sequence (1,2,3) produces (1,1,2,2,3,3).

function_replicate-item

Note that you can supply a different count value for each item. For example, let's assume that you have a source XML file with the following structure:

 

<?xml version="1.0" encoding="UTF-8"?>
<SourceList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="source.xsd">
  <person>
    <name>Michelle</name>
    <count>2</count>
  </person>
  <person>
    <name>Ted</name>
    <count>4</count>
  </person>
  <person>
    <name>Ann</name>
    <count>3</count>
  </person>
</SourceList>

 

With the help of the replicate-item function, you can repeat each person name a different number of times in a target component. To achieve this, connect the <count> node of each person to the count input of the replicate-item function:

example_replicate-item

The output is as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<TargetLists xsi:noNamespaceSchemaLocation="target.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <TargetList>
    <TargetString>Michelle</TargetString>
    <TargetString>Michelle</TargetString>
  </TargetList>
  <TargetList>
    <TargetString>Ted</TargetString>
    <TargetString>Ted</TargetString>
    <TargetString>Ted</TargetString>
    <TargetString>Ted</TargetString>
  </TargetList>
  <TargetList>
    <TargetString>Ann</TargetString>
    <TargetString>Ann</TargetString>
    <TargetString>Ann</TargetString>
  </TargetList>
</TargetLists>

© 2019 Altova GmbH