Ok, after a bit of more testing I can now come up with another example.
The version using startstop works, but with the normal command, I’m always getting back the content of the first element.
I thought it might be an expansion issue, but \expanded and also expansion=yes or expansion=xml on \definedescription have no effect. Perhaps most interestingly, adding using the startstop variant together with the command variant gives correct
results for the command as well (xml:index-entry-term-3).
I have now found a way to proceed with my project (I’ll just use the startstop variant), but I’d still be interested in understanding what is happening here.
Does anyone know? Or is there anything I’m doing wrong here?
Best,
Denis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{index}{xml:*}
\xmlsetsetup{#1}{index-entry}{xml:index-entry}
%\xmlsetsetup{#1}{term}{xml:index-entry-term}
\xmlsetsetup{#1}{term}{xml:index-entry-term-2}
\xmlsetsetup{#1}{term}{xml:index-entry-term-3}
\stopxmlsetups
\xmlregisterdocumentsetup{test}{xml:test}
% Index
\startxmlsetups xml:book-back
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index
\xmlflush{#1}
\stopxmlsetups
\definedescription[indexentry][]
%\definedescription[indexentry][expansion=yes] % has no effect
%\definedescription[indexentry][expansion=xml] % has no effect
\startxmlsetups xml:index-entry
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index-entry-term % does not work
\expanded{\indexentry{\xmlflush{#1}}}
\indexentry{\xmlflush{#1}}
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index-entry-term-2 % works
\startindexentry{\xmlflush{#1}}
\xmlflush{#1}
\stopindexentry
\stopxmlsetups
\startxmlsetups xml:index-entry-term-3 % works
\expanded{\indexentry{\xmlflush{#1}}}
\indexentry{\xmlflush{#1}}
\startindexentry{\xmlflush{#1}}
\xmlflush{#1}
\stopindexentry
\stopxmlsetups
\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<index>
<index-entry>
<term>One</term>
</index-entry>
<index-entry>
<term>Two</term>
</index-entry>
<index-entry>
<term>Three</term>
</index-entry>
</index>
\stopbuffer
\starttext
\xmlprocessbuffer{test}{test}{}
\stoptext
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Von: denis.maier@unibe.ch <denis.maier@unibe.ch>
Gesendet: Montag, 24. Juli 2023 15:57
An: ntg-context@ntg.nl
Betreff: [NTG-context] Re: xml: matches always child of other element
Interestingly, we should be in the right subtree as this modified example is supposed to demonstrate (we’re getting the correct numbers under each index-entry-term, just the terms are incorrect in all but the first case):
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{index}{xml:*}
\xmlsetsetup{#1}{index-entry}{xml:index-entry}
%\xmlsetsetup{#1}{index-entry}{xml:index-entry-2}
\xmlsetsetup{#1}{term}{xml:index-entry-term}
\xmlsetsetup{#1}{nav-pointer-group}{xml:*}
\xmlsetsetup{#1}{nav-pointer}{xml:nav-pointer}
\xmlsetsetup{#1}{nav-pointer/ext-link}{xml:nav-pointer-link}
\stopxmlsetups
\xmlregisterdocumentsetup{test}{xml:test}
% Index
\startxmlsetups xml:book-back
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index
\startsectionlevel[title={\xmlfilter{#1}{/index-title-group/title/command(xml:index-title)}},]
\xmlflush{#1}
\stopsectionlevel
\stopxmlsetups
\startxmlsetups xml:index-title
\xmlflush{#1}
\stopxmlsetups
\definedescription[indexentry]
[alternative=top,
headstyle=normal,
headcommand=\hskip-1cm,
margin=1cm,
inbetween=,
]
\startxmlsetups xml:index-entry
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index-entry-2
\xmlfilter{#1}{/term/command(xml:index-entry-term)}%
\xmlverbatim{#1}
\stopxmlsetups
\startxmlsetups xml:index-entry-term
\indexentry{\xmlflush{#1}}
\stopxmlsetups
\startxmlsetups xml:nav-pointer-group
\xmlconcat{#1}{/nav-pointer}{, }
\stopxmlsetups
\startxmlsetups xml:nav-pointer
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:nav-pointer-link
\xmlflush{#1}
\stopxmlsetups
\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<index>
<index-title-group>
<title>Index</title>
</index-title-group>
<index-entry>
<term>First</term>
<nav-pointer-group>
<nav-pointer>
<ext-link>1</ext-link>
</nav-pointer>
<nav-pointer>
<ext-link>2</ext-link>
</nav-pointer>
<nav-pointer>
<ext-link>3</ext-link>
</nav-pointer>
</nav-pointer-group>
</index-entry>
<index-entry>
<term>Second</term>
<nav-pointer-group>
<nav-pointer>
<ext-link>4</ext-link>
</nav-pointer>
</nav-pointer-group>
</index-entry>
<index-entry>
<term>Third</term>
<nav-pointer-group>
<nav-pointer>
<ext-link>5</ext-link>
</nav-pointer>
<nav-pointer>
<ext-link>6</ext-link>
</nav-pointer>
<nav-pointer>
<ext-link>7</ext-link>
</nav-pointer>
</nav-pointer-group>
</index-entry>
</index>
\stopbuffer
\starttext
\xmlprocessbuffer{test}{test}{}
\stoptext
Von:
denis.maier@unibe.ch <denis.maier@unibe.ch>
Gesendet: Montag, 24. Juli 2023 13:38
An: ntg-context@ntg.nl
Betreff: [NTG-context] xml: matches always child of other element
Hi,
I must be missing something obvious, but in this example the pattern for <term> always matches the first element, not the one under the current <index-entry>.
Interestingly, using xml:index-entry-2 instead of the normal version matches correctly… Any hints what is going off the rails here?
Best,
Denis
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{index}{xml:*}
\xmlsetsetup{#1}{index-entry}{xml:index-entry}
%\xmlsetsetup{#1}{index-entry}{xml:index-entry-2}
\xmlsetsetup{#1}{term}{xml:index-entry-term}
\xmlsetsetup{#1}{nav-pointer-group}{xml:*}
\xmlsetsetup{#1}{nav-pointer}{xml:nav-pointer}
\xmlsetsetup{#1}{nav-pointer/ext-link}{xml:nav-pointer-link}
\stopxmlsetups
\xmlregisterdocumentsetup{test}{xml:test}
% Index
\startxmlsetups xml:book-back
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index
\startsectionlevel[title={\xmlfilter{#1}{/index-title-group/title/command(xml:index-title)}},]
\xmlflush{#1}
\stopsectionlevel
\stopxmlsetups
\startxmlsetups xml:index-title
\xmlflush{#1}
\stopxmlsetups
\definedescription[indexentry]
[alternative=top,
headstyle=normal,
headcommand=\hskip-1cm,
margin=1cm,
inbetween=,
]
\startxmlsetups xml:index-entry
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:index-entry-2
\xmlfilter{#1}{/term/command(xml:index-entry-term)}%
\xmlverbatim{#1}
\stopxmlsetups
\startxmlsetups xml:index-entry-term
\indexentry{\xmlflush{#1}}
\stopxmlsetups
\startxmlsetups xml:nav-pointer-group
\xmlconcat{#1}{/nav-pointer}{, }
\stopxmlsetups
\startxmlsetups xml:nav-pointer
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:nav-pointer-link
\xmlflush{#1}
\stopxmlsetups
\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<index>
<index-title-group>
<title>Index</title>
</index-title-group>
<index-entry>
<term>First</term>
<nav-pointer-group>
<nav-pointer>
<ext-link>1</ext-link>
</nav-pointer>
<nav-pointer>
<ext-link>2</ext-link>
</nav-pointer>
<nav-pointer>
<ext-link>3</ext-link>
</nav-pointer>
</nav-pointer-group>
</index-entry>
<index-entry>
<term>Second</term>
<nav-pointer-group>
<nav-pointer>
<ext-link>1</ext-link>
</nav-pointer>
</nav-pointer-group>
</index-entry>
<index-entry>
<term>Third</term>
<nav-pointer-group>
<nav-pointer>
<ext-link>1</ext-link>
</nav-pointer>
</nav-pointer-group>
</index-entry>
</index>
\stopbuffer
\starttext
\xmlprocessbuffer{test}{test}{}
\stoptext