ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: denis.maier@unibe.ch, ntg-context@ntg.nl
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: [NTG-context] Re: XML processing beginner's question
Date: Tue, 22 Aug 2023 09:43:22 +0200	[thread overview]
Message-ID: <6f4e3f91-3484-029e-add5-16ad10e7115f@freedom.nl> (raw)
In-Reply-To: <ZRAP278MB04952264B4ED2E3A83CA151A831FA@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM>

On 8/22/2023 8:53 AM, denis.maier@unibe.ch wrote:
>> -----Ursprüngliche Nachricht-----
>> Von: Hans Hagen via ntg-context <ntg-context@ntg.nl>
>> Gesendet: Montag, 21. August 2023 19:09
>>
>> you need a bit of imagination because basically (depends a bit on what you
>> do) one big nested expansion is going on, as Thomas explained: using setups
>> which are basically macros. The #1 is the current node (but you can store it in a
>> macro and use it later if needed). So, only references are passed around.
>>
>> for thomas: we now also have (in lmtx)
>>
>> \ifxml         {id}{pattern}      \else \fi
>> \ifxmltext     {id}{pattern}      \else \fi
>> \ifxmlatt      {id}{name}{value}  \else \fi
>> \ifxmlattempty {id}{pattern}      \else \fi
>> \ifxmlempty    {id}{pattern}      \else \fi
>> \ifxmlselfempty{id}               \else \fi
> 
> So, these new commands diverge from the older patterns:
> \xmldoifelse{#1}{pattern}{TRUE}{FALSE} ?

they can do the same

> Am I reading this correctly?
These are more 'texie' commands avoiding a middle layer. A main 
difference is that in the case of a \if construction one can have 
lookahead issues when a command in a branch has to look forward and pick 
up an argument but that happens seldom in xml (probably never).

\ifxml{#1}{/foo}
   a
\orelse\ifxml{#1}{/ofo}
   b
\orelse\ifxml{#1}{/oof}
   c
\orelse\ifempty{xmlatt{#1}{n}}
   d
% could also be a check for number first:
\orelse\ifnum\xmlattr{#1}{n}>10\relax % of \norelax
   e
\fi

etc (see lowlevel manual) can look a bit less messy that using 5 nested 
\doifelse's but one has to be aware of the number scanner looking ahead 
so ending up in the branch because setups have no spaces at the end of 
lines.

(kind of) think of it like this:

\protected\def\xmldoifelse#1#2%
   {\ifxml{#1}{pattern}%
      \expandafter\firstoftwoareguments
    \else
      \expandafter\secondoftwoareguments
    \fi}

performance wise there is a bit of a difference but i never hear 
complaints so i guess that matters less

so: just two ways of programming a solution

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2023-08-22  7:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 15:29 [NTG-context] " Michael Löscher
2023-08-21 15:45 ` [NTG-context] " Thomas A. Schmitz
2023-08-21 15:59   ` Michael Löscher
2023-08-21 16:19     ` Thomas A. Schmitz
     [not found]       ` <GV2P251MB09935835934E71D701185407DD1EA@GV2P251MB0993.EURP251.PROD.OUTLOOK.COM>
2023-08-21 16:56         ` Thomas A. Schmitz
2023-08-21 17:08           ` Hans Hagen via ntg-context
2023-08-22  6:53             ` denis.maier
2023-08-22  7:43               ` Hans Hagen via ntg-context [this message]
2023-08-22  7:06       ` denis.maier
2023-08-22  7:46         ` Hans Hagen via ntg-context
2023-08-21 19:21     ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f4e3f91-3484-029e-add5-16ad10e7115f@freedom.nl \
    --to=ntg-context@ntg.nl \
    --cc=denis.maier@unibe.ch \
    --cc=j.hagen@freedom.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).