To my surprise the following works with an XQuery Saxon 9.8.0.12 (tried EE and HE) transformation scenario in oXygen 20.1:
Code: Select all
doc('data:application/xml,' || encode-for-uri('<root><foo>bar</foo></root>'))//foo
Code: Select all
<foo>bar</foo>
That is a surprise as running Saxon 9.8 from the command line gives an error "FODC0002: I/O error reported by XML parser processing ... unknown protocol: data".
So my first question is: is that support for data URIs something added on top of Saxon in oXygen or is that a particular Saxon configuration?
For which functions or in which contexts should the use of data URIs work?
I also get it to work for further simple but kind of meaningless stuff like
Code: Select all
unparsed-text('data:text/plain,' || encode-for-uri('This is a test.'))
Code: Select all
let $query as xs:string := 'xquery version "3.1"; module namespace foo = "http://example.com/foo"; declare function foo:f1() as xs:string { "test" };',
$module as map(*) := load-xquery-module('http://example.com/foo', map { 'location-hints' : 'data:application/xquery,' || encode-for-uri($query) })
return $module?functions(QName('http://example.com/foo', 'f1'))(0)()
Should the above work? Why does it fail, and why with that error?
Interestingly enough, when I try to reduce the sample to something that does not use data URIs but the same inline code with
Code: Select all
let $query as xs:string := 'xquery version "3.1"; module namespace foo = "http://example.com/foo"; declare function foo:f1() as xs:string { "test" };',
$module as map(*) := map { 'functions' : map { QName('http://example.com/foo', 'f1') : map { 0 : function() { 'test' }}}}
return $module?functions(QName('http://example.com/foo', 'f1'))(0)()
So I am not sure whether the error I get with the previous attempt of "load-xquery-module" is due to problems with the use of a "data" URI in the location-hints or due to the way oXygen calls/uses Saxon. I hope you can clarify that.
As a last test I tried to avoid inlining the XQuery code but still using a data URI with
Code: Select all
let $query as xs:string := unparsed-text('test2018081903.xq'),
$module as map(*) := load-xquery-module('http://example.com/foo', map { 'location-hints' : 'data:text/plain,' || encode-for-uri($query) })
return $module?functions(QName('http://example.com/foo', 'f1'))(0)()
As I can't run such code directly with Saxon as there I get a "java.net.MalformedURLException: unknown protocol: data" I would like to know whether that error is within Saxon or oXygen using Saxon.
For completeness, the sample test2018081903.xq simply has
Code: Select all
xquery version "3.1"; module namespace foo = "http://example.com/foo"; declare function foo:f1() as xs:string { "test" };