ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Thomas A. Schmitz" <thomas.schmitz@uni-bonn.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Re: xmldoif: checking for contents of attribute
Date: Thu, 24 Aug 2023 16:34:54 +0200	[thread overview]
Message-ID: <3A9BBD7F-6328-44F2-8ADC-339E9605CABE@uni-bonn.de> (raw)
In-Reply-To: <ZRAP278MB0495DE11D6B95B32E5B8FED6831DA@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM>

One way would be to do the search in Lua; when you have multiple searches to perform, that may be the easiest way to go. For example:

\startxmlsetups xml:test
                \xmlsetsetup{#1}{*}{-}
                \xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups
 
\xmlregisterdocumentsetup{test}{xml:test}
 
\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups
 
\startxmlsetups xml:element
	 \xmlfunction {#1} {element}
\stopxmlsetups
 
\startluacode
function xml.functions.element (t)
	 if t.at.class and t.at.class:find ("abc") then
			context.startcolor { "blue" }
			lxml.flush (t)
			context.stopcolor ()
	 else
			context.startcolor { "red" }
			lxml.flush (t)
			context.stopcolor ()
	 end
end
\stopluacode 
 
\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<element class="abcdefg">Yes</element>
<element>No</element>
</doc>
\stopbuffer
 
\starttext
 
\xmlprocessbuffer{test}{test}{}
 
\stoptext

Hope that gets you started.

Thomas

> On 24. Aug 2023, at 16:11, denis.maier@unibe.ch wrote:
> 
> Hi,
>  I’m trying to check whether an attribute contains (or, actually starts with) a given string.
> I’ve tried a whole bunch of different combinations, but I’ve had no luck so far. Minimal example below. Anyone has a hint?
>  Best,
> Denis
>   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \startxmlsetups xml:test
>                 \xmlsetsetup{#1}{*}{-}
>                 \xmlsetsetup{#1}{doc|element}{xml:*} \stopxmlsetups
>  \xmlregisterdocumentsetup{test}{xml:test}
>   \startxmlsetups xml:doc
> \xmlflush{#1}
> \stopxmlsetups
>  \startxmlsetups xml:element
> \xmlfilter{#1}{./find(attribute('class'), 'abc')/command(xml:whatever)}
>  \xmldoifelse{#1}{./attribute('class')/contains('abc')} {Yes}{No}
> \stopxmlsetups
>  \startxmlsetups xml:whatever
> Yes
> \stopxmlsetups
>  \startbuffer[test]
> <?xml version="1.0" encoding="UTF-8"?>
> <doc>
> <element class="abcdefg">Yes</element>
> <element>No</element>
> </doc>
> \stopbuffer
>  \starttext
>  \xmlprocessbuffer{test}{test}{}
>  \stoptext


___________________________________________________________________________________
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-24 14:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 14:11 [NTG-context] " denis.maier
2023-08-24 14:34 ` Thomas A. Schmitz [this message]
2023-08-25  6:25   ` [NTG-context] " denis.maier
2023-08-24 14:54 ` Hans Hagen
2023-08-25  6:22   ` denis.maier
2023-08-25  7:05     ` Hans Hagen
2023-08-25 11:45       ` denis.maier
2023-08-25 12:48         ` 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=3A9BBD7F-6328-44F2-8ADC-339E9605CABE@uni-bonn.de \
    --to=thomas.schmitz@uni-bonn.de \
    --cc=ntg-context@ntg.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).