Page 1 of 1

conditionally showing/hiding content controls

PostPosted: Tue Jul 25, 2017 1:54 am
by vash
Hi,

I have absolutely no experience with openxml or docx4j. But I'd like to know if the scenario I need is possible before diving into it. Pointers in the right direction would suffice.

I have data in XML or JSON format containing a persons employer type.
Suppose I have 3 plain text content controls in my word template: one if the employer type equals 'GOVERNMENT', one for 'SEMI-GOVERNMENT', one for 'OTHER'.
Only one of these content controls should be visible in the end result, depending on the data.

Is this something that should be done/solved with docx4j, or in the word template itself? How?

Thanks.

Re: conditionally showing/hiding content controls

PostPosted: Tue Jul 25, 2017 8:52 am
by jason
Hi, sure, for this you'd use an OpenDoPE conditional content control.

You need your data in XML format. Then for the GOVERNMENT example, you need an XPath expression which results in true if employer type equals 'GOVERNMENT'.

Your document contains a conditional content control having that XPath expression, then inside it, whatever you want to appear when that is true. In your case, your GOVERNMENT plain text content control.

You'd have a conditional content control for each of the other two: SEMI-GOVERNMENT and OTHER. In the GOVERNMENT case, their XPath expressions would evaluate to false, so their content would not appear.

You need to create a Word template with these structures in it, typically using an OpenDoPE authoring add-in (and sample XML data), and then at run time, docx4j handles everything (you feed it your template, plus XML data in the same format as the sample you used at authoring time).

That's an overview. For details, please Google, then feel free to post again.

Re: conditionally showing/hiding content controls

PostPosted: Tue Jul 25, 2017 10:17 pm
by vash
Thank you. This is enough info for now. If I run into issues I'll post again.