Now an alternative approach I thought, because the index I'm working on is a biographical index, I mean a index of cited people, with a biographical profile. So every entry is a few lines long. That's why I thought to index only the ids in the text and use a textcommand in the index to pass from the id to the real entry.
Suppose to use \setupregister[Animal][textcommand=\fromIdToEntry] and an indexEntry function modified like this:
function xml.functions.indexEntry(e) local animal = animals[e.at.idref] if animal then context.Animal( { animal.key }, e.at.idref ) end end
Without a textcommand, you would have an index of the ids. The textcommand \fromIdToEntry should take the id of an index entry and typeset the entry content.
\def\fromIdToEntry#1{ ... }
#1 is the id, but it's not a string. Is there a way to use it as a string to look for the entry? Is this approach better?
comparable
btw, you can better use deeptextcommand as textcommand gets something more passed
I think I've understood (thanks Hans): \startbuffer[test] <text> <div> <p>In this page there is a <name idref="id1">cat</name>, a <name idref="id2">dog</name> and a <name idref="id3">horse</name>.</p> </div> <div> <p>In this page there's only a <name idref="id2">fox terrier</name>.</p> </div> <div> <p>In this page you find a <name idref="id1">persian cat</name> and a <name idref="id3">horse</name>.</p> </div> <index> <entry id="id1" data-sort="cat">Cat</entry> <entry id="id2" data-sort="dog"><bf>Dog</bf></entry> <entry id="id3" data-sort="horse">Horse</entry> </index> </text> \stopbuffer \defineregister[Animal][Animals] \setupregister[Animal][deeptextcommand=\idToEntry] \def\idToEntry#1{\ctxlua{id2entry([==[#1]==])}} \startxmlsetups xml:mysetup \xmlsetsetup{#1}{*}{xml:*} \stopxmlsetups \xmlregistersetup{xml:mysetup} \startxmlsetups xml:text \xmlfunction{#1}{collectIndex} \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:bf \dontleavehmode {\xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:div \xmlflush{#1} \page \stopxmlsetups \startxmlsetups xml:p \ignorespaces \xmlflush{#1} \removeunwantedspaces \par \stopxmlsetups \startxmlsetups xml:name \dontleavehmode \xmlfunction{#1}{indexEntry} {\bf\xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:i \dontleavehmode {\em\xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:index \placeregister[Animal] \stopxmlsetups \startxmlsetups xml:entry \xmlflush{#1} \stopxmlsetups \startluacode local animals = { } function xml.functions.collectIndex(e) for entry in xml.collected(e,"/index/entry") do local key = entry.at["data-sort"] local id = entry.at["id"] if key and id then animals[id] = { key = key, entry = entry, } end end end function xml.functions.indexEntry(e) local animal = animals[e.at.idref] if animal then context.Animal( { animal.key }, e.at.idref ) end end function id2entry(id) if animals[id] then lxml.flush(animals[id].entry) end end \stopluacode \starttext \xmlprocessbuffer{main}{test}{} \stoptext