Dear Contex’ers,

I still desperately need your help. I would like to use Context mkiv for compiling serial letters with an xml database of addresses. I used to do this in mkii.

The problem may seem trivial to experienced programmers like yourselves, but yes, I am stuck.

I have several mkiv manuals, I tried dozens of lines of luacode, but somehow ...

Let me as a turcologist compare my problem to learning Kazakh: I am prepared to give you a manual with the grammatical rules, provide you with lists of nouns, verbs, adjectives and postpositions, explain the application of phonological rules, transliterations of the alphabet, give you a insight in the nominal cases and verb structure, and read with you a text in Kazakh. Nevertheless, without being rude, I bet that even then you are unable to flawlessly produce a poem or even a brief text in Kazakh yourself.

The same applies to information on complicated programming languages such as lua and TeX (steep learning curves - remember!).

Yet even for non-programmers it it is fun to use TeX and Context.

Therefore, knowledgeable list members, please help us. Have compassion and patience with the non-programmers amongst you who struggle with the application of the available information on Context. Who sometimes do not know how to accurately formulate their problems in programmer-ish. Who are  specialists in their own fields, but feel humble in this area.

….

Regarding my file, I have found out how to process the xml data from an xml file (now in the buffer). The recipient’s address neatly shows up in the designed place. (See pdf). So far, everything seems OK. 

Yet when I add text, only the text appears, and all address data from the xml file disappear.

You can try it out by uncommenting the %\input knuth or %tekst lines.

I have tried various options, but for now I have no idea how to proceed further.


Context Version: 2017.07.17 00:20
Lua 5.2.4, This is LuaTeX, Version 1.05.0.

Your help is much appreciated!

Раһмет!

Kind regards,

Robert

\usemodule[letter]

\setuplanguage[nl][date={year, –, mm, –, dd}] % ISO 8601 date
\setupletteroptions[language=netherlands,bodyfont={rm,10pt},whitespace=1.5ex]

\startbuffer[participants]
<contacts>
  <contact class='participant' label='Hendriks'>
    <formalname>Hendriks</formalname>
    <informalname>Karel</informalname>
    <prefix>mr.</prefix>
    <initials>K.</initials>
    <city>Arnhem</city>
    <address>
      <p>Mr. K. Hendriks</p>
      <p>Grotestraat 5</p>
      <p>1234 BB Arnhem</p>
    </address>
    <kix>1234bb5</kix>
  </contact>
  <contact class='participant' label='Janssen'>
    <formalname>Janssen</formalname>
    <informalname>Piet</informalname>
    <initials>P.</initials>
    <prefix>mr.</prefix>
    <city>Nijmegen</city>
    <address>
     <p>Mr. P. Janssen</p>
     <p>Kortestraat 8</p>
     <p>1234 AA Nijmegen</p>
    </address>
    <kix>1234aa8</kix>
  </contact>
</contacts>
\stopbuffer

\startxmlsetups xml:setups
\xmlsetsetup{#1}{document|contacts|contact|prefix|initials|address|city|text|kix|p}{xml:*}
%\xmlsetsetup{\xmldocument}{text:p}{xml:paragraph}
\stopxmlsetups

\xmlregistersetup{xml:setups}

\startxmlsetups xml:contacts
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:contact

\setupletter
[toaddress={\xmlall{#1}{/address/p}\par\xmltext{#1}{/kix}}]

\defineletterelement[layer][address][example]%
    {\correspondenceparameter{toname}\\\correspondenceparameter{toaddress}\par}

%toname is not used in setupletter because toaddress contains all data.
%kix is used for adding a barcode to the address.

\setupletterlayer[address][alternative=example,y=6cm,x=12cm,color=red,style=\tfa\sans]

\startletter
  [opening={Dear \xmltext{#1}{/prefix} \xmltext{#1}{/formalname},},
   closing={Kind regards,},
   subject={subject: your life in \xmltext{#1}{/city}},
   signature={X}]

\stopletter

\stopxmlsetups

\startxmlsetups xml:address
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:p
\xmlflushtext{#1}\par
\stopxmlsetups

\starttext

%\input knuth

%tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst

\xmlprocessbuffer{main}{participants}{}

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