On 8/18/25 12:30 PM, Hans Hagen wrote:
you need to apply setups so here we just load at the tex end

Hans
Hans,

thank you! And yes, of course; this is how I process my main files. My example wasn't explicit enough: I need a second pass to typeset notes. New example, hopefully clearer. As I said - maybe I'm trying too hard to reinvent the wheel, but right now, this appears to be the best approach for what I want to do.

All best

Thomas


\startbuffer[test]
<document>
	<content>
		<include href="test.xml"/>
	</content>
   <content type="notes">
		<notesinclude href="test.xml"/>
   </content>
</document>
\stopbuffer

\startxmlsetups xml:testsetups
  \xmlinclude{#1}{include}{href}
  \xmlsetsetup{#1}{*}{-}
  \xmlsetsetup{#1}{document|notesinclude|chapter|chaptertitle|content|note|emph|bold|p}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

\startxmlsetups xml:document
	\xmlflush {#1}
\stopxmlsetups

\startxmlsetups xml:content
	\xmlfunction {#1} {content}
\stopxmlsetups

\startxmlsetups xml:chapter
	\startchapter [title=\xmltext {#1} {chaptertitle}]
	\xmlflush {#1}
   \stopchapter
\stopxmlsetups

\startxmlsetups xml:p
	\xmlflush {#1}\par
\stopxmlsetups

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

\startxmlsetups xml:bold
    {\bf \xmlflush {#1}}
\stopxmlsetups

\startxmlsetups xml:note
    \pagereference [\xmlatt {#1} {xml:id}]
\stopxmlsetups

\startluacode
function xml.functions.content (t)
	if xml.attribute (t, "./", "type", "X") and xml.attribute (t, "./", "type", "X") == "notes" then
		current_file = xml.attribute (t, "/notesinclude", "href", "X")
		for e in xml.collected (xml.load (current_file), "chapter") do
			raw_title = xml.text (lxml.id (e), "/chaptertitle")
			ch_title = "Notes to " .. raw_title
			context.page ()
			context.startsubsection { title=ch_title }
			for note in xml.collected (lxml.id (e), "/**/note") do
				note_ref = xml.attribute (lxml.id (note), "/", "xml:id", "")
				note_text = xml.first (lxml.id (note), "/")
				page_number = structures.references.collected[""][note_ref].references.realpage
				context ("This is ")
				context (note_ref)
				context (". It is typeset on p. ")
				context (page_number)
				context (". Its content is ")
				lxml.flush (lxml.id (note_text))
				context.par ()
			end
			context.stopsubsection ()
		end
	else
		lxml.flush (t)
	end
end
\stopluacode

\setupbodyfont [times,12pt]

\starttext
	\xmlprocessbuffer{main}{test}{}
\stoptext
<chapter>
  <chaptertitle>Chapter 1</chaptertitle>
  <p>This is the <emph>text</emph> of our chapter.<note xml:id="note_1">This is <emph>note</emph> 1.</note> In the first pass, the text will be typeset normally, except for the notes. For the <bold>notes</bold>, we set page references that will be used in the second pass.<note xml:id="note_2">This is <emph>note</emph> 2.</note></p>
</chapter>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to