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
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
participants (1)
-
MF