ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* lpath to select last item
@ 2020-07-07 20:46 Pablo Rodriguez
  2020-07-08  9:59 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Rodriguez @ 2020-07-07 20:46 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Dear list,

I have the following sample:

  \startbuffer[demo]
    <document>
    <h2 id="heading">Heading</h2>
      <ul>
        <li>list</li>
      </ul>
    <h2 id="heading-1">Heading</h2>
      <ul>
        <li>list
        <ul>
           <li>list</li>
        </ul></li>
      </ul>
    <h2 id="heading-2">Heading</h2>
      <ul>
        <li>list
        <ul>
          <li>list
          <ul>
            <li>list</li>
          </ul></li>
        </ul></li>
      </ul>
    </document>
  \stopbuffer

  \startxmlsetups xml:demo:base
      \xmlsetsetup{#1}{document|h2|ul|li}{xml:*}
      %~ \xmlsetsetup{#1}{ul/li/!ul}{xml:last:item} % nothing changes
      %~ \xmlsetsetup{#1}{ul/li/!li}{xml:last:item} % blank item inserted
      %~ \xmlsetsetup{#1}{h2/**/ul/li}{xml:last:item} % nothing changes
      \xmlsetsetup{#1}{h2/***/ul/li/!ul}{xml:last:item} % shouldn’t be
this one?
  \stopxmlsetups

  \xmlregistersetup{xml:demo:base}

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

  \startxmlsetups xml:h2
      \section{\xmlflush{#1}}
  \stopxmlsetups

  \startxmlsetups xml:ul
      \startitemize\xmlflush{#1}\stopitemize
  \stopxmlsetups

  \startxmlsetups xml:li
      \startitem\xmlflush{#1}\stopitem
  \stopxmlsetups

  \startxmlsetups xml:last:item
      \startitem\red\xmlflush{#1}\stopitem
  \stopxmlsetups

  \starttext
      \xmlprocessbuffer{main}{demo}{}
  \stoptext

I need to be able to select the last <li> (the one with no <ul> child)
in the <h2> element.

I thought that the lpath for that would be "h2/***/ul/li/!ul", but I
don’t know what I’m missing, since it doesn’t work at all.

Which would be the right lpath to select the last item in each list?

Many thanks for your help,

Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: lpath to select last item
  2020-07-07 20:46 lpath to select last item Pablo Rodriguez
@ 2020-07-08  9:59 ` Hans Hagen
  2020-07-08 13:56   ` Pablo Rodriguez
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2020-07-08  9:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 7/7/2020 10:46 PM, Pablo Rodriguez wrote:
> Dear list,
> 
> I have the following sample:
> 
>    \startbuffer[demo]
>      <document>
>      <h2 id="heading">Heading</h2>
>        <ul>
>          <li>list</li>
>        </ul>
>      <h2 id="heading-1">Heading</h2>
>        <ul>
>          <li>list
>          <ul>
>             <li>list</li>
>          </ul></li>
>        </ul>
>      <h2 id="heading-2">Heading</h2>
>        <ul>
>          <li>list
>          <ul>
>            <li>list
>            <ul>
>              <li>list</li>
>            </ul></li>
>          </ul></li>
>        </ul>
>      </document>
>    \stopbuffer
> 
>    \startxmlsetups xml:demo:base
>        \xmlsetsetup{#1}{document|h2|ul|li}{xml:*}
>        %~ \xmlsetsetup{#1}{ul/li/!ul}{xml:last:item} % nothing changes
>        %~ \xmlsetsetup{#1}{ul/li/!li}{xml:last:item} % blank item inserted
>        %~ \xmlsetsetup{#1}{h2/**/ul/li}{xml:last:item} % nothing changes
>        \xmlsetsetup{#1}{h2/***/ul/li/!ul}{xml:last:item} % shouldn’t be
> this one?
>    \stopxmlsetups
> 
>    \xmlregistersetup{xml:demo:base}
> 
>    \startxmlsetups xml:document
>        \xmlflush{#1}
>    \stopxmlsetups
> 
>    \startxmlsetups xml:h2
>        \section{\xmlflush{#1}}
>    \stopxmlsetups
> 
>    \startxmlsetups xml:ul
>        \startitemize\xmlflush{#1}\stopitemize
>    \stopxmlsetups
> 
>    \startxmlsetups xml:li
>        \startitem\xmlflush{#1}\stopitem
>    \stopxmlsetups
> 
>    \startxmlsetups xml:last:item
>        \startitem\red\xmlflush{#1}\stopitem
>    \stopxmlsetups
> 
>    \starttext
>        \xmlprocessbuffer{main}{demo}{}
>    \stoptext
> 
> I need to be able to select the last <li> (the one with no <ul> child)
> in the <h2> element.
> 
> I thought that the lpath for that would be "h2/***/ul/li/!ul", but I
> don’t know what I’m missing, since it doesn’t work at all.
> 
> Which would be the right lpath to select the last item in each list?
This should work but we're one off so i need to fix that.

\startbuffer[demo]
<document>
   <ul>
     <li>first</li>
     <li>any</li>
     <li>last</li>
   </ul>
</document>
\stopbuffer

\startxmlsetups xml:demo:base
   \xmlsetsetup{#1}{document|ul|li}{xml:*}
   \xmlsetsetup{#1}{ul/li[1]}{xml:item:first}
   \xmlsetsetup{#1}{ul/li[-1]}{xml:item:last}
\stopxmlsetups

\xmlregistersetup{xml:demo:base}

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

\startxmlsetups xml:ul
  \startitemize
    \xmlflush{#1}
  \stopitemize
\stopxmlsetups

\startxmlsetups xml:li
   \startitem
     \xmlflush{#1}
   \stopitem
\stopxmlsetups

\startxmlsetups xml:item:first
   \startitem
     \color[blue]{\xmlflush{#1}}
   \stopitem
\stopxmlsetups

\startxmlsetups xml:item:last
   \startitem
     \color[red]{\xmlflush{#1}}
   \stopitem
\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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: lpath to select last item
  2020-07-08  9:59 ` Hans Hagen
@ 2020-07-08 13:56   ` Pablo Rodriguez
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Rodriguez @ 2020-07-08 13:56 UTC (permalink / raw)
  To: ntg-context

On 7/8/20 11:59 AM, Hans Hagen wrote:
> On 7/7/2020 10:46 PM, Pablo Rodriguez wrote:
>> [...]
>> Which would be the right lpath to select the last item in each list?
> This should work but we're one off so i need to fix that.
>
> \startbuffer[demo]
> <document>
>    <ul>
>      <li>first</li>
>      <li>any</li>
>      <li>last</li>
>    </ul>
> </document>
> \stopbuffer
>
> \startxmlsetups xml:demo:base
>    \xmlsetsetup{#1}{document|ul|li}{xml:*}
>    \xmlsetsetup{#1}{ul/li[1]}{xml:item:first}
>    \xmlsetsetup{#1}{ul/li[-1]}{xml:item:last}
> \stopxmlsetups

Many thanks for your help, Hans.

This is like magic to me. But I’m afraid that my description was inaccurate.

I need to mark the last item from nested lists, but considering each
<h2> (such as in my sample), not the whole document.

Just in case it isn’t clear, this is the XML source with desired items
marked:

    <document>
    <h2 id="heading">Heading</h2>
      <ul>
        <li>list</li>                    ***this one***
      </ul>
    <h2 id="heading-1">Heading</h2>
      <ul>
        <li>list
        <ul>
           <li>list</li>                 ***this one***
        </ul></li>
      </ul>
    <h2 id="heading-2">Heading</h2>
      <ul>
        <li>list
        <ul>
          <li>list
          <ul>
            <li>list</li>               ***this one***
          </ul></li>
        </ul></li>
      </ul>
    </document>

I hope it is clear now that it is the last item in a nested list, but
for each <h2> element.

Many thanks for your help again,

Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2020-07-08 13:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 20:46 lpath to select last item Pablo Rodriguez
2020-07-08  9:59 ` Hans Hagen
2020-07-08 13:56   ` Pablo Rodriguez

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