![](https://secure.gravatar.com/avatar/532990f0c5a8331f60e3d0e1173292a6.jpg?s=120&d=mm&r=g)
Just a quick question regarding this? Is xml.filter equivalent to \xmlfilter? If so, how do you pass the match to a command as you'd do with \xmlfilter? Best, Denis
-----Ursprüngliche Nachricht----- Von: ntg-context
Im Auftrag von mf via ntg- context Gesendet: Mittwoch, 16. November 2022 20:56 An: ntg-context@ntg.nl Cc: mf Betreff: Re: [NTG-context] Xml filtering in Lua This works:
local metadata = xml.filter (t, '../../topics/topic[@t:id=="' .. ch_id .. '"]')
also this:
local lpath = string.format('../../topics/topic[@t:id=="%s"]', ch_id)
local metadata = xml.filter (t, lpath)
It looks like xml.filter supports only 2 arguments (see lxml-tex.lua), and so it doesn't let you use string formatting patterns like the "context" command does.
You can write:
context('the value of @t:id is "%s"', ch_id)
but you can't write:
xml.filter (t, '../../topics/topic[@t:id=="%s"]', ch_id)
Best wishes,
Massi
__________________________________________________________ _________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg- context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net __________________________________________________________ _________________________
-----Ursprüngliche Nachricht----- Von: ntg-context
Im Auftrag von Thomas A. Schmitz via ntg-context Gesendet: Mittwoch, 16. November 2022 20:56 An: mailing list for ConTeXt users Cc: Thomas A. Schmitz Betreff: Re: [NTG-context] Xml filtering in Lua On 11/16/22 19:56, mf via ntg-context wrote:
local ch_id = t.at["ch:id"]
You're right, of course, using a colon was a stupid idea. When I replace it with an underscore, you can see that both are in fact identical:
\startbuffer[test] <document> <topics> <topic t_id="test1"> <title>This is the first test</title> <date>22/11/16</date> </topic> <topic t_id="test2"> <title>This is the second test</title> <date>22/11/17</date> </topic> </topics> <chapters> <chapter ch_id="test1"> <content> This will be the content of the <emph>first</emph> chapter. </content> </chapter> <chapter ch_id="test2"> <content> This will be the content of the <emph>second</emph> chapter. </content> </chapter> </chapters> </document> \stopbuffer
\startxmlsetups xml:testsetups \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{document|chapters|chapter|content|emph}{xml: *} \stopxmlsetups
\xmlregistersetup{xml:testsetups}
\startxmlsetups xml:document \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:chapters \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:chapter \xmlfunction {#1} {chapter} % \xmlflush {#1} \stopxmlsetups
\startxmlsetups xml:chapter:content \xmltext {#1} {content} \stopxmlsetups
\startxmlsetups xml:emph {\em \xmlflush {#1}} \stopxmlsetups
\startluacode function xml.functions.chapter (t) local chapter_id = t.at.ch_id local other_chapter_id = t.at["ch_id"] context (chapter_id) context.par () context (other_chapter_id) context.par () local metadata = xml.filter (t, '../../topics/topic[@t:id=="%s"]', ch_id) print (inspect(metadata)) lxml.command(t, ".", "xml:chapter:content") context.par () 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 / https://www.ntg.nl/mailman/listinfo/ntg- context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net __________________________________________________________ _________________________