From: Hans Hagen <pragma@wxs.nl>
To: ntg-context@ntg.nl
Subject: Re: Help with xml & lua
Date: Mon, 7 Aug 2017 15:38:01 +0200 [thread overview]
Message-ID: <fa7565b8-89de-544a-369e-ac8369ecb5da@wxs.nl> (raw)
In-Reply-To: <48e40256-9b2a-6d7b-ec77-760212d7b472@wanadoo.fr>
On 8/2/2017 5:23 PM, Olivier Binda wrote:
> Hello
>
> I have been trying for the past 3 days to process files with xml on the
> lua side (with Context beta 0.70), but I'm at then end of my wits and
> really need help.
>
> On the lua side, I would really like to be able to :
>
> 1) transform a tree : replace nodes with other nodes
>
> 2) transform a tree : walk it and modify node attributes
>
> 3) walk a modified tree and flush it with setups
what do you mean with 'walk with setups' ... at the lua end? setuips are
something at the tex end
> Could someone give me hints or better yet a lua snipet that :
> 1) load a tree in lua
> 2) modify it
> 3) walk it
> 4) it can be done again
in some cases you need to apply setups after adaption, eg with
\xmlregistereddocumentsetups{...}{...}
> I have had some success with 1, but lost 2 days trying to make 2 & 3
> work with setups
>
> A) I managed to replace a node of an xml document with a subtree of
> another xml document by doing :
>
> -- load the main tree
> local mainTree = lxml.load("mainTree", "mainFile.xml)
>
> local replacementNode = xml.first(lxml.load("replacement",
> "replacementFile.xml), somePattern)
>
> -- replace nodes
> for node in xml.collected(tree, pattern) do
> node.tg ="toBeReplaced"
> xml.replace(tree, "toBeReplaced", replacementNode)
> end
>
> But then I failed to walk the modified tree with setups : my setups for
> "mainTree" work, but not for the inserted subtrees
at the lua end there's lxm.include
(there's also some some indexing going on)
> B) So, to process my tree further, I need to first serialize it
>
> -- save the modified tree
>
> xml.save(mainTree, "saved.xml")
>
> And then, I can reload the modified tree and work further with it (but
> it sucks to have to save to reload).
\xmlinclude should work ok (at least it does at our end) given that you
do it before associating the setups
> C) "xml.replace" works in a weird way : it erases node (toBereplaced)
> and inserts the children of replacementNode as children of the parent of
> the node to be replaced...
>
> D) I did not manage to walk a tree loaded with xml.load in lua. I know
> that I have to register setups, I tried all sort of things, looked at
> the Tex/Lua context source code but could not make it work. Also the xml
> documentation for context on the net is really old, sparse and obsolete.
>
> On the tex side, it works : \xmlprocessfile{mySetups}{saved.xml}{} works
> like a charm
> But the TeX commands don't allow you to grab a modified xml tree, once
> you have walked it
>
> E) I tried
>
> lxml.load(id, filename)
> context("\\xmlregistereddocumentsetups{" .. id .. "}{}")
you need to provide (small) working (valid) examples
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
___________________________________________________________________________________
prev parent reply other threads:[~2017-08-07 13:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-02 15:23 Olivier Binda
2017-08-07 13:38 ` Hans Hagen [this message]
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=fa7565b8-89de-544a-369e-ac8369ecb5da@wxs.nl \
--to=pragma@wxs.nl \
--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).