> On 6 Oct 2025, at 17:34, Thomas A. Schmitz <[email protected]> wrote:
>
> 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.
I find that for me personally the easiest way to do something like this is to
set a state variable in the tree; my input is very similar to HTML complete
with the “style" attribute parsing so my code is very geared towards processing
properties and attributes. Setting it up would look something like this
function xml.functions.footnote(t)
lxml.setparameter(t,'*’,’infootnote’, 1)
lmxl.flush(t)
ene
The lxml.setparameter sets a value in the ‘pa' field in the whole child xml
tree, so to get at the value, perhaps with a default, you would use something
like this inside the <ref> processing.
function inherited(t,a,b)
if t.pa and t.pa[a] then return t.pa[a] else return b end
end
function xml.functions.ref(t)
if inherited(t, ‘infootnote’, 0) == 1 then
..
end
..
end
But this is not very efficient if you not need to access that property a lot.
Alternatively, you can do loop using xml.parent(t) to move upwards in the tree
from within xml.functions.ref() to see whether there is ‘footnote’ parent. That
has the advantage that would also have easy direct access to its attributes,
but it has been a while since I used that sort of logic so I do not have
example code ready, sorry.
Best wishes,
Taco
___________________________________________________________________________________
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
___________________________________________________________________________________