Hi Taco,
that is a great start and gets me going, thanks so much! I have slightly
adapted your code. For the ../../footnote path, I think I can use
ancestor::footnote, that should be more robust; the footnote/**/../ref
is OK, I think. Out of curiosity: how would you have coded it in Lua?
I'm always open to processing xml in Lua because testing such conditions
(are we inside a footnote?) is so much easier. Maybe I write an attempt
of that too and have you have a go at it... Below is the code that
appears to work for me.
Thanks and all best
Thomas
\startbuffer[test]
<document>
<p>Here is <ref id="A">Thing A</ref>. It has a reference.<footnote
id="ftn1">This is just a dummy footnote.</footnote> It is
not<footnote>Another dummy note.</footnote> inside a footnote.<footnote
id="ftn2">However, <ref id="B">Thing B</ref> is.</footnote> And so on.</p>
<references>
<referred id="A">Thing A</referred>
<referred id="B">Thing B</referred>
</references>
</document>
\stopbuffer
\startxmlsetups xml:testsetups
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{document|p|ref|references|referred|footnote}{xml:*}
\xmlsetsetup{#1}{footnote/**/../ref}{xml:footnoteref}
\stopxmlsetups
\xmlregistersetup{xml:testsetups}
\startxmlsetups xml:document
\xmlflush {#1}
\stopxmlsetups
\startxmlsetups xml:p
\xmlflush {#1}\par
\stopxmlsetups
\startxmlsetups xml:ref
\reference [\xmlatt {#1} {id}]{}\xmlflush {#1}
\stopxmlsetups
\startxmlsetups xml:footnoteref
\reference [\xmlatt {#1} {id}]{\high{\in [\xmlattribute {#1}
{ancestor::footnote} {id}]}\unskip}\xmlflush {#1}
\stopxmlsetups
\startxmlsetups xml:footnote
\footnote [\xmlatt {#1} {id}] {\xmlflush {#1}}
\stopxmlsetups
\startxmlsetups xml:references
\page
REFERENCES: \par
\xmlflush {#1}
\stopxmlsetups
\startxmlsetups xml:referred
\xmlflush {#1}: \hfill p. \at [\xmlatt {#1} {id}]\in [\xmlatt {#1}
{id}] \par
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{test}{}
\stoptext
On 10/6/25 16:05, Taco Hoekwater wrote:
Hi Thomas,
My xml processing is normally completely done in lua and that knowledge does
not map one-on-one to the TeX frontend, but the code below is close to what you
want, I think. The main trick is to use the context (no pun intended) to create
two different full \reference commands, with the extra text required as their
\in contents.
I am a unsure about the lpath definitions, these may need fixing or improving.
The “footnote/**/../ref” is my weird way of allowing both
<footnote>..<ref/>
and the deeper embedded
<footnote>..<b>..<ref/>..</b>
as input. There should be a more elegant way to that, but I don’t know how
using TeX syntax. Still, it works.
More problematic is the “../../footnote” lpath. This will only work for the first
case, not for the embedded one. I have no idea whether there is an lpath for ‘nearest
enclosing parent named <footnote>'
Anyway, here is my code.
Best wishes, Taco
--
Prof. Dr. Thomas A. Schmitz
Institut für Klassische und Romanische Philologie
Universität Bonn
Rabinstr. 8
53111 Bonn
http://www.philologie.uni-bonn.de/de/personal/schmitz
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________