[Chicago] mailmerge for xml?

Lukasz Szybalski szybalski at gmail.com
Fri May 1 22:07:43 CEST 2009


On Fri, May 1, 2009 at 2:44 PM, Cosmin Stejerean <cosmin at offbytwo.com> wrote:
> On Fri, May 1, 2009 at 1:51 PM, Lukasz Szybalski <szybalski at gmail.com>
> wrote:
>>
>> Hello,
>> Sorry if its not too related.....but...
>>
>> Does anybody know a documentation that would show how to create  a
>> openoffice template and then fill in the data from an xml?
>>
>> 1. I have an existing xml with a structure
>> 2. I have an existing openoffice document/form
>> 3. I want to fill in information like: Firstname, lastname...etc
>> 4. I want to easly move the xml data to the openoffice form.
>> 5. I will automate the transfer using python uno later on (unless xslt
>> will do it for me)
>>
>> What I'm looking for is a way to define field names in a form that
>> would correspond to a xml. I don't want to translate xml nodes to some
>> field name but I would rather do:
>>
>> xml:
>>     <ClientApp>
>>           <Org>my company</Org>
>>            <Name>Full name of the comapny</Name>
>>           <Version>1.02 (4.02)</Version>
>>       </ClientApp>
>>
>> in my openoffice template create a table and fill it in like this:
>>
>> |   ClientApp.Name       |  ClientApp.Version     |
>>
>>
>> Anybody did anything like that? Its like a mailmerge, but for xml to a
>> form, instead of csv to mailing label.
>
> We've done similar things at work in the past, although we filled OpenOffice
> templates with data from a database. If you're using lxml.objectify to
> translate your XML into an object tree and have some flexibility over your
> ODT layout I would simply use a regex for the transformation with some code
> that looks like
> import re
> pattern = re.compile('\$\$(.+?)\$\$')
> for match in pattern.findall(otdbody):
>   current = root # object form lxml.objectify
>   for level in match.split('.'):
>      current = getattr(current, level)
>   odtbody.replace(match, current)
>
> I think that should do it.


I'll test it.

Have you done anything with a xforms in openoffice. There is a
tutorial that shows how to build a form (from to xml) but it does not
show how to go the other way. If I could build the template using
xforms, and then use similar program as you have above to fill it in,
then that would give me form to xml, form to pdf, xml to form, xml to
form to pdf.

Thanks,
Lucas


More information about the Chicago mailing list