* issue with lpath
@ 2022-08-02 19:14 Pablo Rodriguez via ntg-context
2022-08-03 7:09 ` Taco Hoekwater via ntg-context
0 siblings, 1 reply; 9+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2022-08-02 19:14 UTC (permalink / raw)
To: ConTeXt users; +Cc: Pablo Rodriguez
Dear list,
I have this sample:
\startbuffer[demo]
<xml>
<div class="section level3">
<h3>One</h3>
<p>Standard paragraph</p>
<blockquote>
<p>Quoted text</p>
</blockquote>
</div>
<div class="section level3">
<h3>Two</h3>
<blockquote>
<p>Direct quote</p>
</blockquote>
</div>
</xml>
\stopbuffer
\startxmlsetups xml:initialize
\xmlsetsetup{#1}
{p|blockquote}
{xml:*}
\xmlsetsetup{#1}
{(div|section)[contains(@class,'level3')]/h3/../!p/../h3}
{xml:section}
\stopxmlsetups
\xmlregistersetup{xml:initialize}
\startxmlsetups xml:p
\startpar\xmlflush{#1}\stoppar
\stopxmlsetups
\startxmlsetups xml:blockquote
\startblockquote\xmlflush{#1}\stopblockquote
\stopxmlsetups
\startxmlsetups xml:section
\section{\xmlflush{#1}}
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{demo}{}
\stoptext
I need an lpath to select the h3 node above, but only the one with "h3 +
blockquote" as a CSS selector (which could be added the lpath "../h3"
after).
It would be "<h3>Two</h3>" and not "<h3>Two</h3>" in this sample.
Excuse my ignorance, but which is the way to achieve this?
Many thanks for your help,
Pablo
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-02 19:14 issue with lpath Pablo Rodriguez via ntg-context
@ 2022-08-03 7:09 ` Taco Hoekwater via ntg-context
2022-08-03 13:54 ` Pablo Rodriguez via ntg-context
0 siblings, 1 reply; 9+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-08-03 7:09 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Taco Hoekwater, Pablo Rodriguez
> On 2 Aug 2022, at 21:14, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>
> Dear list,
>
>
> I need an lpath to select the h3 node above, but only the one with "h3 +
> blockquote" as a CSS selector (which could be added the lpath "../h3"
> after).
Lpath supports CSS selectors between curly braces as parts, so simply:
\xmlsetsetup{#1}{{h3 + blockquote}/../h3} {xml:section}
should do. The xml-mkiv.pdf manual has lots of other lpath examples as well.
Best wishes,
Taco
—
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-03 7:09 ` Taco Hoekwater via ntg-context
@ 2022-08-03 13:54 ` Pablo Rodriguez via ntg-context
2022-08-04 10:22 ` Taco Hoekwater via ntg-context
0 siblings, 1 reply; 9+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2022-08-03 13:54 UTC (permalink / raw)
To: Taco Hoekwater via ntg-context; +Cc: Pablo Rodriguez
On 8/3/22 09:09, Taco Hoekwater via ntg-context wrote:
>> On 2 Aug 2022, at 21:14, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>> [...]
>> I need an lpath to select the h3 node above, but only the one with "h3 +
>> blockquote" as a CSS selector (which could be added the lpath "../h3"
>> after).
>
> Lpath supports CSS selectors between curly braces as parts, so simply:
>
> \xmlsetsetup{#1}{{h3 + blockquote}/../h3} {xml:section}
Taco,
I knew that, but I wasn’t sure how to mix both. I’d say yesterday I
tried something similar to:
\xmlsetsetup{#1}{{h3 + blockquote}../h3} {xml:section}
Which, of course, couldn’t work.
> The xml-mkiv.pdf manual has lots of other lpath examples as well.
I know, I have read them many times. And I read them from time to time.
But I’m not smart enough to understand them.
BTW, is there any way to rephrase "{h3 + blockquote}" in proper Lua?
Something like "/h3/../!p/../blockquote" selected both "h3 + p" (which I
didn’t want and "h3 + blockquote" (the one intended).
Many thanks for your help,
Pablo
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-03 13:54 ` Pablo Rodriguez via ntg-context
@ 2022-08-04 10:22 ` Taco Hoekwater via ntg-context
2022-08-04 14:07 ` Hans Hagen via ntg-context
2022-08-04 15:15 ` Pablo Rodriguez via ntg-context
0 siblings, 2 replies; 9+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-08-04 10:22 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Taco Hoekwater, Pablo Rodriguez
> On 3 Aug 2022, at 15:54, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>
> BTW, is there any way to rephrase "{h3 + blockquote}" in proper Lua?
I was wondering about that as well, and I really had no clue how to do that. Some
reading and studying later, I realised that there is a preceding-sibling:: axis.
That is not documented in xml-mkiv.pdf I think, but it inherited from xpath, and that means this works:
\xmlsetsetup{#1}{blockquote/preceding-sibling::h3[-1]/} {xml:section}
“Take all blockquotes, then tests their immediate preceding siblings (index [-1]) that are h3."
But the CSS version is nicer. Still, both solutions fail on generic input.
Sorry, out of clues
Best wishes,Taco
—
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-04 10:22 ` Taco Hoekwater via ntg-context
@ 2022-08-04 14:07 ` Hans Hagen via ntg-context
2022-08-04 15:32 ` Taco Hoekwater via ntg-context
2022-08-04 15:15 ` Pablo Rodriguez via ntg-context
1 sibling, 1 reply; 9+ messages in thread
From: Hans Hagen via ntg-context @ 2022-08-04 14:07 UTC (permalink / raw)
To: mailing list for ConTeXt users
Cc: Hans Hagen, Pablo Rodriguez, Taco Hoekwater
On 8/4/2022 12:22 PM, Taco Hoekwater via ntg-context wrote:
>
>
>> On 3 Aug 2022, at 15:54, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>>
>> BTW, is there any way to rephrase "{h3 + blockquote}" in proper Lua?
>
>
> I was wondering about that as well, and I really had no clue how to do that. Some
> reading and studying later, I realised that there is a preceding-sibling:: axis.
>
> That is not documented in xml-mkiv.pdf I think, but it inherited from xpath, and that means this works:
>
> \xmlsetsetup{#1}{blockquote/preceding-sibling::h3[-1]/} {xml:section}
>
> “Take all blockquotes, then tests their immediate preceding siblings (index [-1]) that are h3."
>
> But the CSS version is nicer. Still, both solutions fail on generic input.
>
> Sorry, out of clues
\startbuffer[demo]
<xml>
<div class="section level3">
<h3>One</h3>
<p>Standard paragraph</p>
<blockquote>
<p>Quoted text</p>
</blockquote>
</div>
<div class="section level3">
<h3>Two</h3>
<blockquote>
<p>Direct quote</p>
</blockquote>
</div>
</xml>
\stopbuffer
\startxmlsetups xml:initialize
\xmlsetsetup{#1}
{xml|p|blockquote|div}
{xml:*}
\xmlsetsetup{#1}
{/xml/div[contains(@class,'level3')]}
{xml:section:level3}
\stopxmlsetups
\xmlregistersetup{xml:initialize}
\startxmlsetups xml:xml
\xmlall{#1}{/div}
\stopxmlsetups
\startxmlsetups xml:p
\startpar\xmlflush{#1}\stoppar
\stopxmlsetups
\startxmlsetups xml:blockquote
\startblockquote\xmlflush{#1}\stopblockquote
\stopxmlsetups
\startxmlsetups xml:section:level3
\xmldoif{#1}{/blockquote} {
\xmldoifnot{#1}{/p} {
\section{\xmlflush{#1}}
}
}
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{demo}{}
\stoptext
-----------------------------------------------------------------
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] 9+ messages in thread
* Re: issue with lpath
2022-08-04 10:22 ` Taco Hoekwater via ntg-context
2022-08-04 14:07 ` Hans Hagen via ntg-context
@ 2022-08-04 15:15 ` Pablo Rodriguez via ntg-context
1 sibling, 0 replies; 9+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2022-08-04 15:15 UTC (permalink / raw)
To: Taco Hoekwater via ntg-context; +Cc: Pablo Rodriguez
On 8/4/22 12:22, Taco Hoekwater via ntg-context wrote:
>> On 3 Aug 2022, at 15:54, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>> BTW, is there any way to rephrase "{h3 + blockquote}" in proper Lua?
>
> I was wondering about that as well, and I really had no clue how to
> do that. Some reading and studying later, I realised that there is a
> preceding-sibling:: axis.
>
> That is not documented in xml-mkiv.pdf I think, but it inherited
> from xpath, and that means this works:>
> \xmlsetsetup{#1}{blockquote/preceding-sibling::h3[-1]/} {xml:section}
>
> “Take all blockquotes, then tests their immediate preceding siblings
> (index [-1]) that are h3."
Many thanks for your reply, Taco.
It isn’t documented, but I have just discovered that it is used inside a
function:
https://www.pragma-ade.com/general/manuals/xml-mkiv.pdf#search=sibling
> But the CSS version is nicer.
I agree. But using CSS for LPaths feels like cheating to me.
Many thanks for your help again,
Pablo
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-04 14:07 ` Hans Hagen via ntg-context
@ 2022-08-04 15:32 ` Taco Hoekwater via ntg-context
2022-08-04 16:39 ` Pablo Rodriguez via ntg-context
0 siblings, 1 reply; 9+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-08-04 15:32 UTC (permalink / raw)
To: Hans Hagen
Cc: Taco Hoekwater, mailing list for ConTeXt users, Pablo Rodriguez
> On 4 Aug 2022, at 16:07, Hans Hagen <j.hagen@xs4all.nl> wrote:
>
> On 8/4/2022 12:22 PM, Taco Hoekwater via ntg-context wrote:
>>> On 3 Aug 2022, at 15:54, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>>>
>>> BTW, is there any way to rephrase "{h3 + blockquote}" in proper Lua?
>> I was wondering about that as well, and I really had no clue how to do that. Some
>> reading and studying later, I realised that there is a preceding-sibling:: axis.
>> That is not documented in xml-mkiv.pdf I think, but it inherited from xpath, and that means this works:
>> \xmlsetsetup{#1}{blockquote/preceding-sibling::h3[-1]/} {xml:section}
>> “Take all blockquotes, then tests their immediate preceding siblings (index [-1]) that are h3."
>> But the CSS version is nicer. Still, both solutions fail on generic input.
>> Sorry, out of clues
> \startbuffer[demo]
> ...
That puts the whole <div> content inside the \section, and I don’t think that was the intent. I understood that Pablo only wants the “h3” node.
In the original request, the CSS “{h3 + blockquote}” matches a “blockquote” anyplace where it is immediately preceded by a “h3” (and nowhere else).
After that, some trickery was needed to try and get back to the actual “h3”.
My trick above with preceding-sibling above also gets the “h3” that is immediately followed by a “blockquote”, but it got easily
confused if there were multiple “h3” or “blockquote” objects in the input.
Best wishes,
Taco
PS This sort of confusing filtering is why I do most of my xml processing from the lua end, where it is much clearer to me what is what.
—
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-04 15:32 ` Taco Hoekwater via ntg-context
@ 2022-08-04 16:39 ` Pablo Rodriguez via ntg-context
2022-08-05 15:28 ` Taco Hoekwater via ntg-context
0 siblings, 1 reply; 9+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2022-08-04 16:39 UTC (permalink / raw)
To: Taco Hoekwater via ntg-context; +Cc: Pablo Rodriguez
On 8/4/22 17:32, Taco Hoekwater via ntg-context wrote:
> [...]
> PS This sort of confusing filtering is why I do most of my xml
> processing from the lua end, where it is much clearer to me what is
> what.
Many thanks for clarifying the issue, Taco.
BTW, according to the last slide from
https://meeting.contextgarden.net/2019/talks/02-xmlprocessing/02-xmlprocessing.pdf,
you had plans to document how to deal with XML in proper Lua.
I wonder whether you are still interested in adding this information to
the manual.
Many thanks for your help,
Pablo
___________________________________________________________________________________
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] 9+ messages in thread
* Re: issue with lpath
2022-08-04 16:39 ` Pablo Rodriguez via ntg-context
@ 2022-08-05 15:28 ` Taco Hoekwater via ntg-context
0 siblings, 0 replies; 9+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-08-05 15:28 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Taco Hoekwater
> On 4 Aug 2022, at 18:39, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
>
> On 8/4/22 17:32, Taco Hoekwater via ntg-context wrote:
>> [...]
>> PS This sort of confusing filtering is why I do most of my xml
>> processing from the lua end, where it is much clearer to me what is
>> what.
> Many thanks for clarifying the issue, Taco.
>
> BTW, according to the last slide from
> https://meeting.contextgarden.net/2019/talks/02-xmlprocessing/02-xmlprocessing.pdf,
> you had plans to document how to deal with XML in proper Lua.
>
> I wonder whether you are still interested in adding this information to
> the manual.
In theory, yes. In reality, life is too short, and it is on the bottom of an ever rising pile of things to do. :sadface
Best wishes,
Taco
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
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] 9+ messages in thread
end of thread, other threads:[~2022-08-05 15:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-02 19:14 issue with lpath Pablo Rodriguez via ntg-context
2022-08-03 7:09 ` Taco Hoekwater via ntg-context
2022-08-03 13:54 ` Pablo Rodriguez via ntg-context
2022-08-04 10:22 ` Taco Hoekwater via ntg-context
2022-08-04 14:07 ` Hans Hagen via ntg-context
2022-08-04 15:32 ` Taco Hoekwater via ntg-context
2022-08-04 16:39 ` Pablo Rodriguez via ntg-context
2022-08-05 15:28 ` Taco Hoekwater via ntg-context
2022-08-04 15:15 ` Pablo Rodriguez via ntg-context
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).