haggis78
haggis78

Reputation: 73

Can XQuery construct and save an output document when run in oXygen?

I am running XQuery 3.1 in oXygen to create output HTML from input XML.

When running XQuery in eXist-DB, it's possible to declare the html framework and FLWOR statements inside it as a variable, something like this:

declare variable $ThisFileContent:=
<html><head></head><body>{FLWOR statement here}</body></html>;

let $filename := "term-finder-output.html"
let $doc-db-uri := xmldb:store("/db/myOutput", $filename, $ThisFileContent, "html")
return $doc-db-uri

(credit: https://newtfire.org/courses/tutorials/XQueryExercise5-TA.html)

...and when you run that, it actually creates the file from scratch in the location indicated in the filepath and saves the output into it. That's what I want to do, except running oXygen in a local environment without a db setup, just creating a file in a regular directory. But that doesn't work in oXygen, since it doesn't recognize what xmldb:store() is. (I also tried oxygen:store(), fn:store(), saxon:store() and just plain store(), none of which works. Maybe one would if I knew a correct namespace to declare?)

In short, I want to do in XQuery exactly what xsl:result-document does in XSLT.

I see that this was discussed as a possible feature for Saxon as long ago as 2007, but I haven't found any updates: https://saxonica.plan.io/boards/2/topics/391

(Why bother? Yes, I can just use the dropdown windows at the top of the oXygen XQuery debugger perspective to save the output file. But with multiple XQueries in a project, it's easy to get mixed up about what XQuery generates what output HTML, and to save it as the wrong output. I want to write it in to my XQuery so it automatically does the right thing without that potential for human error.)

Upvotes: 0

Views: 72

Answers (1)

Michael Kay
Michael Kay

Reputation: 163595

The only way to generate multiple output files using Saxon's XQuery is to use the XQuery update fn:put(), or the EXPath file module, or some other extension function. All these approaches are problematic from the point of a query being purely functional and side-effect-free.

For a single output file you can set the destination in the -o option on the command line, or the equivalent in Oxygen's transformation scenario.

Upvotes: 1

Related Questions