documentPool and textResourcePool for SaxonJS.XPath.evaluate?
Added by Martin Honnen over 1 year ago
For SaxonJS 2.5, the documentation for the transform
function in https://www.saxonica.com/saxon-js/documentation2/index.html#!api/transform shows two options documentPool
and textResourcePool
that can be used together with SaxonJS.getResource
to ensure doc
or unparsed-text
calls access preloaded resources, allowing some kind of URI resolution.
Now I wonder whether the same exists for SaxonJS.XPath.evaluate: I have looked into loading the files in a Github Gist, using the asynchronous API that Github provides and that gives me a files
object of e.g. { "foo.xml" : { "content" : "<root>...</root>", "language": "XML", "type": "application/xml", "filename" : "foo.xml" }, "bar.xml" : { "content" : "<root>...</root>", "language": "XML", "type": "application/xml", "filename" : "bar.xml" } }
, now I would like my XPath (or XSLT code code called using fn:transform
) evaluated by SaxonJS.XPath.evaluate
to not to try to load e.g. foo.xml
over HTTP with doc('foo.xml')
but access it from a documentPool I set up from the Github Gist files
result.
Is anything like that possible in SaxonJS 2.5 for SaxonJS.XPath.evaluate
?
If not, is that planned for 3.0?
Replies (4)
Please register to reply
RE: documentPool and textResourcePool for SaxonJS.XPath.evaluate? - Added by Martin Honnen over 1 year ago
Everyone on vacation these days?
My suspicion is that SaxonJS 3 will give me some API to compile XSLT to SEF and then run that compiled SEF within the same Javascript program, so perhaps then I can just use the transform
function and documentPool
and/or textResourcePool
. If I ever manage to understand the various options the getResource
function has; the documentation https://www.saxonica.com/saxon-js/documentation2/index.html#!api/getResource say " Exactly one of location
, file
, or text
must be supplied" but also baseURI
property on the options "Absolute base URI for the resource. The base URI of the resource is automatically set when obtained using location or file. This option can be used to set the base URI for a resource supplied using text.".
Where is the base URI used or stored in the context of the Promise getResource
returns?
RE: documentPool and textResourcePool for SaxonJS.XPath.evaluate? - Added by Martin Honnen over 1 year ago
Still have no idea what the baseURI
is meant for or where it is used or stored in the context of passing text
to getResource
but for SaxonJS.transform
I finally got some documentPool
and textResourcePool
working to not make a request to a file or http URL but to use my string/text resource, both within the browser and with Node.js.
The key seems to be to store the absolute URL as the key in the Javascript object.
Still have no idea how to use that approach with SaxonJS.XPath.evaluate
.
RE: documentPool and textResourcePool for SaxonJS.XPath.evaluate? - Added by Norm Tovey-Walsh over 1 year ago
Everyone on vacation these days?
No. Sorry. Just … busy. I’ll try to look into this today, or early next week.
Be seeing you,
norm
--
Norm Tovey-Walsh
Saxonica
RE: documentPool and textResourcePool for SaxonJS.XPath.evaluate? - Added by Martin Honnen over 1 year ago
Based on some tests it seems the only place where a documentPool
and/or a textResourcePool
can be provided is SaxonJS.transform
.
Now after some pondering I thought I could just write a custom stylesheet that exposes fn:transform
in a public stylesheet function and then pass that SEF compiled stylesheet together with the wanted parameters in and would have a way to use a documentPool
and evaluate XSLT on the fly.
My simplest test case seems to fail, however, with SaxonJS 2.5 under Node.js with e.g.
Transformation failure: Error FODC0002 at exposeFnTransform.xsl#8
Cannot read file file:///C:/Users/marti/OneDrive/Documents/xslt/saxonjs-documentPool/doc1.xml - ENOENT: no such file or directory, open 'C:\Users\marti\OneDrive\Documents\xslt\saxonjs-documentPool\doc1.xml'
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
Error
at new L (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4109:549)
at Object.readFile (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4713:171)
at Object.readFile (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4108:74)
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4340:316
at a (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4338:294)
at Object.Ec (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4340:280)
at doc (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4513:298)
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4632:444
at Object.push (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4390:245)
at Object.e [as internalTransform] (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4988:69)
at transform (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4578:303)
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4632:444
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4625:263
at B (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4614:164)
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4614:412
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4627:186
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4618:382
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4670:281
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4618:382
at A (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4600:78)
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4672:459
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4646:463
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4618:382
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4670:281
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4618:382
at Object.push (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4390:245)
at e (C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:4987:320)
at C:\Users\marti\AppData\Roaming\npm\node_modules\saxon-js\SaxonJS2N.js:5015:342 {
message: "Cannot read file file:///C:/Users/marti/OneDrive/Documents/xslt/saxonjs-documentPool/doc1.xml - ENOENT: no such file or directory, open 'C:\\Users\\marti\\OneDrive\\Documents\\xslt\\saxonjs-documentPool\\doc1.xml'",
name: 'XError',
code: 'FODC0002',
xsltLineNr: '8',
xsltModule: 'exposeFnTransform.xsl'
}
although the documentPool
I have set up has e.g.
{
'file:///C:/Users/marti/OneDrive/Documents/xslt/saxonjs-documentPool/doc1.xml': <ref *1> Hf {
I guess I need to file that as a bug (or lack of feature).
Please register to reply