* a string xmlpath in Lua
@ 2017-07-10 9:15 MF
2017-07-10 11:44 ` MF
0 siblings, 1 reply; 2+ messages in thread
From: MF @ 2017-07-10 9:15 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hello list,
is there a Lua function to get the XML path of an element as a string?
\xmlpath typesets the path, I need a similar function for Lua, but the
path should be a string to be worked on in Lua.
This is the problem originating that question: i must name (give an id
to) some anonymous XML elements (read: "without an id attribute"), and
their path is a good candidate.
To be more precise: when i parse a <table> element, i look for elements
representing footnotes, to prepare them with \setnotetext;
then the table contents are parsed and the footnotes' markers are
typeset with \note[footnote_id].
When there are more footnotes, i need to identify them, to give \note
the right footnote id.
Thanks,
Massi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: a string xmlpath in Lua
2017-07-10 9:15 a string xmlpath in Lua MF
@ 2017-07-10 11:44 ` MF
0 siblings, 0 replies; 2+ messages in thread
From: MF @ 2017-07-10 11:44 UTC (permalink / raw)
To: ntg-context
> Hello list,
> is there a Lua function to get the XML path of an element as a
> string?
>
Found. I adapted a function from lxml-tex.lua (chainpath):
function xmlpath( e, nonamespace )
if e then
local t = { }
while e do
local tg = e.tg
local rt = e.__p__
local ns = e.ns
if tg == "@rt@" then
break
elseif rt.tg == "@rt@" then
if nonamespace or not ns or ns == "" then
t[ #t + 1 ] = tg
else
t[ #t + 1 ] = ns .. ":" .. tg
end
else
if nonamespace or not ns or ns == "" then
t[ #t + 1 ] = tg .. "[" .. e.ei .. "]"
else
t[ #t + 1 ] = ns .. ":" .. tg .. "[" .. e.ei .. "]"
end
end
e = rt
end
return table.concat( table.reverse( t ), "/" )
else
return ""
end
end
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-10 11:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-10 9:15 a string xmlpath in Lua MF
2017-07-10 11:44 ` MF
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).