ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	mf <massifr@fastwebnet.it>
Subject: Re: content of xml node (element) in lua
Date: Sat, 17 Oct 2020 12:02:29 +0200	[thread overview]
Message-ID: <a269e180-34d9-a27d-18ac-898483bc9858@xs4all.nl> (raw)
In-Reply-To: <ae180a8b-0fed-6344-556e-f1229ae486fa@fastwebnet.it>

On 10/17/2020 12:16 AM, mf wrote:
> (sorry, I sent it before refining it)
> 
> Il 16/10/20 20:57, Jano Kula ha scritto:
>> Hello!
>>
>> Processing XML I want to manipulate content of XML elements inside Lua.
>>
>> I can define the Lua function xml.functions.name 
>> <http://xml.functions.name>(t), where processing happens, and use the 
>> command \xmlfunction{#1}{name} to pass the current node #1from ctx to 
>> lua as described in the xml-mkiv.pdf manual. To access the element 
>> content xml.text(t,"/element") Lua function is used.
>>
>> However, using the same function xml.text("#1",/element) directly 
>> inside Lua doesn't work for me. Node #1 is available, but not the 
>> content of /element.
> 
> In your lua fragment, node #1 is available as "xml:name::4" or 
> "xml:name::6", but not as a lua table.

when you're at the lua end you can use lxml.getid to access that node, 
assuming that you somehow pass #1 (being a string)


> When node #1 is passed to a \xmlfunction, the function gets a lua table 
> as argument.
> 
> To write direct lua code instead of a xmlfunction you'd need a function 
> to transform those "xml:name::..." into the lua tables representing the 
> xml elements in the xml tree.
> 
> Which is what \xmlfunction does, so I wouldn't expect any performance gain.

actually one has the same function at the lua end, so once you passed 
the node id you can use

xml.first(lxml.getid("xml:name::4"),"foo/bar")

and alike (the lxml.* function pipe back to tex)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2020-10-17 10:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16 18:57 Jano Kula
2020-10-16 22:16 ` mf
2020-10-17 10:02   ` Hans Hagen [this message]
2020-10-17 10:45     ` Jano Kula

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=a269e180-34d9-a27d-18ac-898483bc9858@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=massifr@fastwebnet.it \
    --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).