[NTG-context] Xml filtering in Lua

Thomas A. Schmitz thomas.schmitz at uni-bonn.de
Wed Nov 16 18:33:07 CET 2022

Hi Duncan,

Thank you for pointing this out! I knew this was true inside the xmlns namespace, so you can’t have identical xml:id tags, but you’re probably right that it’s better to avoid this confusion altogether. Alas, this doesn’t help with my problem. Since there was a type in my minimal example from my experimentations, I include a corrected version, avoiding the identical tags

All best


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

> On 16. Nov 2022, at 17:18, Duncan Hothersall via ntg-context <ntg-context at ntg.nl> wrote:
> 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

More information about the ntg-context mailing list