Use Google to find help fast. For example, search on "xpressdox choosefromlist".

Conditional Numbering of Paragraphs

Conditional Numbering of Paragraphs

Suppose you have a document where names and other identifying information are listed.  They could be parties to a contract or names and addresses of directors of a company, or something like that.

Suppose further that if there are a number of parties to be listed, the paragraphs in which they appear should be numbered, but if only one, then it should appear without numbering.

Something like this:

The directors are

  1. Frederick Basset
    Email address: fbasset@email.com
    Telephone: +999 456 123
  2. Charles Harry Brown
    Email address: chbrown@email.com
    Telephone: +999 123 456

But where there is only one director, this should read:

The director is

Frederick Basset
Email address: fbasset@email.com
Telephone: +999 456 123

The way to achieve the introductory wording is quite straight forward:

The director«When(count(Director) = 1, is,s are)»

Then, listing the directors also looks quite straight forward:

«ForEach(Director)»

«Firstnames» «Lastname»
Email address: «EmailAddress»
Telephone: «Phone»

«End()»

So far, this would work well in the case of one director.

The trick to numbering the directors when there is more than one is to use numbered styles.  But you can’t use a numbered style directly in the template, otherwise the single director on its own will be numbered.  Here’s the trick:

  1. Create a style called “DirectorStyle” and assign that style to the paragraph with the «Firstnames» «Lastname» fillpoints. Make sure this style is not numbered. Also make sure that the end of that line and the Email line are made using <Shift Enter> to get a line break instead of a paragraph end, otherwise those two lines will also be numbered when the time comes.
  2. Make another template, call it “Numberer”.  Make a style in that template called “DirectorStyle” – i.e. exactly the same name as the style made in the original template.  But this DirectorStyle style must be assigned a numbering scheme – however you want the numbered paragraphs to look in the final document.  Don’t put any text in the Numberer template – just leave it empty.
  3. In the original template, put the following (it can go anywhere in the template):

«If(count(Director) > 1)»
«InsertTemplate('Numberer',Source)»«RemoveParagraph()»
«End()»

What will happen is that when the number of directors is more than one (i.e. the condition “count(Director) > 1” is satisfied), the Numberer template will be inserted into the document being assembled.  Then because XpressDox will see two styles called “DirectorStyle”, one in the original template and one in the Numberer, it will need to decide which one to use.  The Source parameter in the InsertTemplate tells XpressDox to use the DirectorStyle from the Numberer template.  How this works is that the definition of DirectorStyle in the merged document is changed to be the definition from Numberer (i.e. the numbered style), and all paragraphs formatted with the DirectorStyle style will then automatically become numbered when the document is opened it Word.

Note the RemoveParagraph() command in the same line as the InsertTemplate  – this is needed because even though the Numbered template has no text in it, Word always inserts an empty paragraph at the end of the document, and this gets inserted into the merged document at the point of the InsertTemplate command, so it needs to be removed (unless of course you want it there for some other reason).