On 22-10-2011 18:46, Thomas A. Schmitz wrote:
Hi all,
again, I'm playing a bit with processing my xml in lua. I want a simple interface for processing tables (I don't need all the power and complexity of cals tables and want to learn something in the process). And I thought that collecting the setups in lua might be the easiest way, but so far, I haven't been successful. Here's an example:
\startbuffer[test] <a> <nattable frame="on"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> </nattable> </a> \stopbuffer
\startxmlsetups xml:testsetups \xmlsetsetup{main}{a|nattable|tr|td|}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:testsetups}
\startxmlsetups xml:a \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:nattable \startluacode framestate = lxml.att("#1", "frame") context(framestate) context(true) context.placefigure( { "here" }, "none" , function() context.setupTABLE( { "frame=on" } ) context.bTABLE() context.xmlflush("#1") context.eTABLE() end) \stopluacode \stopxmlsetups
\startxmlsetups xml:tr \startluacode context.bTR() context.xmlflush("#1") context.eTR() \stopluacode \stopxmlsetups
\startxmlsetups xml:td \startluacode context.bTD() context.xmlflush("#1") context.eTD() \stopluacode \stopxmlsetups
\starttext \xmlprocessbuffer{main}{test}{} \stoptext
question: I have the value "on" in the lua variable "framestate." But how can I pass this on to the line context.setupTABLE( { "frame=on" } )? I tried something like context.setupTABLE( { "frame=" .. framestate } ) but that doesn't work. Any suggestions?
why so complex \startbuffer[test] <a> <nattable frame="on"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> </nattable> <nattable frame="off"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> </nattable> <nattable frame="no"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> </nattable> </a> \stopbuffer \startxmlsetups xml:testsetups \xmlsetsetup{main}{a|nattable|tr|td|}{xml:*} \stopxmlsetups \xmlregistersetup{xml:testsetups} \startxmlsetups xml:a \xmlflush{#1} \stopxmlsetups \xmlmapvalue {nattable:frame} {on} {on} \xmlmapvalue {nattable:frame} {yes} {on} \xmlmapvalue {nattable:frame} {off} {off} \xmlmapvalue {nattable:frame} {no} {off} \startxmlsetups xml:nattable \placefigure [here,none] {} { \setupTABLE[frame=\xmlval{nattable:frame}{\xmlatt{#1}{frame}}{on}] \bTABLE \xmlflush{#1} \eTABLE } \stopxmlsetups \startxmlsetups xml:tr \bTR \xmlflush{#1} \eTR \stopxmlsetups \startxmlsetups xml:td \bTD \xmlflush{#1} \eTD \stopxmlsetups \starttext \xmlprocessbuffer{main}{test}{} \stoptext In x-cals.lua / mkiv you can see an example of pure lua solution. It boils down to applying a function the the whole table element. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------