Forum


Replies: 4   Views: 865
Bulkprocessing replace all variables in the same text tag
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by michael.stubenvoll  · 18-11-2021 - 10:28

Thank you very much!

While testing we now found a problem when using a variable multiple times in a document. Because there can be multiple nodes with the same variable the inner foreach loop should not refresh the document. That's because the nodes that are being iterated and modified still belong to the original document. So the added lines should be inserted a few lines below at the end of the outer foreach loop.  

foreach ($variables as $variable => $value) {
            // ...
         foreach ($foundNodes as $node) {
               // ...
         }
         $dom = $this->generateDomDocument($dom->saveXML());
         $xpath = new \DOMXPath($dom);
         $xpath->registerNamespace('w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
}

Is this problem known? And is this a viable fix or is there a different solution to the underlying problem?

Regards.