writing to file using XQuery

Is it possible to write the result to a file(text or xml) using XQuery?
For eg:

for $b in document(“bib.xml”)/bib/book
where $b/publisher = “Addison-Wesley”
return $b

instead of return $b is it possible to write the result to another new file?

Thank You

The XQuery language in principle allows you to return a sequence of documents as the result of a query, rather than just a single document. But it doesn’t allow you to say what you want to happen to those documents once they are returned - that’s up to the receiving application. Nor does it allow you to generate one document while you are in the middle of generating another (as xsl:result-document in XSLT 2.0 does).

I think you’ll have to look again at your requirements and find a different way of tackling them. Some kind of postprocessing of the query results may be the answer.

Michael Kay