Comma separated list

Sometimes report needs to have a list that is rendered horizontally. In this case you will need to use a separator for the values in the lines. This turns out great by simply using a space character as space is not seen after the last value. Although it would be nice if the values would be separated by the comma (“,”) character.

To achieve a horizontally rendered list in a report with customized separators, follow these steps:

Add the @FieldName (replace with the actual field name from your data source) field to the report using a List tagging element . This allows you to treat each field as a separate element.

Normally we would just put the comma character after this Field tagging element which would add a comma after each iteration. This would however result in the comma being added even after the last element in the list like shown in this example:



To avoid adding a separator after the last element, you need to introduce a second Field tagging element immediately after the @FieldName Field tagging element .

In the second Field tagging element , use the following expression to display a comma character after each value in the rendered report, excluding the last one:

iif(count(@FieldName) = current-index(), ‘’, “,”)

This expression checks whether the count of nodes selected by the attribute @FieldName is equal to the current index. If true, an empty string is returned; otherwise, a comma is returned.

Here are some screenshots for a visual representation.



In summary, the provided expression handles the addition of commas, ensuring they are present between elements but not after the last element in the list. The logic involves checking the count of nodes against the current index within the context of the loop or iteration.

Expression downbreak:

  1. count(@FieldName): This part counts the number of nodes selected by the XPath expression @FieldName. It appears to be counting the nodes of the attribute named “FieldName.”
  2. = current-index(): This part checks if the count is equal to the current index. The current-index() function, returns the current index in the context of a loop or iteration.
  3. '': If the count is equal to the current index, an empty string is returned.
  4. ',': If the count is not equal to the current index, a comma is returned.