ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* XML: calculations on attribute values before output
@ 2022-05-04 20:10 Duncan Hothersall via ntg-context
  2022-05-05  7:21 ` Taco Hoekwater via ntg-context
  0 siblings, 1 reply; 3+ messages in thread
From: Duncan Hothersall via ntg-context @ 2022-05-04 20:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Duncan Hothersall


[-- Attachment #1.1: Type: text/plain, Size: 1737 bytes --]

Hi.

I'm processing an XML table and need to set a row span. Because we use a
variant of the CALS table model, spans are defined by an attribute saying
how many *additional* rows should be spanned, as opposed to how many *in
total*. So to translate this into TABLE \bTD[nr=X] syntax I need to add 1.

I'm guessing this is very easily doable (in lua?) but I've tried various
permutations and can't work it out. If anyone could give me a pointer that
would be great.

(In reality I'm going to need to handle lots of other conversions of
attribute values into \bTD[...] commands, so if there's a generalised way
of doing that sort of thing, or even better if someone has already tackled
CALS tables in this way, that would also be great!)

MWE below, but obviously it just passes the morerows="1" value straight
through into \bTD[nr=1] so it doesn't give me a row span at all.

Thanks in advance.

Duncan

------

\startbuffer[demo]
<informaltable>
 <tgroup>
  <tbody>
   <row>
    <entry morerows="1">1</entry>
    <entry>2</entry>
   </row>
   <row>
    <entry>3</entry>
   </row>
  </tbody>
 </tgroup>
</informaltable>
\stopbuffer

\startxmlsetups xml:demo:base
 \xmlsetsetup{#1}{*}{xml:demo:*}
\stopxmlsetups

\xmlregisterdocumentsetup{demo}{xml:demo:base}

\startxmlsetups xml:demo:informaltable
 \bTABLE
  \xmlflush{#1}
 \eTABLE
\stopxmlsetups

\startxmlsetups xml:demo:tgroup
 \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:tbody
 \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:row
 \bTR
  \xmlflush{#1}
 \eTR
\stopxmlsetups

\startxmlsetups xml:demo:entry
 \bTD[nr=\xmlattdef{#1}{morerows}{1}]
  \xmlflush{#1}
 \eTD
\stopxmlsetups

\setupbodyfont[modern]
\starttext
\xmlprocessbuffer{demo}{demo}{}
\stoptext

------

[-- Attachment #1.2: Type: text/html, Size: 2596 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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: XML: calculations on attribute values before output
  2022-05-04 20:10 XML: calculations on attribute values before output Duncan Hothersall via ntg-context
@ 2022-05-05  7:21 ` Taco Hoekwater via ntg-context
  2022-05-05  8:37   ` Duncan Hothersall via ntg-context
  0 siblings, 1 reply; 3+ messages in thread
From: Taco Hoekwater via ntg-context @ 2022-05-05  7:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Taco Hoekwater



> On 4 May 2022, at 22:10, Duncan Hothersall via ntg-context <ntg-context@ntg.nl> wrote:
> 
> Hi.
> 
> I'm processing an XML table and need to set a row span. Because we use a variant of the CALS table model, spans are defined by an attribute saying how many *additional* rows should be spanned, as opposed to how many *in total*. So to translate this into TABLE \bTD[nr=X] syntax I need to add 1.
> 
> I'm guessing this is very easily doable (in lua?) but I've tried various permutations and can't work it out. If anyone could give me a pointer that would be great.
> 
> (In reality I'm going to need to handle lots of other conversions of attribute values into \bTD[...] commands, so if there's a generalised way of doing that sort of thing, or even better if someone has already tackled CALS tables in this way, that would also be great!)

Not CALS, but I do a lot of HTML table processing. I find it all much easier on the lua side, because there the 
attributes are just in a table entry of the argument node t ( t.at ):

set up a lua function in the setups:

\startxmlsetups xml:demo:base
 \xmlsetsetup{#1}{*}{xml:demo:*}
 \xmlsetfunction {\xmldocument}{entry}{userdata.xmlfunctions.entry}
\stopxmlsetups

and then add this lua code:

\startluacode
userdata.xmlfunctions = {}
function userdata.xmlfunctions.entry (t)
  local rows = (t.at.morerows or 1) + 1
  context.bTD({nr=rows})
  lxml.flush(t) 
  context.eTD()
end
\stopluacode

All of the tex-side commands also exist in lua, in the lxml and/or xml table, e.g.:

direct output flushing: 
  lxml.flush(t)
  lxml.all(t, ‘entry’)

filter for processing:
  for b in xml.collected(lxml.getid(t),'../row/entry') do … end


(those are the ones I use a lot, there are many more)

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: XML: calculations on attribute values before output
  2022-05-05  7:21 ` Taco Hoekwater via ntg-context
@ 2022-05-05  8:37   ` Duncan Hothersall via ntg-context
  0 siblings, 0 replies; 3+ messages in thread
From: Duncan Hothersall via ntg-context @ 2022-05-05  8:37 UTC (permalink / raw)
  To: Taco Hoekwater; +Cc: Duncan Hothersall, mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2788 bytes --]

Thanks so much Taco, that opens the door to a lot for me. It's a tricky
learning curve.

Just in case anyone else is copying code in future for CALS, there's a tiny
tweak to the rows calculation, it should be (t.at.morerows or 0) + 1.

I see a route to solving lots of other problems here too. Thanks again.

Duncan

On Thu, 5 May 2022 at 08:21, Taco Hoekwater <taco@bittext.nl> wrote:

>
>
> > On 4 May 2022, at 22:10, Duncan Hothersall via ntg-context <
> ntg-context@ntg.nl> wrote:
> >
> > Hi.
> >
> > I'm processing an XML table and need to set a row span. Because we use a
> variant of the CALS table model, spans are defined by an attribute saying
> how many *additional* rows should be spanned, as opposed to how many *in
> total*. So to translate this into TABLE \bTD[nr=X] syntax I need to add 1.
> >
> > I'm guessing this is very easily doable (in lua?) but I've tried various
> permutations and can't work it out. If anyone could give me a pointer that
> would be great.
> >
> > (In reality I'm going to need to handle lots of other conversions of
> attribute values into \bTD[...] commands, so if there's a generalised way
> of doing that sort of thing, or even better if someone has already tackled
> CALS tables in this way, that would also be great!)
>
> Not CALS, but I do a lot of HTML table processing. I find it all much
> easier on the lua side, because there the
> attributes are just in a table entry of the argument node t ( t.at ):
>
> set up a lua function in the setups:
>
> \startxmlsetups xml:demo:base
>  \xmlsetsetup{#1}{*}{xml:demo:*}
>  \xmlsetfunction {\xmldocument}{entry}{userdata.xmlfunctions.entry}
> \stopxmlsetups
>
> and then add this lua code:
>
> \startluacode
> userdata.xmlfunctions = {}
> function userdata.xmlfunctions.entry (t)
>   local rows = (t.at.morerows or 1) + 1
>   context.bTD({nr=rows})
>   lxml.flush(t)
>   context.eTD()
> end
> \stopluacode
>
> All of the tex-side commands also exist in lua, in the lxml and/or xml
> table, e.g.:
>
> direct output flushing:
>   lxml.flush(t)
>   lxml.all(t, ‘entry’)
>
> filter for processing:
>   for b in xml.collected(lxml.getid(t),'../row/entry') do … end
>
>
> (those are the ones I use a lot, there are many more)
>
> Best wishes,
> Taco



-- 
Duncan Hothersall, Operations Director
CAPDM Limited - Online Program Enablers
0131 677 2400  www.capdm.com
Registered in Scotland: SC168970       VAT: 682 846 983
Registered address: 20 Forth Street Edinburgh EH1 3LH UK
<https://maps.google.com/?q=22+Forth+Street,+Edinburgh,+EH1+3LH,+UK&entry=gmail&source=g>

Capture, author, publish, deliver and manage your learning materials.


*Sign up to the CAPDM newsletter here <http://eepurl.com/bqzBQn>*

[-- Attachment #1.2: Type: text/html, Size: 4130 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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:[~2022-05-05  8:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04 20:10 XML: calculations on attribute values before output Duncan Hothersall via ntg-context
2022-05-05  7:21 ` Taco Hoekwater via ntg-context
2022-05-05  8:37   ` Duncan Hothersall 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).