![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/d4db251f6da966f841fc5b1a9822eb56.jpg?s=120&d=mm&r=g)
On 2 Aug 2022, at 21:14, Pablo Rodriguez via ntg-context
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)
![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
On 8/3/22 09:09, Taco Hoekwater via ntg-context wrote:
On 2 Aug 2022, at 21:14, Pablo Rodriguez via ntg-context
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
![](https://secure.gravatar.com/avatar/d4db251f6da966f841fc5b1a9822eb56.jpg?s=120&d=mm&r=g)
On 3 Aug 2022, at 15:54, Pablo Rodriguez via ntg-context
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)
![](https://secure.gravatar.com/avatar/46562c7d27388490d62e8d7a5bc960dd.jpg?s=120&d=mm&r=g)
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
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 -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d4db251f6da966f841fc5b1a9822eb56.jpg?s=120&d=mm&r=g)
On 4 Aug 2022, at 16:07, Hans Hagen
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
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)
![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
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-xmlprocessi..., 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
![](https://secure.gravatar.com/avatar/d4db251f6da966f841fc5b1a9822eb56.jpg?s=120&d=mm&r=g)
On 4 Aug 2022, at 18:39, Pablo Rodriguez via ntg-context
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-xmlprocessi..., 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)
![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
On 8/4/22 12:22, Taco Hoekwater via ntg-context wrote:
On 3 Aug 2022, at 15:54, Pablo Rodriguez via ntg-context
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
participants (3)
-
Hans Hagen
-
Pablo Rodriguez
-
Taco Hoekwater