Problem: Reference to \arabic{counter} inside \index{...}
From an XML dictionary, I have an XSLT script that generates XeTeX. There's a global counter named "entry"
\newcounter{entry}\setcounter{entry}{0}
that provides a unique number for each entry in the dictionary.
Then the XSLT script generates, for each dictionary entry
\addtocounter{entry}{1}
\arabic{entry}<xsl:text>. \index{</xsl:text><xsl:value-of select="headword"/><xsl:text>, </xsl:text>\arabic{entry} <xsl:text>}</xsl:text> ....
The idea is that each dictionary entry has a unique counter number, \arabic{entry}, and that number precedes the text for that entry.
(The text content of the entry is not important here--that's all working well.)
The Problem:
Each generated entry also has an \index{...} reference (see above) that includes a reference to \arabic{entry}.
1. The index relates the entry keyword to the page number on which the entry appears (that's what is desired, and it's working perfectly).
2. But the index headword, as it appears in the index, is supposed to be followed by a literal comma, a space, and the entry number \arabic{entry}.
That reference to \arabic{entry} is _not_ working correctly.
The problem seems to be that the content inside \index{...} is moved to a separate file, effectively included at the end of the .tex document, and the reference to \arabic{entry} inside \index{...} is evaluated _after_ all the references to \arabic{entry} that appear outside of \index{...} commands. So if there are 500 entries in the dictionary, the entry count is incremented
to 500, all the entries in the main text are numbered correctly, BUT all the references to \arabic{entry} that appear inside the index section resolve to 500.
Intuitively, I need to specify that any \arabic{entry} that appears inside \index{...} should be evaluated immediately, before the content of the \index{...} gets moved to the end.
How can I do that?
Thanks,
Ken