ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Taco Hoekwater via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Taco Hoekwater <taco@bittext.nl>
Subject: Re: XML: calculations on attribute values before output
Date: Thu, 5 May 2022 09:21:17 +0200	[thread overview]
Message-ID: <74B4B9BC-4A24-438A-9746-205990199BF0@bittext.nl> (raw)
In-Reply-To: <CAN8fp9U+LzaUTxEQ0XZDVi1x77N32gGWQwq545ZMToVFQm-xMQ@mail.gmail.com>



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

  reply	other threads:[~2022-05-05  7:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04 20:10 Duncan Hothersall via ntg-context
2022-05-05  7:21 ` Taco Hoekwater via ntg-context [this message]
2022-05-05  8:37   ` Duncan Hothersall via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74B4B9BC-4A24-438A-9746-205990199BF0@bittext.nl \
    --to=ntg-context@ntg.nl \
    --cc=taco@bittext.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).