From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/114853 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Duncan Hothersall via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: XML: calculations on attribute values before output Date: Thu, 5 May 2022 09:37:43 +0100 Message-ID: References: <74B4B9BC-4A24-438A-9746-205990199BF0@bittext.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0059747305787238774==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5540"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Duncan Hothersall , mailing list for ConTeXt users To: Taco Hoekwater Original-X-From: ntg-context-bounces@ntg.nl Thu May 05 10:38:49 2022 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nmX0Z-00018P-Kv for gctc-ntg-context-518@m.gmane-mx.org; Thu, 05 May 2022 10:38:47 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 68228289E6D; Thu, 5 May 2022 10:38:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zW2ZuSNVo5vl; Thu, 5 May 2022 10:38:03 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B8003289E6E; Thu, 5 May 2022 10:38:02 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 9BA55289E6C for ; Thu, 5 May 2022 10:38:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OXnSRbWM37xF for ; Thu, 5 May 2022 10:38:00 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.208.180; helo=mail-lj1-f180.google.com; envelope-from=dh@capdm.com; receiver= Original-Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 3E324289E54 for ; Thu, 5 May 2022 10:38:00 +0200 (CEST) Original-Received: by mail-lj1-f180.google.com with SMTP id y19so4688008ljd.4 for ; Thu, 05 May 2022 01:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=capdm.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V4bZUnD9S+hoK3Uw/u9PDvKlJvU+jXS2lhituLuORiA=; b=be/JWJRECD8gIE/kNx3eM5fwZ4Vlfq/A/wwDPJs7b46SavDwPVdOlxi0/u30mNFrBG LuWYCSWZKw/0IuvFNi6XU9f7d8AuCpCGnYk7TAH1zcU/ogk8tu3IwYHRXsh2Fiq70UH1 /R0dvwlmYtrWsovRPAfS2QjGfIt1dA3/RQvI8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V4bZUnD9S+hoK3Uw/u9PDvKlJvU+jXS2lhituLuORiA=; b=Kl1uEoS0hq43WusTlGk0A2G+yc5cxbN4euzqDOAvir0Ij+m86ZGphpxb5HVn4IrhuB z9masUZbNa/PIBvRhIYfzQBp/Q/7k8AmYhLpQniSACuSbFQmi38a6aTnqBTRF2MGzL4w hovsUEN8eMUMDfV77uI0q9cyVKFCp5k/fV7YfjGqIdK3hSlRauHcsuVtZYDJ741jBz33 JcVl69+1n51S0tmVe98gO5rU+BXdrTGa2wdoqSStiatLyJ/nozzlp2MYAVM1aL+t42PW tAhxsz7ax+TLVfYd+ghepBaaKBp7iFIZJSoX9CpChMSJyZIchLTLmIVD5MtRkzIDsvyg iPVw== X-Gm-Message-State: AOAM531mSL4WwiRapg88rtvGgnPtMwZnF2JQBp7ne2I8V26Ed0GCj1D/ eoBwswLdExl/4gVMa4UKiKx8FvEcK3TKXyCFGCn57Xsgo6CvnNTZ X-Google-Smtp-Source: ABdhPJzRNjyi8przfIpyfsg0KDDu55wbfpwxK1ReoSj4Pa5MofmFMdXoH34AhO+pUCbucwZOVw6FiVXoSwPBceMSr+8= X-Received: by 2002:a2e:bf05:0:b0:247:b233:cfba with SMTP id c5-20020a2ebf05000000b00247b233cfbamr15364336ljr.131.1651739879369; Thu, 05 May 2022 01:37:59 -0700 (PDT) In-Reply-To: <74B4B9BC-4A24-438A-9746-205990199BF0@bittext.nl> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:114853 Archived-At: --===============0059747305787238774== Content-Type: multipart/alternative; boundary="000000000000c58a9b05de3fa85b" --000000000000c58a9b05de3fa85b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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=3DX] syntax I need to add= 1. > > > > I'm guessing this is very easily doable (in lua?) but I've tried variou= s > permutations and can't work it out. If anyone could give me a pointer tha= t > 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 tackle= d > 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 =3D {} > function userdata.xmlfunctions.entry (t) > local rows =3D (t.at.morerows or 1) + 1 > context.bTD({nr=3Drows}) > 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, =E2=80=98entry=E2=80=99) > > filter for processing: > for b in xml.collected(lxml.getid(t),'../row/entry') do =E2=80=A6 end > > > (those are the ones I use a lot, there are many more) > > Best wishes, > Taco --=20 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 Capture, author, publish, deliver and manage your learning materials. *Sign up to the CAPDM newsletter here * --000000000000c58a9b05de3fa85b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks so much Taco, that opens the door to a lot for me. = It's a tricky learning curve.

Just in case anyone el= se 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.<= /div>

Duncan

<= div dir=3D"ltr" class=3D"gmail_attr">On Thu, 5 May 2022 at 08:21, Taco Hoek= water <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 s= aying how many *additional* rows should be spanned, as opposed to how many = *in total*. So to translate this into TABLE \bTD[nr=3DX] syntax I need to a= dd 1.
>
> I'm guessing this is very easily doable (in lua?) but I've tri= ed 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 generalise= d way of doing that sort of thing, or even better if someone has already ta= ckled 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 easie= r 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
=C2=A0\xmlsetsetup{#1}{*}{xml:demo:*}
=C2=A0\xmlsetfunction {\xmldocument}{entry}{userdata.xmlfunctions.entry} \stopxmlsetups

and then add this lua code:

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

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

direct output flushing:
=C2=A0 lxml.flush(t)
=C2=A0 lxml.all(t, =E2=80=98entry=E2=80=99)

filter for processing:
=C2=A0 for b in xml.collected(lxml.getid(t),'../row/entry') do =E2= =80=A6 end


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

Best wishes,
Taco


--
Duncan Hothersa= ll, Operations Director
CAPDM Limited - Online Program Enablers
0131 677 24= 00=C2=A0=C2=A0www.capdm.com
Registered in Scotland: SC168970=C2=A0 =C2=A0 =C2=A0 =C2=A0= VAT: 682 846 983
Registered address:=C2=A02= 0 Forth Street Edinburgh EH1 3LH UK

Captur= e, author, publish, deliver and manage your learning materials.
<= br>
=
--000000000000c58a9b05de3fa85b-- --===============0059747305787238774== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============0059747305787238774==--