I'm trying to turn a list of attendees in a repeating table into a thank you sentence.
For examples, the values in the repeating table look like:
Jim
Tim
Lisa
Fred
I need the sentence to say:
"Special Thanks to Jim, Tim, Lisa, and Fred."
Consider the following repeating table structure:
groupAttendees
groupAttendee
fieldAttendeeName
I could create the sentence "Special thanks to Jim, Tim, Lisa, Fred, " all day using nested evals:
concat("Special thanks to ", eval(eval(groupAttendee, 'concat(my:fieldAttendeeName, ", ")'), ".."))
However this does not give me the desired result with the "and" before the last table entry. I searched around and could not find a way to enter the "and" in the sentence just before the last table entry.
So here's my thought process:
1) Assign a Line Item number to each table entry.
2) Count the number of rows in the table.
3) If the line number is less than the row count, concat a string
4) If the line number is equal to the row count, concat the and string
5) concat the two strings together
Implementation:
1) Assign a Line Item number to each table entry.
Modified repeating table structure by adding fieldAttendeeLineItem:
groupAttendees
groupAttendee
fieldAttendeeName
fieldAttendeeLineItem
assigned fieldAttendeeLineItem default value of:
count(../preceding-sibling::*) + 1
2) Count the number of rows in the table.
created a field outside the repeating table named fieldRowCount with a Default value of:
count(groupAttendee)
3) If the line number is less than the row count, concat a string
eval(eval(groupAttendee[msxsl:string-compare(fieldAttendeeLineItem, fieldRowCount) < 0], 'concat(my:fieldAttendeeName, ", ")'), "..")
The results of such a string would be:
Jim, Tim, Lisa,
4) If the line number is equal to the row count, concat the "and" string
eval(eval(groupAttendee, 'concat("and ", my:fieldAttendeeName[../my:fieldAttendeeLineItem = ../../../my:fieldRowCount], ". ")'), "..")
The results of such a string would be:
and Fred.
5) concat the two strings together
created a field outside the repeating table called fieldAttendeeThankYou with the Default Value:
concat("Special thanks to ", eval(eval(groupAttendee[msxsl:string-compare(fieldAttendeeLineItem, fieldRowCount) < 0], 'concat(my:fieldAttendeeName[../my:fieldAttendeeLineItem < ../../../my:fieldRowCount], ", ")'), ".."), "and ", fieldAttendeeName[fieldAttendeeLineItem = fieldRowCount], ". ")
Got what I wanted:
Special thanks to Jim, Tim, Lisa, and Fred.
I'll have to add some logic for blank fields, if there is only one name, etc, but you get the idea.
If anyone has a simpler way, please let me know!
~Dustin.