[NTG-context] issue with lpath

Hans Hagen j.hagen at xs4all.nl
Thu Aug 4 16:07:51 CEST 2022


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


More information about the ntg-context mailing list