* [NTG-context] xmldoif: checking for contents of attribute
@ 2023-08-24 14:11 denis.maier
2023-08-24 14:34 ` [NTG-context] " Thomas A. Schmitz
2023-08-24 14:54 ` Hans Hagen
0 siblings, 2 replies; 8+ messages in thread
From: denis.maier @ 2023-08-24 14:11 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 989 bytes --]
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
[-- Attachment #1.2: Type: text/html, Size: 4960 bytes --]
[-- Attachment #2: Type: text/plain, Size: 495 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-24 14:11 [NTG-context] xmldoif: checking for contents of attribute denis.maier
@ 2023-08-24 14:34 ` Thomas A. Schmitz
2023-08-25 6:25 ` denis.maier
2023-08-24 14:54 ` Hans Hagen
1 sibling, 1 reply; 8+ messages in thread
From: Thomas A. Schmitz @ 2023-08-24 14:34 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-24 14:11 [NTG-context] xmldoif: checking for contents of attribute denis.maier
2023-08-24 14:34 ` [NTG-context] " Thomas A. Schmitz
@ 2023-08-24 14:54 ` Hans Hagen
2023-08-25 6:22 ` denis.maier
1 sibling, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2023-08-24 14:54 UTC (permalink / raw)
To: ntg-context
On 8/24/2023 4:11 PM, 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
\xmldoifelse{#1}{.[@class and contains(@class,'abc')]}{Yes}{No}
\xmldoifelse{#1}{.[@class and find(@class,"abc")]}{Yes}{No}
-----------------------------------------------------------------
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-24 14:54 ` Hans Hagen
@ 2023-08-25 6:22 ` denis.maier
2023-08-25 7:05 ` Hans Hagen
0 siblings, 1 reply; 8+ messages in thread
From: denis.maier @ 2023-08-25 6:22 UTC (permalink / raw)
To: ntg-context
> -----Ursprüngliche Nachricht-----
> Von: Hans Hagen <j.hagen@xs4all.nl>
> Gesendet: Donnerstag, 24. August 2023 16:54
> An: ntg-context@ntg.nl
> Betreff: [NTG-context] Re: xmldoif: checking for contents of attribute
>
> On 8/24/2023 4:11 PM, denis.maier@unibe.ch wrote:
> > Hi,
> >
> > I'm trying to check whether an attribute contains (or, actually starts with) a
> given string.
> \xmldoifelse{#1}{.[@class and contains(@class,'abc')]}{Yes}{No}
> \xmldoifelse{#1}{.[@class and find(@class,"abc")]}{Yes}{No}
Thanks for your help. I can use that, but why is this sort of double-checking necessary here?
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups
\xmlregisterdocumentsetup{test}{xml:test}
\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:element
1 \xmldoifelse{#1}{.[@class and contains(@class,'abc')]}{Yes}{No} \par
2 \xmldoifelse{#1}{.[@class and find(@class,"abc")]}{Yes}{No} \par
3 \xmldoifelse{#1}{.[True and contains(@class,'abc')]}{Yes}{No} \par % runs, but no match
4 \xmldoifelse{#1}{.[True and find(@class,"abc")]}{Yes}{No} \par % run, but no match
% 5 \xmldoifelse{#1}{.[contains(@class,'abc')]}{Yes}{No} \par % causes an error
% 6 \xmldoifelse{#1}{.[find(@class,"abc")]}{Yes}{No} \par % causes an error
\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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-24 14:34 ` [NTG-context] " Thomas A. Schmitz
@ 2023-08-25 6:25 ` denis.maier
0 siblings, 0 replies; 8+ messages in thread
From: denis.maier @ 2023-08-25 6:25 UTC (permalink / raw)
To: ntg-context; +Cc: thomas.schmitz
> -----Ursprüngliche Nachricht-----
> Von: Thomas A. Schmitz <thomas.schmitz@uni-bonn.de>
> Gesendet: Donnerstag, 24. August 2023 16:35
> An: mailing list for ConTeXt users <ntg-context@ntg.nl>
> Betreff: [NTG-context] Re: xmldoif: checking for contents of attribute
>
>
> 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:
>
...
>
> Hope that gets you started.
>
> Thomas
Thank you, Thomas. Yes, that get's me started. But same question applies this solution too: Why do you need to double check? (I guess the answer will probably be the same.)
Anyway, it looks like I should really look more into Lua as this will probably make a few things much easier.
Best,
Denis
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-25 6:22 ` denis.maier
@ 2023-08-25 7:05 ` Hans Hagen
2023-08-25 11:45 ` denis.maier
0 siblings, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2023-08-25 7:05 UTC (permalink / raw)
To: denis.maier, mailing list for ConTeXt users
On 8/25/2023 8:22 AM, denis.maier@unibe.ch wrote:
> Thanks for your help. I can use that, but why is this sort of double-checking necessary here?
because containsa in a function that has checking while find is just the
lua find .. so i've added a check in that one too now but no upload
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-25 7:05 ` Hans Hagen
@ 2023-08-25 11:45 ` denis.maier
2023-08-25 12:48 ` Hans Hagen
0 siblings, 1 reply; 8+ messages in thread
From: denis.maier @ 2023-08-25 11:45 UTC (permalink / raw)
To: j.hagen, ntg-context
> -----Ursprüngliche Nachricht-----
> Von: Hans Hagen <j.hagen@xs4all.nl>
> Gesendet: Freitag, 25. August 2023 09:06
> An: Maier, Denis Christian (UB) <denis.maier@unibe.ch>; mailing list for
> ConTeXt users <ntg-context@ntg.nl>
> Betreff: Re: [NTG-context] Re: xmldoif: checking for contents of attribute
>
> On 8/25/2023 8:22 AM, denis.maier@unibe.ch wrote:
>
> > Thanks for your help. I can use that, but why is this sort of double-checking
> necessary here?
>
> because containsa in a function that has checking while find is just the lua find
> .. so i've added a check in that one too now but no upload
>
So, that would mean that the double checking is only necessary for find, not for contains. And indeed the example below works.
Is that correct or are there any unwanted side-effects?
\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups
\xmlregisterdocumentsetup{test}{xml:test}
\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:element
1 \xmldoifelse{#1}{.[contains(@class,'abc')]}{Yes}{No} \par
2 \xmldoifelse{#1}{.[@class and find(@class,'abc')]}{Yes}{No} \par % runs, but no match
\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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* [NTG-context] Re: xmldoif: checking for contents of attribute
2023-08-25 11:45 ` denis.maier
@ 2023-08-25 12:48 ` Hans Hagen
0 siblings, 0 replies; 8+ messages in thread
From: Hans Hagen @ 2023-08-25 12:48 UTC (permalink / raw)
To: denis.maier, mailing list for ConTeXt users
On 8/25/2023 1:45 PM, denis.maier@unibe.ch wrote:
>> -----Ursprüngliche Nachricht-----
>> Von: Hans Hagen <j.hagen@xs4all.nl>
>> Gesendet: Freitag, 25. August 2023 09:06
>> An: Maier, Denis Christian (UB) <denis.maier@unibe.ch>; mailing list for
>> ConTeXt users <ntg-context@ntg.nl>
>> Betreff: Re: [NTG-context] Re: xmldoif: checking for contents of attribute
>>
>> On 8/25/2023 8:22 AM, denis.maier@unibe.ch wrote:
>>
>>> Thanks for your help. I can use that, but why is this sort of double-checking
>> necessary here?
>>
>> because containsa in a function that has checking while find is just the lua find
>> .. so i've added a check in that one too now but no upload
>>
>
> So, that would mean that the double checking is only necessary for find, not for contains. And indeed the example below works.
> Is that correct or are there any unwanted side-effects?
correct and in the next upload i'll also catch the find
-----------------------------------------------------------------
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-25 12:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-24 14:11 [NTG-context] xmldoif: checking for contents of attribute denis.maier
2023-08-24 14:34 ` [NTG-context] " Thomas A. Schmitz
2023-08-25 6:25 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox