ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* processing xml with lua
@ 2013-02-26 12:23 Schmitz Thomas A.
  2013-02-26 12:54 ` Hans Hagen
  0 siblings, 1 reply; 8+ messages in thread
From: Schmitz Thomas A. @ 2013-02-26 12:23 UTC (permalink / raw)
  To: mailing ConTeXt users list for

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?

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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-03-05 10:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-26 12:23 processing xml with lua Schmitz Thomas A.
2013-02-26 12:54 ` Hans Hagen
2013-02-26 13:32   ` Schmitz Thomas A.
2013-03-05  8:47     ` Thomas A. Schmitz
2013-03-05  8:58       ` Hans Hagen
2013-03-05  9:16         ` Thomas A. Schmitz
2013-03-05 10:11           ` Hans Hagen
2013-03-05 10:27             ` Thomas A. Schmitz

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).