ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Thomas A. Schmitz" <thomas.schmitz@uni-bonn.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: processing xml with lua
Date: Tue, 05 Mar 2013 09:47:48 +0100	[thread overview]
Message-ID: <5135B134.10900@uni-bonn.de> (raw)
In-Reply-To: <92A8729E-7338-4EE3-8835-BE8A66DE748B@uni-bonn.de>

Hi,

may I ask another question about my new favorite topic? No? Anyway: here 
comes. While processing xml, I would like to store the content of a node 
in a lua table and retrieve it later. The example is silly, but 
demonstrates my problem. Is there a way to have ConTeXt process and 
typeset the value in lines 3 and 4? As you can see, it typesets the raw 
xml instead of processing it. (I suspect I'm still a bit lost regarding 
the difference between xml... and lxml... functions, but I couldn't hit 
the right combination here).

Thanks, and all best

Thomas

\startbuffer[test]
<a>
   <b><c>Fruit</c> <d><e>Apple</e></d></b>
   <b><c>Vegetable</c> <d><q>Carot</q></d></b>
   <b><c>Fruit</c></b>
   <b><c>Vegetable</c></b>
</a>
\stopbuffer

\startxmlsetups xml:testsetups
	\xmlsetsetup{\xmldocument}{a|b|c|d}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

\startxmlsetups xml:a
	\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:b
	\xmlfunction{#1}{lookup} \par
\stopxmlsetups

\startxmlsetups xml:e
	{\bgroup\em \xmlflush{#1}\egroup}
\stopxmlsetups

\startxmlsetups xml:q
	\quotation{\xmlflush{#1}}
\stopxmlsetups

\startluacode
lookuptable = { }
function xml.functions.lookup(t)
   mytype = xml.text(t, "c")
   myvalue = xml.text(t, "d")
   if not lookuptable[mytype] then
     context("New Type: ") context(mytype) context("; its value is: ") 
lxml.text(t, "d")
     lookuptable[mytype] = mytype .. " = " .. myvalue
   else
     context("This Type is already known: ") context(lookuptable[mytype])
   end
end
\stopluacode

\starttext
\xmlprocessbuffer{main}{test}{}

\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-03-05  8:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26 12:23 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 [this message]
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=5135B134.10900@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).