ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to get the last item from an XML node
@ 2020-09-21 16:31 Denis Maier
  2020-09-22  7:18 ` Taco Hoekwater
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Maier @ 2020-09-21 16:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi

struggling again: Shouldn't the code below give me the last element 
under <tbody>? Right now 
\xmlfilter{#1}{/tr/last()/command(xml:table:tbody:tr)} gives me nothing...

(Use case is that I want to have a frame above the table and one bar 
below. So I think I should wrap the last line in the \startxtablefoot 
...\stopxtablefoot, i.e., I need one command for the last element, and 
one for the rest (Or is there a better way?). What would be the 
everything but the last?

What am I missing?

Thanks again,
Denis

==================
\setupxtable[frame=off,split=yes]
\setupxtable[head][topframe=on,bottomframe=on]
\setupxtable[body][]
\setupxtable[foot][bottomframe=on]

\startbuffer[test]
<?xml version="1.0" encoding="utf-8" ?>
<article>
<table>
    <tbody>
     <tr>
       <td>5</td>
       <td>A</td>
     </tr>
         <tr>
       <td>7</td>
       <td>B</td>
     </tr>
         <tr>
       <td>2</td>
       <td>C</td>
     </tr>
   </tbody>
</table>
</article>
\stopbuffer

\startxmlsetups xml:test
     \xmlsetsetup{#1}{*}{-}
     \xmlsetsetup{#1}{article}{xml:*}
     \xmlsetsetup{#1}{table}{xml:table}
     \stopxmlsetups

\xmlregistersetup{xml:test}

\startxmlsetups xml:article
\starttext
     \xmlflush{#1}
\stoptext
\stopxmlsetups

\startxmlsetups xml:table
   \startembeddedxtable
         \xmlfilter{#1}{/tbody/command(xml:table:tbody)}
   \stopembeddedxtable
\stopxmlsetups

\startxmlsetups xml:table:tbody
     \xmlfilter{#1}{/tr/last()/command(xml:table:tbody:tr)}
\stopxmlsetups

\startxmlsetups xml:table:tbody:tr
     \startxrow
     \xmlfilter{#1}{/td/command(xml:table:tbody:tr:td)}
     \stopxrow
\stopxmlsetups

\startxmlsetups xml:table:tbody:tr:td
     \startxcell
         \xmlflush{#1}
     \stopxcell
\stopxmlsetups

\xmlprocessbuffer{test}{test}{}
==================
___________________________________________________________________________________
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: How to get the last item from an XML node
  2020-09-21 16:31 How to get the last item from an XML node Denis Maier
@ 2020-09-22  7:18 ` Taco Hoekwater
  2020-09-22  8:23   ` Denis Maier
  0 siblings, 1 reply; 3+ messages in thread
From: Taco Hoekwater @ 2020-09-22  7:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 21 Sep 2020, at 18:31, Denis Maier <denis.maier.lists@mailbox.org> wrote:
> 
> Hi
> 
> struggling again: Shouldn't the code below give me the last element under <tbody>? Right now \xmlfilter{#1}{/tr/last()/command(xml:table:tbody:tr)} gives me nothing...
> 
> (Use case is that I want to have a frame above the table and one bar below. So I think I should wrap the last line in the \startxtablefoot ...\stopxtablefoot, i.e., I need one command for the last element, and one for the rest (Or is there a better way?). What would be the everything but the last?
> 
> What am I missing?

You need to read some more on the "Expressions and filters” chapter of the xml manual, as it does not work quite the way you think. Here is a quick fix:

> 
> 
> \startxmlsetups xml:table:tbody
>     \xmlfilter{#1}{/tr/last()/command(xml:table:tbody:tr)}

\xmlfilter{#1}{/tr[position()==last()]/command(xml:table:tbody:tr)}

Best wishes,
Taco

___________________________________________________________________________________
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: How to get the last item from an XML node
  2020-09-22  7:18 ` Taco Hoekwater
@ 2020-09-22  8:23   ` Denis Maier
  0 siblings, 0 replies; 3+ messages in thread
From: Denis Maier @ 2020-09-22  8:23 UTC (permalink / raw)
  To: ntg-context

Am 22.09.2020 um 09:18 schrieb Taco Hoekwater:
> 
> 
>> On 21 Sep 2020, at 18:31, Denis Maier <denis.maier.lists@mailbox.org> wrote:
>>
>> Hi
>>
>> struggling again: Shouldn't the code below give me the last element under <tbody>? Right now \xmlfilter{#1}{/tr/last()/command(xml:table:tbody:tr)} gives me nothing...
>>
>> (Use case is that I want to have a frame above the table and one bar below. So I think I should wrap the last line in the \startxtablefoot ...\stopxtablefoot, i.e., I need one command for the last element, and one for the rest (Or is there a better way?). What would be the everything but the last?
>>
>> What am I missing?
> 
> You need to read some more on the "Expressions and filters” chapter of the xml manual, as it does not work quite the way you think. Here is a quick fix:
> 
>>
>>
>> \startxmlsetups xml:table:tbody
>>      \xmlfilter{#1}{/tr/last()/command(xml:table:tbody:tr)}
> 
> \xmlfilter{#1}{/tr[position()==last()]/command(xml:table:tbody:tr)}
> 
> Best wishes,
> Taco

Thanks! That works. I have to admit, it's not entirely clear to me.

I adapted my pattern from the one given on page 78: /whocares/last()
Obviously, it's not that easy.

Best,
Denis


___________________________________________________________________________________
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-09-22  8:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 16:31 How to get the last item from an XML node Denis Maier
2020-09-22  7:18 ` Taco Hoekwater
2020-09-22  8:23   ` Denis Maier

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