ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \xmldoifelse false condition
@ 2017-04-14 18:17 Gerard Keiser
  0 siblings, 0 replies; only message in thread
From: Gerard Keiser @ 2017-04-14 18:17 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 2112 bytes --]

I am trying to select specific elements from an XML document to make
anthologies, and still retain the original numbering, by using
\xmldoifelse; if the node matches, it is printed, and if it is not, the
head number is incremented, to get something like this:

    1 First Section (first match)
    4 Fourth Section (second match, but fourth element in the XML file)

 But the fail condition is not being triggered properly. Here are the files:

%
% anthologize.xml
%
\def\incrementheadnumber[#1]{\setupheadnumber[#1]
                        [\numexpr\namedheadnumber{#1}+1\relax]}

\startxmlsetups xml:selectivity:*
  \xmlsetsetup{\xmldocument}{*}{-}
  \xmlsetsetup{\xmldocument}{stuff|div|head}{xml:selectivity:*}
\stopxmlsetups

\xmlregisterdocumentsetup{selectivity}{xml:selectivity:*}

% Here is the difficulty.
\startxmlsetups{xml:selectivity:stuff}
    \xmldoifelse{#1}{/div[match()==1 or match()==4]/all()}
    {
      \xmlflush{#1}
    } {
      \incrementheadnumber[section]
    }
\stopxmlsetups

\startxmlsetups{xml:selectivity:div}
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups{xml:selectivity:head}
  \startsection[title={\xmlflush{#1}}]\stopsection
\stopxmlsetups

\starttext

  \xmlprocessfile{selectivity}{bob.xml}{}

\stoptext

%
% bob.xml
%
<stuff>
  <div>
    <head>First Section</head>
  </div>
  <div>
    <head>Second Section</head>
  </div>
  <div>
    <head>Third Section</head>
  </div>
  <div>
    <head>Fourth Section</head>
  </div>
</stuff>

The result is that only the first and fourth heads are printed, as desired,
but I end up with:

    1 First Section
    2 Fourth Section.

I have used the \incrementheadnumber function elsewhere, and it works fine.
If I replace \incrementheadnumber[section] with \xmlflush{#1}, it prints:

    1 First Section
    2 Fourth Section
    3 First Section
    4 Second Section
    5 Third Section
    6 Fourth Section

So it seems to be properly triggering the true condition, but not the false
condition, and I cannot figure out how to fix it. Using ConTeXt 2017.04.08
and LuaTeX 1.0.3. I do thank you for your help.

Sincerely,
Gerard Keiser

[-- Attachment #1.2: Type: text/html, Size: 3855 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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] only message in thread

only message in thread, other threads:[~2017-04-14 18:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-14 18:17 \xmldoifelse false condition Gerard Keiser

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