copy behavior ?
Monday, 5 March 2018 · 2 messages · last reply 6 Mar 2018
XS
Xavier-Laurent SALVADOR5 Mar 2018 18:21 #
Hi List,
I was working on multi replacement in Word docx.
I saw a strange behavior of "copy/modify".
I modified a document.xml and zip my folder content twice when I realized my template was wrong. I had to do it again and, after a hundred tries, I realized that copy/modify clause restored every time the old version of my content.
I had to close basexGui and relaunch it to have my changes taken in charge.
Hi List,
I was working on multi replacement in Word docx.
I saw a strange behavior of "copy/modify".
I modified a document.xml and zip my folder content twice when I realized my template was wrong. I had to do it again and, after a hundred tries, I realized that copy/modify clause restored every time the old version of my content.
I had to close basexGui and relaunch it to have my changes taken in charge.
Hi List,
I was working on multi replacement in Word docx.
I saw a strange behavior of "copy/modify".
Here is the fact:
I use Basex to modify document.xml then zip its folder in a docx file. After a few try, I needed to modify the original and start the process again. But it always zipped back the elder document.xml version I had corrected ... and deleted (I mean, the text inside $doc was the elder version, see infra). I had to close basexGui and relaunch it to have my new file taken in charge. And I have to do this every time I modify the original docx file.
Here is the code :
declare function local:mapp($path,$space){
for $x at $count in file:list($path)
order by $x descending
return
if (file:is-dir($path||'/'||$x))
then
let $s := count(analyze-string($path||$x,'/')//fn:match)
return
<zip:dir name = "{replace($x,'/$','')}">
{local:mapp($path||'/'||$x,$s)}
</zip:dir>
else
<zip:entry name="{$x}" src="{$path}/{$x}"/>
};
for $x in file:read-text-lines('liste.txt')
return
*copy $doc := doc("/document.xml")*
modify
for $w in $doc//w:t[.//text() contains text 'XXXXX'] return
replace value of node $w with replace($w,'XXXXX',$x)
return
(
file:write("document.xml",$doc)
,
let $rep := "/docx"
let $dest := "/tmp"
return
zip:zip-file(
<file xmlns="http://expath.org/ns/zip" href="{$dest}/courrier{$count}
.docx">
{local:mapp($rep,1)}
</file>)
)All the best,
X
--
Ce message peut contenir des informations réservées exclusivement à son destinataire. Toute diffusion sans autorisation est interdite. Si vous n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur et de détruire ce message.
*This email may contain material for the sole use of the intended recipient. Any forwarding without express permission is prohibited. If you are not the intended recipient, please contact the sender and delete all copies*.
--
Ce message peut contenir des informations réservées exclusivement à son destinataire. Toute diffusion sans autorisation est interdite. Si vous n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur et de détruire ce message.
*This email may contain material for the sole use of the intended recipient. Any forwarding without express permission is prohibited. If you are not the intended recipient, please contact the sender and delete all copies*.
--
Ce message peut contenir des informations réservées exclusivement à son destinataire. Toute diffusion sans autorisation est interdite. Si vous n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur et de détruire ce message.
*This email may contain material for the sole use of the intended recipient. Any forwarding without express permission is prohibited. If you are not the intended recipient, please contact the sender and delete all copies*.
CG
Christian Grün6 Mar 2018 22:11 #
Salut Xavier,
Salut Xavier,
Salut Xavier,
Please note that
fn:doc is a « deterministic » function, which means that the addressed document will only be retrieved once during the lifetime of your query. Replacing it with fetch:xml might already do the job.
If the data you are working with is not too huge, I recommend you to switch over to the Archive Module, which is better supported these days.
Hope this helps,
Hope this helps,
Hope this helps,
Christian
Xavier-Laurent SALVADOR <xavierlaurent.salvador at gmail.com> schrieb am Mo.,
5. März 2018, 18:22:Quoted text · Xavier-Laurent SALVADOR · 115 lines
> Hi List, > > I was working on multi replacement in Word docx. > I saw a strange behavior of "copy/modify". > > I modified a document.xml and zip my folder content twice when I realized > my template was wrong. I had to do it again and, after a hundred tries, I > realized that copy/modify clause restored every time the old version of my > content. > > I had to close basexGui and relaunch it to have my changes taken in charge. > > > Hi List, > > I was working on multi replacement in Word docx. > I saw a strange behavior of "copy/modify". > > I modified a document.xml and zip my folder content twice when I realized > my template was wrong. I had to do it again and, after a hundred tries, I > realized that copy/modify clause restored every time the old version of my > content. > > I had to close basexGui and relaunch it to have my changes taken in charge. > > > Hi List, > > I was working on multi replacement in Word docx. > I saw a strange behavior of "copy/modify". > > Here is the fact: > > I use Basex to modify document.xml then zip its folder in a docx file. > After a few try, I needed to modify the original and start the process > again. But it always zipped back the elder document.xml version I had > corrected ... and deleted (I mean, the text inside $doc was the elder > version, see infra). I had to close basexGui and relaunch it to have my new > file taken in charge. And I have to do this every time I modify the > original docx file. > > Here is the code : > > declare function local:mapp($path,$space){ > for $x at $count in file:list($path) > order by $x descending > return > if (file:is-dir($path||'/'||$x)) > then > let $s := count(analyze-string($path||$x,'/')//fn:match) > return > <zip:dir name = "{replace($x,'/$','')}"> > {local:mapp($path||'/'||$x,$s)} > </zip:dir> > else > <zip:entry name="{$x}" src="{$path}/{$x}"/> > }; > > for $x in file:read-text-lines('liste.txt') > return > *copy $doc := doc("/document.xml")* > modify > for $w in $doc//w:t[.//text() contains text 'XXXXX'] return > replace value of node $w with replace($w,'XXXXX',$x) > return > ( > file:write("document.xml",$doc) > , > let $rep := "/docx" > let $dest := "/tmp" > return > zip:zip-file( > <file xmlns="http://expath.org/ns/zip" > href="{$dest}/courrier{$count}.docx"> > {local:mapp($rep,1)} > </file>) > ) > > All the best, > > X > -- > Ce message peut contenir des informations réservées exclusivement à son > destinataire. Toute diffusion sans autorisation est interdite. Si vous > n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur > et de détruire ce message. > > *This email may contain material for the sole use of the intended > recipient. Any forwarding without express permission is prohibited. If you > are not the intended recipient, please contact the sender and delete all > copies*. > > -- > Ce message peut contenir des informations réservées exclusivement à son > destinataire. Toute diffusion sans autorisation est interdite. Si vous > n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur > et de détruire ce message. > > *This email may contain material for the sole use of the intended > recipient. Any forwarding without express permission is prohibited. If you > are not the intended recipient, please contact the sender and delete all > copies*. > > > -- > Ce message peut contenir des informations réservées exclusivement à son > destinataire. Toute diffusion sans autorisation est interdite. Si vous > n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur > et de détruire ce message. > > *This email may contain material for the sole use of the intended > recipient. Any forwarding without express permission is prohibited. If you > are not the intended recipient, please contact the sender and delete all > copies*. >
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery