From thomas.schmitz@uni-bonn.de Wed Nov 16 17:10:37 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 17:10:19 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7878060798651139750==" --===============7878060798651139750== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi all, I thought this was easy, but I overestimated my competence=E2=80=A6 I want to= filter xml elements via their attributes and retrieve and typeset parts belo= nging together. Here is a small test file that explains what I=E2=80=99m tryi= ng: \startbuffer[test] This is the first test 22/11/16 This is the second test 22/11/17 This will be the content of the first chapter. This will be the content of the second chapter. \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}=09 \stopxmlsetups \startxmlsetups xml:chapter:content \xmltext {#1} {content} \stopxmlsetups \startxmlsetups xml:emph {\em \xmlflush {#1}} \stopxmlsetups \startluacode function xml.functions.chapter (t) local ch_id =3D t.at.id local metadata =3D xml.filter (root, '../../topics/topic[@id=3D=3D"%s"]', c= h_id) print (inspect(metadata)) lxml.command(t, ".", "xml:chapter:content") context.par () context (ch_id) context.par () end \stopluacode \starttext \xmlprocessbuffer{main}{test}{} \stoptext The line with xml.filter does not work as I expected. How can I walk the tree= , find the =E2=80=9Ctopic=E2=80=9D element with the same =E2=80=9Cid=E2=80=9D= attribute as the chapter I=E2=80=99m currently in, and then typeset the diff= erent children of the topic element?=20 Thanks a lot and all best Thomas --===============7878060798651139750==-- From dh@capdm.com Wed Nov 16 17:18:38 2022 From: Duncan Hothersall To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 16:18:20 +0000 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6953049227824564828==" --===============6953049227824564828== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi Thomas. I'm not sure about the code, sorry, but I do know that an XML document can't have two IDs of the same value. Typically you would use a linkend attribute on the element which is referencing an id (in this case the topics, I think). Probably doesn't help with your problem, but it's likely a prerequisite for it to work. Bests, Duncan On Wed, 16 Nov 2022 at 16:11, Thomas A. Schmitz via ntg-context < ntg-context(a)ntg.nl> wrote: > Hi all, > > I thought this was easy, but I overestimated my competence=E2=80=A6 I want = to > filter xml elements via their attributes and retrieve and typeset parts > belonging together. Here is a small test file that explains what I=E2=80=99= m trying: > > \startbuffer[test] > > > > This is the first test > 22/11/16 > > > This is the second test > 22/11/17 > > > > > > This will be the content of the first chapter. > > > > > This will be the content of the second chapter. > > > > > \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 ch_id =3D t.at.id > local metadata =3D xml.filter (root, > '../../topics/topic[@id=3D=3D"%s"]', ch_id) > print (inspect(metadata)) > lxml.command(t, ".", "xml:chapter:content") > context.par () > context (ch_id) > context.par () > end > \stopluacode > > \starttext > \xmlprocessbuffer{main}{test}{} > \stoptext > > The line with xml.filter does not work as I expected. How can I walk the > tree, find the =E2=80=9Ctopic=E2=80=9D element with the same =E2=80=9Cid=E2= =80=9D attribute as the chapter > I=E2=80=99m currently in, and then typeset the different children of the to= pic > element? > > Thanks a lot and all best > > Thomas > > > ___________________________________________________________________________= ________ > If your question is of interest to others as well, please add an entry to > the Wiki! > > maillist : ntg-context(a)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 > > ___________________________________________________________________________= ________ > --===============6953049227824564828== Content-Type: text/html Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="attachment.html" MIME-Version: 1.0 PGRpdiBkaXI9Imx0ciI+SGkgVGhvbWFzLjxkaXY+PGJyPjwvZGl2PjxkaXY+SSYjMzk7bSBub3Qg c3VyZSBhYm91dCB0aGUgY29kZSwgc29ycnksIGJ1dCBJIGRvIGtub3cgdGhhdCBhbiBYTUwgZG9j dW1lbnQgY2FuJiMzOTt0IGhhdmUgdHdvIElEcyBvZiB0aGUgc2FtZSB2YWx1ZS4gVHlwaWNhbGx5 IHlvdSB3b3VsZCB1c2UgYSBsaW5rZW5kIGF0dHJpYnV0ZSBvbiB0aGUgZWxlbWVudCB3aGljaCBp cyByZWZlcmVuY2luZyBhbiBpZCAoaW4gdGhpcyBjYXNlIHRoZSB0b3BpY3MsIEkgdGhpbmspLjwv ZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+UHJvYmFibHkgZG9lc24mIzM5O3QgaGVscCB3aXRoIHlv dXIgcHJvYmxlbSwgYnV0IGl0JiMzOTtzIGxpa2VseSBhIHByZXJlcXVpc2l0ZSBmb3IgaXQgdG8g d29yay48L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PkJlc3RzLDwvZGl2PjxkaXY+PGJyPjwvZGl2 PjxkaXY+RHVuY2FuPC9kaXY+PC9kaXY+PGJyPjxkaXYgY2xhc3M9ImdtYWlsX3F1b3RlIj48ZGl2 IGRpcj0ibHRyIiBjbGFzcz0iZ21haWx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hIGhyZWY9 Imh0dHBzOi8vYml0YnVja2V0Lm9yZy9waGcvY29udGV4dC1taXJyb3IvY29tbWl0cy8iIHJlbD0i bm9yZWZlcnJlciIgdGFyZ2V0PSJfYmxhbmsiPmh0dHBzOi8vYml0YnVja2V0Lm9yZy9waGcvY29u dGV4dC1taXJyb3IvY29tbWl0cy88L2E+PGJyPgp3aWtpwqAgwqAgwqA6IDxhIGhyZWY9Imh0dHBz Oi8vY29udGV4dGdhcmRlbi5uZXQiIHJlbD0ibm9yZWZlcnJlciIgdGFyZ2V0PSJfYmxhbmsiPmh0 dHBzOi8vY29udGV4dGdhcmRlbi5uZXQ8L2E+PGJyPgpfX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f Xzxicj4KPC9ibG9ja3F1b3RlPjwvZGl2Pgo= --===============6953049227824564828==-- From thomas.schmitz@uni-bonn.de Wed Nov 16 18:33:21 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 18:33:07 +0100 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6559033846710103516==" --===============6559033846710103516== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi Duncan, Thank you for pointing this out! I knew this was true inside the xmlns namesp= ace, so you can=E2=80=99t have identical xml:id tags, but you=E2=80=99re prob= ably right that it=E2=80=99s better to avoid this confusion altogether. Alas,= this doesn=E2=80=99t help with my problem. Since there was a type in my mini= mal example from my experimentations, I include a corrected version, avoiding= the identical tags All best Thomas \startbuffer[test] This is the first test 22/11/16 This is the second test 22/11/17 This will be the content of the first chapter. This will be the content of the second chapter. \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}=09 \stopxmlsetups \startxmlsetups xml:chapter:content \xmltext {#1} {content} \stopxmlsetups \startxmlsetups xml:emph {\em \xmlflush {#1}} \stopxmlsetups \startluacode function xml.functions.chapter (t) local ch_id =3D t.at.ch:id local metadata =3D xml.filter (t, '../../topics/topic[@t:id=3D=3D"%s"]', ch= _id) print (inspect(metadata)) lxml.command(t, ".", "xml:chapter:content") context.par () context (ch_id) context.par () end \stopluacode > On 16. Nov 2022, at 17:18, Duncan Hothersall via ntg-context wrote: >=20 > I'm not sure about the code, sorry, but I do know that an XML document can'= t have two IDs of the same value. Typically you would use a linkend attribute= on the element which is referencing an id (in this case the topics, I think). >=20 > Probably doesn't help with your problem, but it's likely a prerequisite for= it to work. >=20 > Bests, >=20 > Duncan --===============6559033846710103516==-- From massifr@fastwebnet.it Wed Nov 16 19:59:48 2022 From: mf To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 19:56:55 +0100 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4752381392704256781==" --===============4752381392704256781== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Il 16/11/22 18:33, Thomas A. Schmitz via ntg-context ha scritto: > \startbuffer[test] > > > > This is the first test > 22/11/16 > > > This is the second test > 22/11/17 > > > > > > This will be the content of the first chapter. > > > > > This will be the content of the second chapter. > > > > > \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 ch_id = t.at.ch:id local ch_id = t.at["ch:id"] > local metadata = xml.filter (t, '../../topics/topic[@t:id=="%s"]', ch_id) > print (inspect(metadata)) > lxml.command(t, ".", "xml:chapter:content") > context.par () > context (ch_id) > context.par () > end > \stopluacode Best wishes, Massi --===============4752381392704256781==-- From thomas.schmitz@uni-bonn.de Wed Nov 16 20:55:34 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 20:55:31 +0100 Message-ID: <2d5a5ef3-ed95-9e95-cfee-b8794294daff@uni-bonn.de> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2112077239458816543==" --===============2112077239458816543== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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] This is the first test 22/11/16 This is the second test 22/11/17 This will be the content of the first chapter. This will be the content of the second chapter. \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 --===============2112077239458816543==-- From massifr@fastwebnet.it Wed Nov 16 20:56:03 2022 From: mf To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 20:56:00 +0100 Message-ID: <4902918e-d6e1-47a7-6d22-0067262a5714@fastwebnet.it> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1642206596314510739==" --===============1642206596314510739== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 --===============1642206596314510739==-- From denis.maier@unibe.ch Wed Nov 16 21:51:14 2022 From: denis.maier@unibe.ch To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 20:51:10 +0000 Message-ID: <17811cfc131b41edae5ea2168e77c912@unibe.ch> In-Reply-To: <2d5a5ef3-ed95-9e95-cfee-b8794294daff@uni-bonn.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2837102064587119597==" --===============2837102064587119597== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=BCngliche Nachricht----- > Von: ntg-context Im Auftrag von mf via ntg- > context > Gesendet: Mittwoch, 16. November 2022 20:56 > An: ntg-context(a)ntg.nl > Cc: mf > Betreff: Re: [NTG-context] Xml filtering in Lua >=20 > This works: >=20 > local metadata =3D xml.filter (t, '../../topics/topic[@t:id=3D=3D"' .. ch_i= d .. '"]') >=20 > also this: >=20 > local lpath =3D string.format('../../topics/topic[@t:id=3D=3D"%s"]', ch_id) >=20 > local metadata =3D xml.filter (t, lpath) >=20 >=20 > 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. >=20 > You can write: >=20 > context('the value of @t:id is "%s"', ch_id) >=20 > but you can't write: >=20 > xml.filter (t, '../../topics/topic[@t:id=3D=3D"%s"]', ch_id) >=20 >=20 > Best wishes, >=20 > Massi >=20 > __________________________________________________________ > _________________________ > If your question is of interest to others as well, please add an entry to t= he > Wiki! >=20 > maillist : ntg-context(a)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=C3=BCngliche 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 >=20 > On 11/16/22 19:56, mf via ntg-context wrote: > > local ch_id =3D t.at["ch:id"] >=20 > 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: >=20 > \startbuffer[test] > > > > This is the first test > 22/11/16 > > > This is the second test > 22/11/17 > > > > > > This will be the content of the first chapter. > > > > > This will be the content of the second chapter. > > > > > \stopbuffer >=20 > \startxmlsetups xml:testsetups > \xmlsetsetup{#1}{*}{-} > \xmlsetsetup{#1}{document|chapters|chapter|content|emph}{xml: > *} > \stopxmlsetups >=20 > \xmlregistersetup{xml:testsetups} >=20 > \startxmlsetups xml:document > \xmlflush{#1} > \stopxmlsetups >=20 > \startxmlsetups xml:chapters > \xmlflush{#1} > \stopxmlsetups >=20 > \startxmlsetups xml:chapter > \xmlfunction {#1} {chapter} > % \xmlflush {#1} > \stopxmlsetups >=20 > \startxmlsetups xml:chapter:content > \xmltext {#1} {content} > \stopxmlsetups >=20 > \startxmlsetups xml:emph > {\em \xmlflush {#1}} > \stopxmlsetups >=20 > \startluacode > function xml.functions.chapter (t) > local chapter_id =3D t.at.ch_id > local other_chapter_id =3D t.at["ch_id"] > context (chapter_id) > context.par () > context (other_chapter_id) > context.par () > local metadata =3D xml.filter (t, '../../topics/topic[@t:id=3D=3D"%s"]', > ch_id) > print (inspect(metadata)) > lxml.command(t, ".", "xml:chapter:content") > context.par () > end > \stopluacode >=20 > \starttext > \xmlprocessbuffer{main}{test}{} > \stoptext >=20 > __________________________________________________________ > _________________________ > If your question is of interest to others as well, please add an entry to t= he > Wiki! >=20 > maillist : ntg-context(a)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 > __________________________________________________________ > _________________________ --===============2837102064587119597==-- From thomas.schmitz@uni-bonn.de Wed Nov 16 22:09:47 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 22:09:45 +0100 Message-ID: <97c5e0b8-aab1-5742-ee72-a8ffdc9049cb@uni-bonn.de> In-Reply-To: <17811cfc131b41edae5ea2168e77c912@unibe.ch> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0400093918830782096==" --===============0400093918830782096== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On 11/16/22 21:51, Denis Maier via ntg-context wrote: > 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? I'm still digesting and playing with Massi's reply; will probably be=20 back with more questions :-) Anyway: If you've filtered something out like this local tree =3D xml.filter (t, "../chapter[@title=3D'mytitle'") you can then apply a command to it lxml.command(lxml.id(tree), ".", "xml:chapter:command") and have to define the command as \startxmlsetups xml:chapter:command \xmltext {#1} {content} \stopxmlsetups for example. Thomas --===============0400093918830782096==-- From j.hagen@xs4all.nl Wed Nov 16 23:19:38 2022 From: Hans Hagen To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Wed, 16 Nov 2022 23:19:34 +0100 Message-ID: <85566e11-a4c6-3cea-32ca-bb2d160dc7de@xs4all.nl> In-Reply-To: <97c5e0b8-aab1-5742-ee72-a8ffdc9049cb@uni-bonn.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2753160055155154526==" --===============2753160055155154526== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 11/16/2022 10:09 PM, Thomas A. Schmitz via ntg-context wrote: > On 11/16/22 21:51, Denis Maier via ntg-context wrote: >> 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? > > I'm still digesting and playing with Massi's reply; will probably be > back with more questions :-) > > Anyway: > > If you've filtered something out like this > > local tree = xml.filter (t, "../chapter[@title='mytitle'") always keep in mind that some expressions return a list of matches, that can be looped over and some commands just process the first anyway, it can sometimes help to add print(tstring(tree)) so see what you got 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 ----------------------------------------------------------------- --===============2753160055155154526==-- From j.hagen@xs4all.nl Thu Nov 17 11:04:43 2022 From: Hans Hagen To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Thu, 17 Nov 2022 11:04:40 +0100 Message-ID: In-Reply-To: <4902918e-d6e1-47a7-6d22-0067262a5714@fastwebnet.it> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5178158804554029360==" --===============5178158804554029360== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 11/16/2022 8:56 PM, mf via ntg-context wrote: > 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) In Thomas example this is also an approach: \startxmlsetups xml:document \xmlfunction{#1} {document} \xmlflush{#1} \stopxmlsetups with \startluacode local topics = { } local chapters = { } function xml.functions.document(t) for c in xml.collected(t,"/topics/topic") do topics[c.at.t_id] = c end -- for c in xml.collected(t,"/chapters/chapter") do -- chapters[c.at.ch_id] = c -- -- or flush here -- end end function xml.functions.chapter (t) local ch_id = t.at.ch_id local metadata = topics[ch_id] lxml.command(t, ".", "xml:chapter:content") context.par () context (ch_id) context.par () end \stopluacode so, basically you collect data and use it later ... for huge datasets that saves some time if you have only chapters to process you can even decide to flush in that function 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 ----------------------------------------------------------------- --===============5178158804554029360==-- From thomas.schmitz@uni-bonn.de Thu Nov 17 11:56:47 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Thu, 17 Nov 2022 11:56:34 +0100 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2696613714217276451==" --===============2696613714217276451== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable > On 17. Nov 2022, at 11:04, Hans Hagen via ntg-context wrote: >=20 > so, basically you collect data and use it later ... for huge datasets that = saves some time >=20 > if you have only chapters to process you can even decide to flush in that f= unction >=20 > Hans I think this is exactly the approach I=E2=80=99m looking for: collecting ever= ything in Lua tables and then retrieving and typesetting it later. I=E2=80=99= m experimenting with it right now. I will have to define a proper lxml.comman= d for every xml tag, I guess; otherwise, the xml gets serialized? I=E2=80=99l= l play some more and will certainly be back with questions :-) Thank you, as always, and all best Thomas --===============2696613714217276451==-- From thomas.schmitz@uni-bonn.de Sun Nov 20 19:19:23 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Sun, 20 Nov 2022 19:19:18 +0100 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============9209345540539171765==" --===============9209345540539171765== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 11/17/22 11:04, Hans Hagen via ntg-context wrote: > > so, basically you collect data and use it later ... for huge datasets > that saves some time > > if you have only chapters to process you can even decide to flush in > that function Alright, I'm making very good progress here, but right now I'm stumbling upon a problem I can't solve. It's difficult to make a minimal example, so bear with some snippets. I load data from an external xml file (not the one I'm processing) and store some of it in a lua table. local examples = lxml.load ("my_examples", "examples.xml") local sets = lxml.load ("my_sets", "example_sets.xml") for e in xml.collected (examples, "/examples/chapter/example") do local ex_id = e.at.id all_examples [ex_id] = e end This works as expected, with print (inspect (all_examples)), I can see that the table looks the way I expect. I then retrieve some entries of the table by their key: local current_example = all_examples [key] Again, this appears to work; when I have a lxml.displayverbatim (current_example) in my file, the xml is typeset and looks like I would expect it to look. However, whatever I try, I get the serialized xml typeset, with all verbatim, instead of processed. Here's what I've tried: \startxmlsetups xml:chapter:example \xmlfirst {#1} {.} \par \stopxmlsetups lxml.command (current_example, ".", "xml:chapter:example") or xml.sprint (lxml.id (current_example)) or local problem = xml.text (lxml.id (current_example), "./[text()]") xml.sprint (problem) I was expecting at least the last version to retrieve the pure text, but it typesets again with the tags included. So I guess my question is: how can I tell ConTeXt to parse my xml as xml and apply the proper setups instead of serializing it? All best wishes Thomas --===============9209345540539171765==-- From thomas.schmitz@uni-bonn.de Mon Nov 21 09:23:14 2022 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] Xml filtering in Lua Date: Mon, 21 Nov 2022 09:23:18 +0100 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7769902776150290401==" --===============7769902776150290401== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 11/20/22 19:19, Thomas A. Schmitz via ntg-context wrote: > I load data from an external xml file (not the one I'm processing) and > store some of it in a lua table. > > local examples = lxml.load ("my_examples", "examples.xml") Replying to myself, and sorry for the noise (this was fairly easy, should have seen it earlier): instead of loading the file "examples.xml," I simply include it via xmlinclude into the tree; this way the proper setups are applied. All best Thomas --===============7769902776150290401==--