Note. I am using InfoPath 2007, so I'm not sure if 100% of this applies to InfoPath 2010
I was looking for something similar, but I just wanted my repeating sections to display a number.
The answer from @firestream almost worked for me, except for some reasons, the first section was not installed. They were numbered as "empty, 2, 3, 4, ..." In addition, I do not need the number to be constant in the data source and not need an additional field.
I just created an Expression Box control and set XPath to count(preceding-sibling::*)+1
source share