XQuery transformation save/stored in eXist-db path

Having trouble installing Oxygen? Got a bug to report? Post it all here.
larsS
Posts: 18
Joined: Mon Sep 13, 2021 10:41 am

XQuery transformation save/stored in eXist-db path

Post by larsS »

Hello,
I have the following problem: I need to copy an open ('${current_file}') XML with an XQuery transformation and modify a few elements before. This copy should be stored in the eXistdb and not locally. In addition, the file should then be opened directly. As it would be with locally stored transformation results.

This two options (I think) I have:
  • I can have the file copied with a XQuery within eXist-db via the integration of eXist-db and control the transformation within eXist-db. But then the file does not open automatically, because I cannot tell the editor to open it directly without the save operation.
  • I tried to give the database path (oxygen:/eXist-db%20localhost$database/db/~) as URI or '${cdfu}' then it just ignores the 'oxygen:' protocol and saves it inside the software installation path. With the WebDav connection URI I have the same result. With the editor variable '${cfd}' the result is saved to Temp.
Is there any kind of solution?

XML Author 21.1, build 2019120214

Thank you very much.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XQuery transformation save/stored in eXist-db path

Post by Radu »

Hi,
Oxygen 21.1 is in our end of life stage and we no longer support it in any way:
https://www.oxygenxml.com/eol.html
I do not quite understand your post.
So you have an XQuery file, right? And it's saved on the Exist server, right? So it's not a local XQuery file.
Is it an XQuery update file (which also makes changes to an XML document)? Does it use the document() function to load an XML document?
Do you pass a parameter to the XQuery file telling it the URL of the file to open using the document() function?
When you run the XQuery transformation in Oxygen, do you run it using the Exist Data source connection (on the server side) or using the Saxon 9 XSLT/XQuery processor (which runs it in the client side)?
If you run the XQuery using the Exist Data source connection, then it runs on the server side and on the server side the server cannot access files using Oxygen's specific "oxygen:" URL protocol.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
larsS
Posts: 18
Joined: Mon Sep 13, 2021 10:41 am

Re: XQuery transformation save/stored in eXist-db path

Post by larsS »

Hello,
first of all, I didn't know that this forum is only for direct support and that the support for 21.1 no longer exists.
Thanks you anyway for your reply.

I have a local xQuery file which are executed with the eXist-db source connection:

Code: Select all

xquery version '3.1';
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace xmldb = "http://exist-db.org/xquery/xmldb";
declare namespace util = "http://exist-db.org/xquery/util";

declare variable $inputfilename as xs:string external;
declare variable $outputpath as xs:string := "/db/projects/data";
declare variable $currentDate as xs:string := replace(substring-before(string(fn:current-date()),"Z"),"-","");
declare variable $countFilename as xs:integer := count(for $i in xmldb:get-child-resources($outputpath) where matches($i, $currentDate) return $i);
declare variable $outputfilename as xs:string := replace(substring-before(string(fn:current-date()),"Z"),"-","")||"-"||$countFilename+1||".xml";
declare variable $webDavBaseUrl as xs:string := "http://localhost:8080/exist/webdav";

declare option output:method "xml";
declare option output:indent "yes";

declare function local:transform($newFilePath as xs:string) as xs:boolean {
    if ($newFilePath ne '') 
    then (
        let $doc-node := doc($newFilePath)
        let $id := $doc-node/zettel/@id
        let $lemma-node := $doc-node//belegform/form
        return (
            try {
                update delete $lemma-node/text(),
                update value $id with "b"||util:uuid(),
                for $ref in $doc-node//werkBelegstelle/ref
                return
                (
                    update delete $ref/text()
                ),
                true()
            }
            catch * 
            { false() }
        )
    )
    else
    ( false() )
};

