ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] XML processing beginner's question
@ 2023-08-21 15:29 Michael Löscher
  2023-08-21 15:45 ` [NTG-context] " Thomas A. Schmitz
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Löscher @ 2023-08-21 15:29 UTC (permalink / raw)
  To: ntg-context

Hello list,

having the xml data at the bottom, I would like to process it so that 
the result is like this:

---
What it is (e.g. bold formatted)
date: 2023-08-01 (italic)
Description (small font size)
Another text (small font size)

hd1 - Header 1

§ 1 First  (A first short description)
AAAAAAAAAA
BBBBBBBBBB

§ 2 Second (A second short description)
CCCCCCCCCC
DDDDDDDDDD

§ 3 Third (A third short description)
EEEEEEEEEE
FFFFFFFFFF
---

How can I process the <element>s differently? The first element contains 
a <date> tag and so it differs from the other ones. The second element's 
<name> tag contains the word "Header" which makes it different again. 
The other elements contain a <shortdescription> tag that they all have 
in common.

What could be the appropriate xml setups to generate the above output?

Michael

---
xml data:
\startbuffer[xmlcontent]
<?xml version="1.0" encoding="UTF-8" ?>
<document>
   <element>
     <mdata>
       <name>What it is</name>
       <date>2023-08-01</date>
     </mdata>
     <tdata>
       <content>
         <p>Description</p>
         <p>Another text</p>
       </content>
     </tdata>
   </element>
   <element>
     <mdata>
       <num>hd1</num>
       <name>Header 1</name>
     </mdata>
     <tdata>
       <content>
         <p>Text of Header 1</p>
       </content>
     </tdata>
   </element>
   <element>
     <mdata>
       <num>1</num>
       <name>First</name>
       <shortdescription>A first short description</shortdescription>
     </mdata>
     <tdata>
       <content>
         <p>AAAAAAAAAA</p>
         <p>BBBBBBBBBB</p>
       </content>
     </tdata>
   </element>
   <element>
     <mdata>
       <num>2</num>
       <name>Second</name>
       <shortdescription>A second short description</shortdescription>
     </mdata>
     <tdata>
       <content>
         <p>CCCCCCCCCC</p>
         <p>DDDDDDDDDD</p>
       </content>
     </tdata>
   </element>
   <element>
     <mdata>
       <num>3</num>
       <name>Third</name>
       <shortdescription>A third short description</shortdescription>
     </mdata>
     <tdata>
       <content>
         <p>EEEEEEEEEE</p>
         <p>FFFFFFFFFF</p>
       </content>
     </tdata>
   </element>
</document>
\stopbuffer

___________________________________________________________________________________
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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  2023-08-21 15:29 [NTG-context] XML processing beginner's question Michael Löscher
@ 2023-08-21 15:45 ` Thomas A. Schmitz
  2023-08-21 15:59   ` Michael Löscher
  0 siblings, 1 reply; 11+ messages in thread
From: Thomas A. Schmitz @ 2023-08-21 15:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Have you looked at chapter 3.10 "Testing" of the manual xml-mkiv.pdf? 
There are a lot of commands there that should help you, such as

\xmldoiftext {#1} {/mdata/date}
  {\bf \xmlflush {#1}}

or \xmldoifelsetext.

There's also \xmlfilter, which you can use to test for the content of 
tags. And of course, you can process in Lua and search for strings or 
use lpeg. However, your question is a bit vague now. Show us some code 
you have and we can take it from there; that's easier than writing the 
whole setup for you.

Thomas


On 8/21/23 17:29, Michael Löscher wrote:
> Hello list,
> 
> having the xml data at the bottom, I would like to process it so that 
> the result is like this:
> 
> ---
> What it is (e.g. bold formatted)
> date: 2023-08-01 (italic)
> Description (small font size)
> Another text (small font size)
> 
> hd1 - Header 1
> 
> § 1 First  (A first short description)
> AAAAAAAAAA
> BBBBBBBBBB
> 
> § 2 Second (A second short description)
> CCCCCCCCCC
> DDDDDDDDDD
> 
> § 3 Third (A third short description)
> EEEEEEEEEE
> FFFFFFFFFF
> ---
> 
> How can I process the <element>s differently? The first element contains 
> a <date> tag and so it differs from the other ones. The second element's 
> <name> tag contains the word "Header" which makes it different again. 
> The other elements contain a <shortdescription> tag that they all have 
> in common.
> 
> What could be the appropriate xml setups to generate the above output?
> 
> Michael
> 
> ---
> xml data:
> \startbuffer[xmlcontent]
> <?xml version="1.0" encoding="UTF-8" ?>
> <document>
>    <element>
>      <mdata>
>        <name>What it is</name>
>        <date>2023-08-01</date>
>      </mdata>
>      <tdata>
>        <content>
>          <p>Description</p>
>          <p>Another text</p>
>        </content>
>      </tdata>
>    </element>
>    <element>
>      <mdata>
>        <num>hd1</num>
>        <name>Header 1</name>
>      </mdata>
>      <tdata>
>        <content>
>          <p>Text of Header 1</p>
>        </content>
>      </tdata>
>    </element>
>    <element>
>      <mdata>
>        <num>1</num>
>        <name>First</name>
>        <shortdescription>A first short description</shortdescription>
>      </mdata>
>      <tdata>
>        <content>
>          <p>AAAAAAAAAA</p>
>          <p>BBBBBBBBBB</p>
>        </content>
>      </tdata>
>    </element>
>    <element>
>      <mdata>
>        <num>2</num>
>        <name>Second</name>
>        <shortdescription>A second short description</shortdescription>
>      </mdata>
>      <tdata>
>        <content>
>          <p>CCCCCCCCCC</p>
>          <p>DDDDDDDDDD</p>
>        </content>
>      </tdata>
>    </element>
>    <element>
>      <mdata>
>        <num>3</num>
>        <name>Third</name>
>        <shortdescription>A third short description</shortdescription>
>      </mdata>
>      <tdata>
>        <content>
>          <p>EEEEEEEEEE</p>
>          <p>FFFFFFFFFF</p>
>        </content>
>      </tdata>
>    </element>
> </document>
> \stopbuffer
> 

___________________________________________________________________________________
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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  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
  2023-08-21 19:21     ` Hans Hagen
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Löscher @ 2023-08-21 15:59 UTC (permalink / raw)
  To: ntg-context

