[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-25 Thread Hans Hagen

On 8/25/2023 1:45 PM, denis.ma...@unibe.ch wrote:

-Ursprüngliche Nachricht-
Von: Hans Hagen 
Gesendet: Freitag, 25. August 2023 09:06
An: Maier, Denis Christian (UB) ; mailing list for
ConTeXt users 
Betreff: Re: [NTG-context] Re: xmldoif: checking for contents of attribute

On 8/25/2023 8:22 AM, denis.ma...@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
___

[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-25 Thread denis.maier
> -Ursprüngliche Nachricht-
> Von: Hans Hagen 
> Gesendet: Freitag, 25. August 2023 09:06
> An: Maier, Denis Christian (UB) ; mailing list for
> ConTeXt users 
> Betreff: Re: [NTG-context] Re: xmldoif: checking for contents of attribute
> 
> On 8/25/2023 8:22 AM, denis.ma...@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]


Yes
No

\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
___


[NTG-context] Re: Question about building an array of values with Lua

2023-08-25 Thread Fabrice Couvreur
Hi Wolfgang,
Thank you so much
Fabrice

Le jeu. 24 août 2023 à 19:46, Wolfgang Schuster <
wolfgang.schuster.li...@gmail.com> a écrit :

> Otared Kavian schrieb am 24.08.2023 um 12:50:
>
>
> On 24 Aug 2023, at 06:03, Wolfgang Schuster <
> wolfgang.schuster.li...@gmail.com> wrote:
>
> […]
>
>
> I would drop the column check in this case.
>
> for i = 0,9 do
> context.startxrow()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(math.mod(i*i,10))
> context.stopxcell()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(math.mod(2*i*i,10))
> context.stopxcell()
> context.stopxrow()
> end
>
> Wolfgang
>
>
> Indeed this is much more elegant… It feels so good to be on this list and
> learn from such insights :-)
>
>
> We don't even need the math.mod function because Lua added with version
> 5.1 a modulo operator,
> the loop to create the row can now be changed to
>
> for i = 0,9 do
> context.startxrow()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(i * i % 10)
> context.stopxcell()
> context.startxcell()
> context(i)
> context.stopxcell()
> context.startxcell()
> context(2 * i * i % 10)
> context.stopxcell()
> context.stopxrow()
> end
>
> Wolfgang
>
>
> ___
> 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
>
> ___
___
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
___

[NTG-context] Re: XML: Correct usage of hash symbol in url

2023-08-25 Thread Hans Hagen via ntg-context

On 8/25/2023 10:16 AM, denis.ma...@unibe.ch wrote:

Hi,

I need to process URLs in XML documents differently depending on the target. 
Thanks to Hans and Thomas I can now deal with the attributes.
Now I need to prefix certain kind of targets with a certain URL (a web viewer 
for IIIF images in this particular case). The prefix contains a #, which, as a 
special character seems to cause an error. Adding a double hash seems to work, 
but those ## will end up in the link URL. How can I properly escape a single #? 
I've already tried using \Ux{23}, but that won't work either.

\#

-
  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
___


[NTG-context] XML: Correct usage of hash symbol in url

2023-08-25 Thread denis.maier
Hi,

I need to process URLs in XML documents differently depending on the target. 
Thanks to Hans and Thomas I can now deal with the attributes.
Now I need to prefix certain kind of targets with a certain URL (a web viewer 
for IIIF images in this particular case). The prefix contains a #, which, as a 
special character seems to cause an error. Adding a double hash seems to work, 
but those ## will end up in the link URL. How can I properly escape a single #? 
I've already tried using \Ux{23}, but that won't work either.

Best,
Denis

\setupinteraction[state=start]

\startxmlsetups xml:test
\xmlsetsetup{#1}{*}{-}
\xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups

\xmlregisterdocumentsetup{test}{xml:test}

\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups

\startluacode
 function xml.finalizers.tex.url(e,a)
 local u = #e > 0 and e[1].at[a]
 local s = u and lpeg.match(lpeg.patterns.urlunescaper,u)
 context(s)
 end
\stopluacode

\startxmlsetups xml:element
\xmldoifelse{#1}{.[@href and contains(@href,'https://iiif.ub.unibe.ch')]}


{\goto{\xmlflush{#1}}[url(https://uv-v4.netlify.app/##?manifest=\xmlatt{#1}{href})]}
 % gives me two hashes in the Link


%{\goto{\xmlflush{#1}}[url(https://uv-v4.netlify.app/#?manifest=\xmlatt{#1}{xlink:href})]}
 \par % does not work

{\goto{\xmlflush{#1}}[url(\xmlatt{#1}{href})]}
\stopxmlsetups


\startbuffer[test]


https://iiif.ub.unibe.ch/presentation/v2.1/berner-inkunabeln/manifest/Inc%20I%20104%20fol%20a1r;>IIIF-Link
https://wiki.contextgarden.net/;>Other Link

\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
___

[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-25 Thread Hans Hagen

On 8/25/2023 8:22 AM, denis.ma...@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
___


[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-25 Thread denis.maier
> -Ursprüngliche Nachricht-
> Von: Thomas A. Schmitz 
> Gesendet: Donnerstag, 24. August 2023 16:35
> An: mailing list for ConTeXt users 
> 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
___


[NTG-context] Re: xmldoif: checking for contents of attribute

2023-08-25 Thread denis.maier
> -Ursprüngliche Nachricht-
> Von: Hans Hagen 
> 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.ma...@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]


Yes
No

\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
___