Support #4809
openHow to use collections in Saxon-JS?
0%
Description
I have a very simple stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:template name="xsl:initial-template">
<xsl:apply-templates select="collection('file:/C:/temp/mydir')"/>
</xsl:template>
</xsl:stylesheet>
When I run this with Saxon-JS on the command-line (xslt3 "-xsl:test.xsl"), I get this error:
Transformation failure: Error FODC0002 at test.xsl#4
Unknown collection (no collectionFinder supplied)
Transformation failed: Error FODC0002 at test.xsl#4
Unknown collection (no collectionFinder supplied)
I have tried to run it with the API, and reading the documentation I see I can supply a collectionFinder in the transform method, but i'm not sure on how to implement it to get the same result as when running it in Saxon-Java.
Updated by Michael Kay about 4 years ago
Another user has been asking about this at
https://saxonica.plan.io/boards/3/topics/8050
and you may find that discussion helpful.
Essentially the implementation of collection() in Saxon-JS is absolutely minimal, since it just delegates the entire logic to the user-supplied CollectionFinder. To replicate the Saxon-J behaviour of processing directory contents recursively you'll have to implement it yourself. Sorry about that.
Updated by Debbie Lockett about 4 years ago
- Project changed from Saxon to SaxonJS
Updated by Jerry Jackson about 4 years ago
Michael Kay wrote:
Another user has been asking about this at
https://saxonica.plan.io/boards/3/topics/8050
and you may find that discussion helpful.
Essentially the implementation of collection() in Saxon-JS is absolutely minimal, since it just delegates the entire logic to the user-supplied CollectionFinder. To replicate the Saxon-J behaviour of processing directory contents recursively you'll have to implement it yourself. Sorry about that.
Can you show a minimal example of how to implement collectionFinder? From looking at the other question, it seems the expected return type is an array of whatever Saxon.getResource() returns, but my attempts to make it work have failed so far, and unfortunately the error messages are rather cryptic.
Updated by Martin Honnen about 4 years ago
As for a smaller sample using collectionFinder, see whether https://saxonica.plan.io/issues/4797#note-3 helps. It uses Saxon.getResource and await to preload an array of two document nodes and makes them available from collectionFinder.
Please register to edit this issue
Also available in: Atom PDF Tracking page