* conditional not working in \setuphead
@ 2020-04-20 16:55 Pablo Rodriguez
2020-04-20 17:23 ` Wolfgang Schuster
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Rodriguez @ 2020-04-20 16:55 UTC (permalink / raw)
To: mailing list for ConTeXt users
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?
Many thanks for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: conditional not working in \setuphead
2020-04-20 16:55 conditional not working in \setuphead Pablo Rodriguez
@ 2020-04-20 17:23 ` Wolfgang Schuster
2020-04-20 18:40 ` Pablo Rodriguez
0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Schuster @ 2020-04-20 17:23 UTC (permalink / raw)
To: mailing list for ConTeXt users, Pablo Rodriguez
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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: conditional not working in \setuphead
2020-04-20 17:23 ` Wolfgang Schuster
@ 2020-04-20 18:40 ` Pablo Rodriguez
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Rodriguez @ 2020-04-20 18:40 UTC (permalink / raw)
To: ntg-context
On 4/20/20 7:23 PM, Wolfgang Schuster wrote:
> [...]
> 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
Many thanks for your help, Wolfgang.
Your sample works perfectly fine.
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-20 18:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20 16:55 conditional not working in \setuphead Pablo Rodriguez
2020-04-20 17:23 ` Wolfgang Schuster
2020-04-20 18:40 ` Pablo Rodriguez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).