Page 1 of 1

Re-Processing document with repeats?

PostPosted: Fri Sep 16, 2022 10:21 pm
by mgiepz
Hi there!
I am developing and application that allows users to create OpenDoPE compliant templates using a word-addin (based on office-js api) and I have some questions regarding docx4j and OpenDoPE processing:

1. Is it possible to "re-run" the processing of a template with repeats? So when the repeat has already been expanded and I add new rows to my data, is it possible to run docx4j again on that document to reflect that new row in the repeating section? Or do I have to start with the original template again? In the document that has already been processed I can see that the od:repeat gets replaced with od:rptd. Does that mean that this repeat cannot be run again?

2. In my add-in I add the XPath for the ConentControls that are inside a repeat to the odx:xpaths in the custom xml part and I set the corresponding <w:tag w:val="od:xpath=xxx"/>. After running the binding I get n repeats of the inner ContentControl but the value does not change accordingly. All "clones" have the same <w:tag w:val="od:xpath=xxx"/>. Do I have to add a standard w15 binding to the inner ContenControl too to make it work? When I set a breakpoint in OpenDoPEHandler.DeepTraversor.processDescendantBindings I can see that none of the codeblocks inside the if (binding == null)... seems to apply.

Thanks and best regards,
Marius

Re: Re-Processing document with repeats?

PostPosted: Sun Sep 18, 2022 9:49 am
by jason
Hi Marius

mgiepz wrote:1. Is it possible to "re-run" the processing of a template with repeats? So when the repeat has already been expanded and I add new rows to my data, is it possible to run docx4j again on that document to reflect that new row in the repeating section? Or do I have to start with the original template again? In the document that has already been processed I can see that the od:repeat gets replaced with od:rptd. Does that mean that this repeat cannot be run again?


There is https://github.com/plutext/docx4j/blob/ ... r.java#L57 but this functionality would be used less (and therefore less tested) than the usual processing steps.

mgiepz wrote:2. In my add-in I add the XPath for the ConentControls that are inside a repeat to the odx:xpaths in the custom xml part and I set the corresponding <w:tag w:val="od:xpath=xxx"/>. After running the binding I get n repeats of the inner ContentControl but the value does not change accordingly. All "clones" have the same <w:tag w:val="od:xpath=xxx"/>.


Seems like the antlr parser might not be handling your xpaths properly?

The sample ContentControlBindingExtensionsOld is useful for debugging since it saves the output of each step in the process.

May I suggest you try to duplicate https://github.com/plutext/docx4j/blob/ ... voice.docx with your authoring add in, then compare the content controls and XPath expressions in the two input template documents?

The sample linked above will also produce "_preprocessed.docx" files which you can compare.

mgiepz wrote:Do I have to add a standard w15 binding to the inner ContenControl too to make it work?


No. Better not to. cheers .. Jason

Re: Re-Processing document with repeats?

PostPosted: Mon Sep 19, 2022 8:48 pm
by mgiepz
jason wrote:
mgiepz wrote:Do I have to add a standard w15 binding to the inner ContenControl too to make it work?


No. Better not to. cheers .. Jason


Hi Jason,
thanks a lot for you fast response.

I did some experiments regarding the presence of the "standard" binding elements. I removed the w:databinding element from

Code: Select all
              <w:sdtPr>
                <w:alias w:val="Price"/>
                <w:tag w:val="price=price&amp;od:xpath=x4&amp;od:finish=t_db"/>
                <w:id w:val="1418037951"/>
                <w:placeholder>
                  <w:docPart w:val="DefaultPlaceholder_22675703"/>
                </w:placeholder>
                <w:dataBinding w:xpath="/invoice[1]/items/item[1]/price" w:storeItemID="{8B049945-9DFE-4726-9DE9-CF5691E53858}"/>
                <w:text/>
              </w:sdtPr>


in your invoice.docx example and now I get the same result as with my own document. It seems that without this element we never reach the code that rewrites the xpath for the inner content controls:

https://github.com/plutext/docx4j/blob/VERSION_11_4_8/docx4j-core/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java#L1394

On the other hand your comment seems to suggest that this is optional:
https://github.com/plutext/docx4j/blob/VERSION_11_4_8/docx4j-core/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java#L1274
Code: Select all
// could be a w15 binding


I don't understand why the w:dataBinding is needet because the same info can be optained from the Xpaths custom xml part.

Re: Re-Processing document with repeats?

PostPosted: Tue Sep 20, 2022 9:24 am
by jason
Great to see you are making progress :-)

Evidently you need w:dataBinding for the normal (not repeat or condition) content controls.

This allows Word to do two way binding (if/when the docx is opened in Word), that is, copy edits a user might make on the document surface into the XML part.

And as you've found out, the OpenDoPE run time code expects it.

But please note the "w" namespace is different to the "w15" namespace. The latter isn't required. This w15 namespace was introduced some time later (for the Word 15 release) by Microsoft to support repeating table rows. See further https://www.docx4java.org/blog/2015/01/ ... rime-time/ and https://www.docx4java.org/blog/2015/01/ ... -now-what/

Re: Re-Processing document with repeats?

PostPosted: Tue Sep 27, 2022 1:37 am
by mgiepz
Hi Jason,
thank you for all the input. I was finally able to achieve to generate a valid OpenDoPE docx with repeats with my add-in. As it turned out the standard databinding elements were missing as I thought they were not necessary. Also there was some other malformed xml that got inserted when I tried to wrap the repeat around a table row, which I was able to solve now.

I didn't check the regenerating process yet. This will come next.

best regards,
Marius