Capturing and formatting repeated data
One of XpressDox’s strong points is the smoothness with which it caters for repeating data. To illustrate this, we will imagine the example of a Will (i.e. “Last Will and Testament”) where the names of the children are repeated. A typical template would have this snippet:
My heir«When(count(Child) > 1,s are my children, is my child)»:
«ForEach(Child)»
«position()». «FirstName» «LastName» (age «Age» years) of «AddressLine1», «AddressLine2»
«End()»
A snippet like this in a template would have a number of effects:
- The
«Foreach(Child)»
would signal to XpressDox that the data element Child will be repeated. A Child “Collection” will be placed on the interview.
- Click on “Add Child” to add an instance of a the repeat. Each Child will have its own FirstName, LastName, Age, and two lines of address data elements.
- This is because those data elements appear between
«Foreach(Child)»
and«End()»
. Notwithstanding our example of “Child”, the Collection name of Child is known as the parent element, and the data elements inside the ForEach are known as the child elements!
- Complete some data for the first repeat, and then click “Confirm” to return to the main interview, or “Confirm and add next” to add another repeated item. Once done, your interview will look like this:
- Click “Add Child” to add more. Click on one of the existing repeats to edit them, or click on the delete button on the right to delete an item altogether.
A typical merged result for this snippet, where there are two children, would look like this:
«position()»
is a function you can use within the context of a ForEach. Each item inside the ForEach is indexed with a numerical value, beginning a 1 and the position() function will return that number.«count()»
can be used to count the number of items inside the ForEach. It also returns a numerical value, and in the above template snippet was used to ensure the plural of child would be correct in the assembled document.
How to print repeating data in a list format:
Using the «List()»
command you can easily print the repeating data in a list format. For example, should you want your document to read “Gary and Rebecca” you would use:
«List(Child,FirstName,!, , and )»
Should you want FirstName and LastName, then use:
«List(Child,FirstName LastName,!, , and )»
How to print a filtered list:
Should you want a list of children who are 16 years of age and older then you would use the square bracket notation to insert a filter on the List.
«List(Child[Age >= 16],FirstName LastName,!, , and )»
This is an example of XPATH; we have filtered on the Child node in the XML dataset to return only the data where the Age >= 16.