[NTG-context] Xml filtering in Lua

Thomas A. Schmitz thomas.schmitz at uni-bonn.de
Wed Nov 16 20:55:31 CET 2022

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:

      <topic t_id="test1">
	<title>This is the first test</title>
      <topic t_id="test2">
	<title>This is the second test</title>
      <chapter ch_id="test1">
	  This will be the content of the <emph>first</emph> chapter.
      <chapter ch_id="test2">
	  This will be the content of the <emph>second</emph> chapter.

\startxmlsetups xml:testsetups


\startxmlsetups xml:document

\startxmlsetups xml:chapters

\startxmlsetups xml:chapter
	\xmlfunction {#1} {chapter}
%	 \xmlflush {#1}	

\startxmlsetups xml:chapter:content
	\xmltext {#1} {content}

\startxmlsetups xml:emph
   {\em \xmlflush {#1}}

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 ()


More information about the ntg-context mailing list