XpressDox Help Center

Use Google To Find Help Fast, e.g. xpressdox choosefromlist


Press Getting Started in the XpressDox toolbar for basic template development
Watch the tutorial videos
View command help from list of commands
Press F1 for help on a command in the Command Editor
Email support@xpressdox.com for assistance

Document per Repeated Item


Document per Repeated Item

Problem Statement

Suppose you have an application which requires that one or more parties sign a suretyship document, with the requirement that each party signs their own document, not that they all sign the same document.

The first thing to do is set up the suretyship template, with the relevant fixed text, etc., just like any other template.  Suppose the template reads something like this:

I, «SuretyFirstNames» «SuretySurname» (Born on «FormatDate(SuretyDOB, “MMMM dd yyyy”)») hereby declare blah blah.
blah
Signed: «SuretyFirstNames» «SuretySurname»

Of course, this will only produce the information for one surety, and doesn’t indicate in any way that there can be more than one surety.

The normal way of indicating repeating data to XpressDox is the «ForEach» command, so it is tempting to try the following:

«ForEach(Surety)»I, «SuretyFirstNames» «SuretySurname» (Born on «FormatDate(SuretyDOB, "dd MMMM yyyy")») hereby declare blah blah.
blah
Signed: «SuretyFirstNames» «SuretySurname»
«End()»

But, of course, this will repeat the sureties’ information for all of the sureties one after the other on the same document.

One Document for each Repeater

In the above code snippet, the ForEach() defines the context of all the data elements before the End() – i.e. that they all belong to one repeater called Surety. The idea of the context is important, and can be applied to a whole template in the following way.

Firstly, the document which should be produced for each Surety must be authored in a template much like the first example, i.e. something like:

I, «SuretyFirstNames» «SuretySurname» (Born on «FormatDate(SuretyDOB, "MMMM dd yyyy")») hereby declare

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.

Signed: «SuretyFirstNames» «SuretySurname»

Let’s assume that a document like this is saved as an XpressDox template, and called DeclarationBySurety.xdtpx. Then, in your main document, you put the following:

«ForEach(Surety
«MergeTemplate('DeclarationBySurety.xdtpx','Surety',position())»
«End()»

In the above MergeTemplate, the ‘Surety‘ and position() provide the context for the entire DeclarationBySurety.xdtpx template. By definition of the MergeTemplate function, each of the MergeTemplates in the ForEach will cause a separate document to be created.

One Section for each Repeater in the Same Document

Also, you could use the same DeclarationBySurety template to create one long document with declarations for all of the sureties in the same document, by replacing MergeTemplate with IncludeTemplate in the above, getting this:

«ForEach(Surety
«IncludeTemplate(DeclarationBySurety)»
«Comment(Include XpressDox and Word commands here to insert page or section breaks after each Declaration. See Working with Section Breaks for information on this.)»
«End()»

Filtering

Suppose you want to produce a separate document for each of the Sureties, but only for the sureties born before a particular date (July 1 2001). Have a look at this:

«ForEach(Surety
«If(DateAsNumber(SuretyDOB) < 20010701)»
«MergeTemplate('DeclarationBySurety.xdtpx','Surety',position())»
«End()»
«End()»

Note that you might be tempted to write (using XpressDox’s powerful XPATH capabilities):
«ForEach(Surety[DateAsNumber(SuretyDOB) < 20010701]
«MergeTemplate('DeclarationBySurety.xdtpx','Surety',position())»
«End()»
The problem with this is that the position() function gives the position of the Surety relative to those conforming to the condition in the predicate (i.e. the bits between the [ and ]), whereas the MergeTemplate needs to the context to reflect the position() in the complete list of Surety repeaters.

The Interview

The way that MergeTemplate functions, is that no interview is prepared for the data elements used in the template being merged – in this case the DeclarationBySurety.xdtpx. This means that all the data elements must be assigned a value in the template which calls the MergeTemplate function. The values can be assigned by retrieving them from a data source (The ChooseFromDataSource Command, or The LinkToDataSource Command, or The IncludeDataSourceData Command), or letting the user capture them in the interview.