@Vamitul – basically using the texts object retaining formatting is a good concept!
However:
1. I got an error from the ESTK, because the automatic conversion from number to string cannot take place.
l+1 remains a Number object (ESTK 3.8.0.12 testet with InDesign CS5.5)
So "contents=l+1" should be: "contents=(l+1).toString()" or: "contents=String(l+1)".
2. In the while loop at the end you are concatenating every found texts in one paragraph (unless the found text has a paragraph sign).
3. And the while loop concatenates the found results in the wrong order (exactly reverse from what is needed).
Instead I would do the following:
1. Iterate the found texts not in reverse!
2. Duplicating the found texts one after another to the end of the story adding consecutive numbers and things (paragraph signs at the end)
3. Changing the found texts in reverse order to superscript numbers
Uwe