ForEach: Handling repeating data

The term repeating data would apply, for example, to a list of parties to an agreement, or to a number of lines on an invoice. The central issue with repeating data is that the number of repeated items (data elements) is not known at the time the template is authored, and so XpressDox offers these commands as a way of processing a variable number of repeated data elements.

 

Basic example:

An example, listing the surname and first names of a number of parties is:

The parties are:
«ForEach(Party)»
Surname: «Surname»
First names: «FirstNames»
«End()»

 

The output of this snippet would look like:

The parties are:
Surname: Potter
First names: Harry
Surname: Jones
First name: Juliet
Surname: Basset
First names: Fred

 

Should you want there to be a line between each party simply place a carriage return before your end.

 

How to sort:

This is actually a subcommand of the ForEach command. For example, to sort the above list by surname, the ForEach would look like:

The parties are:
«ForEach(Party,Surname,ascending,text)»
Surname: «Surname»
First names: «FirstNames»
«End()»

In this example the parties would be listed in ascending order of surname. The ‘ascending’ and ‘text’ are the order and data type respectively, and these values could in fact have been omitted in this example, as they are the defaults. The other option for order is ‘descending’, and the other option for data type is ‘number’.

The output of the snippet would now look like:

The parties are:
Surname: Basset
First names: Fred
Surname: Jones
First name: Juliet
Surname: Potter
First names: Harry

 

Related articles:

The commands used to handle repeating data are the ForEach, position, List and Ordinal commands.

Learn more about working with repeating data here.