let $store := xmldb:store($outputpath,$outputfilename,doc($outputpath||"/"||$filename))
let $transform := local:transform($store)
return
element root {
    element copiedto {$store},
    element tranformed {$transform},
    element url {$webDavBaseUrl||$outputpath||"/"||$outputfilename}
}
The opened XML file is located in eXist-db collection tree, which was mounted with the wizard through the xmldb interface in Oxygen Author.
The script stored a copy of the current opened document and updates the copy with the update extensions of eXist-db. The external parameter $inputfilename is passed through as a parameter with the editor variable ${cfne}. This works flawlessy.

And now, back to my question, is it possible to have the newly created (copied) file automatically in Oxygen Author?

For a not so convenient solution , I have added the WebDav address in the output, which can be opened by "Open URL...". Would be nice if this extra step was not necessary.

Thank you very much.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XQuery transformation save/stored in eXist-db path

Post by Radu »

Hi,
I think I understand now, so by running the XQuery update script on the server side (with the Exist connector from Oxygen) you generate files which have variable file names (depending on the current date). And it would be convenient for you to have Oxygen open that generated file after the publishing process.
Your workaround with showing the created XML URL in the results makes sense.
I'm afraid I do not have a good idea about how to make this work seamless, Oxygen has no idea what the script does, it just delegates to the Exist database driver to execute it. In the XQuery transformation scenario there is an "Output" tab where you can decide to open a certain file after running it but again the file name is decided inside the script depending on some XQuery specific logic.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
larsS
Posts: 18
Joined: Mon Sep 13, 2021 10:41 am

Re: XQuery transformation save/stored in eXist-db path

Post by larsS »

Hey Radu,
thanks for the reply.

I understand that the Xquery script can return values, but the oXygen Author/Editor can't interpret them further, so I can't tell i.e. this is a file path, like in this case, and the transformation scenario only displays the result as a sequence. Check.

(1) But is it possible in anyways to tell the transformation scenario an eXist-db address/path?
Since the xmlrpc (neither the xmlrpc API) as well as the oxygen: protocol did not work.
(2) I presume it would also not allow a "Save file as..." via WebDav, or would it? As far as I understand it, the exact file that was saved under "Save file as..." is opened in the following.
(3) So as long as I can't pass the file into eXist-db collection tree via the scenario, as long as it would not be possible to open the file automatically, do I understand correctly?

Thanks for the further replies. :)
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XQuery transformation save/stored in eXist-db path

Post by Radu »

Hi,

Please see some answers below:
(1) But is it possible in anyways to tell the transformation scenario an eXist-db address/path?
Since the xmlrpc (neither the xmlrpc API) as well as the oxygen: protocol did not work.
I'm not sure what you mean by "tell", you can pass parameters to the xquery script using the scenario but there is probably not much to do with an "oxygen:" specific URL in the xquery script.
Oxygen uses the Exist DB API to run the XQuery, I assume the Exist DB API we are using passes the XQuery script to the server side and runs it there. We have no control over the execution of the XQuery script. And the Exist server does not know what "oxygen:" specific URLs are as it has no handling for Oxygen's specific URL protocols.
(2) I presume it would also not allow a "Save file as..." via WebDav, or would it? As far as I understand it, the exact file that was saved under "Save file as..." is opened in the following.
We do not have the possibility to use the "Save as" to save to a remote location, we have a registered an internal issue to implement this but we have not yet done this.
(3) So as long as I can't pass the file into eXist-db collection tree via the scenario, as long as it would not be possible to open the file automatically, do I understand correctly?
Oxygen has support for Java based plugins, we have APIs to open resources in Oxygen (from the local disk or from a server), make changes to them, but we do not have the API to intercept the end of a transformation scenario's execution and then maybe open a certain resource.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
larsS
Posts: 18
Joined: Mon Sep 13, 2021 10:41 am

Re: XQuery transformation save/stored in eXist-db path

Post by larsS »

Hello Radu,
thank you very much for this detailed answer.

I understand and hope the best for the remote "Save As..." solution.
Then I have to continue with the XQuery output in the above solution first.
Then I will diligently follow the next version changes :)

Regards,
Lars
Post Reply