[NTG-context] XML: calculations on attribute values before output

Taco Hoekwater taco at bittext.nl
Thu May 5 09:21:17 CEST 2022

> On 4 May 2022, at 22:10, Duncan Hothersall via ntg-context <ntg-context at 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
 \xmlsetfunction {\xmldocument}{entry}{userdata.xmlfunctions.entry}

and then add this lua code:

userdata.xmlfunctions = {}
function userdata.xmlfunctions.entry (t)
  local rows = (t.at.morerows or 1) + 1

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

direct output flushing: 
  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,

More information about the ntg-context mailing list