xquery multiple output files?
Added by Anonymous about 19 years ago
Legacy ID: #3327921 Legacy Poster: coojam (coojam)
From what I read on the web and from the saxon documentation there seems to be neither a standard xquery way to output to multiple files nor a saxon extension for it. Before I try and write an extension can someone point me to the existing way of doing it please - I can't be the first person to want to do this? I am sure there is a way but I just can't find it. Thanks, Matty.
Replies (4)
Please register to reply
RE: xquery multiple output files? - Added by Anonymous about 19 years ago
Legacy ID: #3328117 Legacy Poster: Michael Kay (mhkay)
You're correct that there's no standard way of doing this. You could do it in Saxon with the help of some Java application code: write your query to generate a sequence of documents: for $in in 1 to 10 return document { .... } and then in the Java application, process this sequence of documents and serialize each one separately. It's not as flexible as xsl:result-document in XSLT but it can be done. Michael Kay
RE: xquery multiple output files? - Added by Anonymous about 19 years ago
Legacy ID: #3328143 Legacy Poster: coojam (coojam)
The multiple document approach does not appear to have a way of setting a property to determine the file name. I was thinking of writing an extension function along the lines of 'write-to' in the QEXO xquery implementation. Are there any reasons why that approach is not a good one that I should be aware of?
RE: xquery multiple output files? - Added by Anonymous about 19 years ago
Legacy ID: #3328328 Legacy Poster: Michael Kay (mhkay)
You could do it with a write-to extension function. I am always wary of extension functions with side-effects, however. Someday a user will do let $x := write-to(.....) return () and wonder why the document didn't get written. (Answer, because the variable $x wasn't used and therefore wasn't evaluated.
RE: xquery multiple output files? - Added by Anonymous about 19 years ago
Legacy ID: #3334439 Legacy Poster: Michael Kay (mhkay)
There is actually another solution, which exploits the fact that with Saxon you can invoke XSLT from XQuery, and XSLT provides access to the xsl:result-document instruction. For example: (: invoke an XSLT transformation using extension functions :) let $splitter := saxon:compile-stylesheet( document { <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="book"> <xsl:result-document href="book{{position()}}.xml"> <xsl:copy-of select="."/> </xsl:result-document> <success>See books<xsl:value-of select="position()"/>.xml</success> </xsl:template> </xsl:stylesheet> } ) let $results := document{ <books>{ doc('bib.xml')//book[@year < 1999] }</books> } return <a>{saxon:transform($splitter, $results)}</a>
Please register to reply