On 2/26/2013 1:23 PM, Schmitz Thomas A. wrote:
Hi all,
one of my favorite topics… Here is a minimal example which shows something that I don't understand: when I process the subsection with the lua code, I want to get the value of the current section's "label" attribute in xml.attribute(r, "../../section", "label", "X"). So i was expecting that lua would go up (../../) and fetch the current section's label. But if you run the example, you see that it actually always gets the first section's label (value is always 1). How can I get the current section's label with a lua function?
you go up to the parent of sections which to far up, try: section = xml.attribute(r, "..", "label", "X") or section = xml.filter(r, "../attribute(label)")
THanks and all best
Thomas
\startbuffer[test] <chapter> <section label="1"> <subsection label="1"> <content> text 1.1 </content> </subsection> </section> <section label="3"> <subsection label="1"> <content> text 3.1 </content> </subsection> <subsection label="5"> <content> text 3.5 </content> </subsection> </section> </chapter> \stopbuffer
\startxmlsetups xml:testsetups \xmlsetsetup{\xmldocument}{chapter|section|subsection|content}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:testsetups}
\startxmlsetups xml:chapter \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:section \xmlflush{#1} \par \stopxmlsetups
\startxmlsetups xml:subsection \xmlfunction{#1}{test} \stopxmlsetups
\startluacode outfile = io.open('temp.tmp', 'w') function xml.functions.test(r) content = xml.text(r, "content") section = xml.attribute(r, "../../section", "label", "X") context("This ") context(content) context(" is in section ") context(section) end \stopluacode
\starttext \xmlprocessbuffer{main}{test}{}
\enabletrackers[context.trace]
\xmlshow{main} \stoptext
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------