ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Schmitz Thomas A." <thomas.schmitz@uni-bonn.de>
To: mailing ConTeXt users list for <ntg-context@ntg.nl>
Subject: processing xml with lua
Date: Tue, 26 Feb 2013 13:23:41 +0100	[thread overview]
Message-ID: <04D0A21F-FEAB-4F86-8317-6ED044B41619@uni-bonn.de> (raw)

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
___________________________________________________________________________________


             reply	other threads:[~2013-02-26 12:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26 12:23 Schmitz Thomas A. [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=04D0A21F-FEAB-4F86-8317-6ED044B41619@uni-bonn.de \
    --to=thomas.schmitz@uni-bonn.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).