Yes, I have done that. But I don't seem to have the basic context of how 
the processing works in order. All I have so far is this as a starting 
point:

\startxmlsetups xml:mysetup
 
\xmlsetsetup{main}{document|element|mdata|tdata|name|date|num|content|shortdescription|p}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetup}

\startxmlsetups xml:mysetup:document
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:element
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:mdata
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:tdata
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:name
\xmlflush
\stopxmlsetups

\startxmlsetups xml:mysetup:num
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:content
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:shortdescription
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:mysetup:p
\xmlflush{#1}\par
\stopxmlsetups

\starttext
   \xmlprocessbuffer {mysetup}{xmlcontent}{}
\stoptext

Am 21.08.2023 um 17:45 schrieb Thomas A. Schmitz:
> Have you looked at chapter 3.10 "Testing" of the manual xml-mkiv.pdf? 
> There are a lot of commands there that should help you, such as
> 
> \xmldoiftext {#1} {/mdata/date}
>   {\bf \xmlflush {#1}}
> 
> or \xmldoifelsetext.
> 
> There's also \xmlfilter, which you can use to test for the content of 
> tags. And of course, you can process in Lua and search for strings or 
> use lpeg. However, your question is a bit vague now. Show us some code 
> you have and we can take it from there; that's easier than writing the 
> whole setup for you.
> 
> Thomas
> 
> 
> On 8/21/23 17:29, Michael Löscher wrote:
>> Hello list,
>>
>> having the xml data at the bottom, I would like to process it so that 
>> the result is like this:
>>
>> ---
>> What it is (e.g. bold formatted)
>> date: 2023-08-01 (italic)
>> Description (small font size)
>> Another text (small font size)
>>
>> hd1 - Header 1
>>
>> § 1 First  (A first short description)
>> AAAAAAAAAA
>> BBBBBBBBBB
>>
>> § 2 Second (A second short description)
>> CCCCCCCCCC
>> DDDDDDDDDD
>>
>> § 3 Third (A third short description)
>> EEEEEEEEEE
>> FFFFFFFFFF
>> ---
>>
>> How can I process the <element>s differently? The first element 
>> contains a <date> tag and so it differs from the other ones. The 
>> second element's <name> tag contains the word "Header" which makes it 
>> different again. The other elements contain a <shortdescription> tag 
>> that they all have in common.
>>
>> What could be the appropriate xml setups to generate the above output?
>>
>> Michael
>>
>> ---
>> xml data:
>> \startbuffer[xmlcontent]
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <document>
>>    <element>
>>      <mdata>
>>        <name>What it is</name>
>>        <date>2023-08-01</date>
>>      </mdata>
>>      <tdata>
>>        <content>
>>          <p>Description</p>
>>          <p>Another text</p>
>>        </content>
>>      </tdata>
>>    </element>
>>    <element>
>>      <mdata>
>>        <num>hd1</num>
>>        <name>Header 1</name>
>>      </mdata>
>>      <tdata>
>>        <content>
>>          <p>Text of Header 1</p>
>>        </content>
>>      </tdata>
>>    </element>
>>    <element>
>>      <mdata>
>>        <num>1</num>
>>        <name>First</name>
>>        <shortdescription>A first short description</shortdescription>
>>      </mdata>
>>      <tdata>
>>        <content>
>>          <p>AAAAAAAAAA</p>
>>          <p>BBBBBBBBBB</p>
>>        </content>
>>      </tdata>
>>    </element>
>>    <element>
>>      <mdata>
>>        <num>2</num>
>>        <name>Second</name>
>>        <shortdescription>A second short description</shortdescription>
>>      </mdata>
>>      <tdata>
>>        <content>
>>          <p>CCCCCCCCCC</p>
>>          <p>DDDDDDDDDD</p>
>>        </content>
>>      </tdata>
>>    </element>
>>    <element>
>>      <mdata>
>>        <num>3</num>
>>        <name>Third</name>
>>        <shortdescription>A third short description</shortdescription>
>>      </mdata>
>>      <tdata>
>>        <content>
>>          <p>EEEEEEEEEE</p>
>>          <p>FFFFFFFFFF</p>
>>        </content>
>>      </tdata>
>>    </element>
>> </document>
>> \stopbuffer
>>
> 
> ___________________________________________________________________________________
> 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  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-22  7:06       ` denis.maier
  2023-08-21 19:21     ` Hans Hagen
  1 sibling, 2 replies; 11+ messages in thread
From: Thomas A. Schmitz @ 2023-08-21 16:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 8/21/23 17:59, Michael Löscher wrote:
> Yes, I have done that. But I don't seem to have the basic context of how 
> the processing works in order. All I have so far is this as a starting 
> point:
> 
Really? I told you about the various commands \xmldoif, but there's 
nothing in your starting point. I don't want to provide anybody homework 
solutions, so just to give you an idea to get you started:

\startxmlsetups xml:mysetup
\xmlsetsetup{main}{document|element|mdata|tdata|name|date|num|content|shortdescription|p}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetup}

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

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

\startxmlsetups xml:mdata
	\xmldoifelsetext {#1} {/date}
		{{\bf \xmltext {#1} {name}}\par
		{\it \xmltext {#1} {date}}\par}
		{\xmltext {#1} {content}\par}
\stopxmlsetups

This will process the name in bold and the date in italic. But I'm sure 
you can do better after reading and digesting the chapter I referred to.

Thomas

___________________________________________________________________________________
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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
       [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
  0 siblings, 1 reply; 11+ messages in thread
From: Thomas A. Schmitz @ 2023-08-21 16:56 UTC (permalink / raw)
  To: ntg-context

On 8/21/23 18:36, Michael Löscher wrote:
> Thank you so far. But what I would like to understand first ist how the 
> different setups work togehter. How are they processed? What is the 
> order of processing, which are the stets taken by the enginge when 
> processing an xml document? Without understanding how that works, it is 
> not possible to apply certain tests on the xml nodes.
> 
As the manual mk.pdf, chapter XVII states: it's a mixture of streaming 
parser and tree manipulation. The whole xml document is transformed into 
a Lua table and then processed. But I definitely get the "do my homework 
for me" vibe, so this will be all from me.

Thomas

___________________________________________________________________________________
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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2023-08-21 17:08 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

On 8/21/2023 6:56 PM, Thomas A. Schmitz wrote:
> On 8/21/23 18:36, Michael Löscher wrote:
>> Thank you so far. But what I would like to understand first ist how 
>> the different setups work togehter. How are they processed? What is 
>> the order of processing, which are the stets taken by the enginge when 
>> processing an xml document? Without understanding how that works, it 
>> is not possible to apply certain tests on the xml nodes.
>>
> As the manual mk.pdf, chapter XVII states: it's a mixture of streaming 
> parser and tree manipulation. The whole xml document is transformed into 
> a Lua table and then processed. But I definitely get the "do my homework 
> for me" vibe, so this will be all from me.
in addition:

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

which in some cases is more efficient

there is also \xmllastatt etc which can be used after a test which 
avoids a second lookup

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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  2023-08-21 15:59   ` Michael Löscher
  2023-08-21 16:19     ` Thomas A. Schmitz
@ 2023-08-21 19:21     ` Hans Hagen
  1 sibling, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2023-08-21 19:21 UTC (permalink / raw)
  To: ntg-context

On 8/21/2023 5:59 PM, Michael Löscher wrote:
> Yes, I have done that. But I don't seem to have the basic context of how 
> the processing works in order. All I have so far is this as a starting 
> point:
you can also find examples in the test suite (xml subpath)


-----------------------------------------------------------------
                                           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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  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
  0 siblings, 1 reply; 11+ messages in thread
From: denis.maier @ 2023-08-22  6:53 UTC (permalink / raw)
  To: ntg-context

> -----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} ?

Am I reading this correctly?

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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  2023-08-21 16:19     ` Thomas A. Schmitz
       [not found]       ` <GV2P251MB09935835934E71D701185407DD1EA@GV2P251MB0993.EURP251.PROD.OUTLOOK.COM>
@ 2023-08-22  7:06       ` denis.maier
  2023-08-22  7:46         ` Hans Hagen via ntg-context
  1 sibling, 1 reply; 11+ messages in thread
From: denis.maier @ 2023-08-22  7:06 UTC (permalink / raw)
  To: ntg-context

> -----Ursprüngliche Nachricht-----
> Von: Thomas A. Schmitz <thomas.schmitz@uni-bonn.de>
> Gesendet: Montag, 21. August 2023 18:20
> An: mailing list for ConTeXt users <ntg-context@ntg.nl>
> Betreff: [NTG-context] Re: XML processing beginner's question
> 
> On 8/21/23 17:59, Michael Löscher wrote:
> > Yes, I have done that. But I don't seem to have the basic context of
> > how the processing works in order. All I have so far is this as a
> > starting
> > point:
> >
> Really? I told you about the various commands \xmldoif, but there's nothing in
> your starting point. I don't want to provide anybody homework solutions, so
> just to give you an idea to get you started:
> 
> \startxmlsetups xml:mysetup
> \xmlsetsetup{main}{document|element|mdata|tdata|name|date|num|con
> tent|shortdescription|p}{xml:*}
> \stopxmlsetups
> 
> \xmlregistersetup{xml:mysetup}
> 
> \startxmlsetups xml:document
> 	\xmlflush {#1}
> \stopxmlsetups
> 
> \startxmlsetups xml:element
> 	\xmlflush {#1}
> \stopxmlsetups
> 
> \startxmlsetups xml:mdata
> 	\xmldoifelsetext {#1} {/date}
> 		{{\bf \xmltext {#1} {name}}\par
> 		{\it \xmltext {#1} {date}}\par}
> 		{\xmltext {#1} {content}\par}
> \stopxmlsetups
> 

Just to add to this: You can also apply a more XSLT-like approach, like test directly when matching:

\startxmlsetups xml:mysetup
\xmlsetsetup{main}{document}{xml:*}
\xmlsetsetup{main}{element[@class="myclass"]}{xml:element-with-attribute}
\xmlsetsetup{main}{element[./subelement-one]}{xml:element-with-subelement-one}
\xmlsetsetup{main}{element[./subelement-two]}{xml:element-with-subelement-two}
\stopxmlsetups

\xmlregistersetup{xml:mysetup}

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

\startxmlsetups xml:element-with-attribute
 	0
\stopxmlsetups

\startxmlsetups element-with-subelement-one
 	1
\stopxmlsetups

\startxmlsetups element-with-subelement-two
 	2
\stopxmlsetups


But, I think the way this is processed differs a bit from XSLT. In XSLT the most specific match will be applied, but ConTeXt seems to proceed from top to bottom until it finds a match. (Is that correct?)

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] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  2023-08-22  6:53             ` denis.maier
@ 2023-08-22  7:43               ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2023-08-22  7:43 UTC (permalink / raw)
  To: denis.maier, ntg-context; +Cc: Hans Hagen

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: XML processing beginner's question
  2023-08-22  7:06       ` denis.maier
@ 2023-08-22  7:46         ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2023-08-22  7:46 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

On 8/22/2023 9:06 AM, denis.maier@unibe.ch wrote:

> But, I think the way this is processed differs a bit from XSLT. In XSLT the most specific match will be applied, but ConTeXt seems to proceed from top to bottom until it finds a match. (Is that correct?)
it just associates the most recent match with a setup . if needed we 
could extend the mechanism with varianst but i have to admit that it has 
been stable (mostly untouched) for close to 15 years now so all has to 
be done very careful; it has also be tuned for performance and large 
scale throughput

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] 11+ messages in thread

end of thread, other threads:[~2023-08-22  7:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21 15:29 [NTG-context] XML processing beginner's question 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
2023-08-22  7:06       ` denis.maier
2023-08-22  7:46         ` Hans Hagen via ntg-context
2023-08-21 19:21     ` Hans Hagen

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