[NTG-context] conditional not working in \setuphead
Wolfgang Schuster
wolfgang.schuster.lists at gmail.com
Mon Apr 20 19:23:48 CEST 2020
Pablo Rodriguez schrieb am 20.04.2020 um 18:55:
> Dear list,
>
> I have the following sample:
>
> \startbuffer[demo]
> <doc>
> <section id="section-i1">
> <text>first</text>
> </section>
> <section id="section-i2">
> <text>second</text>
> </section>
>
> </doc>
> \stopbuffer
>
> \startxmlsetups xml:initialize
> \xmlsetsetup{#1}{doc|section}{xml:*}
> \stopxmlsetups
>
> \xmlregistersetup{xml:initialize}
>
> \startxmlsetups xml:doc
> \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:section
> \startsection[title={\xmlatt{#1}{id}},
> beforesection={\doif{\xmlatt{#1}{id}}{\selectedtopic}
> {conditional}}]
> \xmlflush{#1}
> \doif{\xmlatt{#1}{id}}{\selectedtopic}{conditional}
> \stopsection
> \stopxmlsetups
>
> \def\selectedtopic{section-i1}
>
> \starttext
> \xmlprocessbuffer{main}{demo}{}
> \stoptext
>
> How can I make the conditional in the beforesection option work?
The argument of the beforesection-key is placed before ConTeXt stores
the values of \startsection which means you can do it this way.
What you can do here is to put whatever something in a macro before you
call \startsection and access the value of this macro with the
beforesection-key. You should ensure the content if this temporary macro
is cleared when your conditional is false.
\setuphead
[section]
[beforesection=\getvariable{xml}{beforesection}]
\startxmlsetups xml:section
\doifelse{\xmlatt{#1}{id}}{\selectedtopic}
{\setvariable{xml}{beforesection}{conditional}}
{\setvariable{xml}{beforesection}{}}
\startsection[title={\xmlatt{#1}{id}}]
\xmlflush{#1}
\stopsection
\stopxmlsetups
Wolfgang
More information about the ntg-context
mailing list