Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
I tried to use the collection() function to get all documents in a directory but it throws this error:
(err:FODC0004) Unknown collection file:/C:/VSProjects/SaxonAsp/SampleWebsite/App_Data/posts/
Line number: 6
This is line 6:
<xsl:variable name="posts" select="collection('../App_Data/posts/')"/>
I've used the collection() function before via command line without problems. I hope I'm not missing something too obvious.
The directory URI is fine, tested on windows explorer.
The XsltCompiler.BaseUri is set to the stylesheet URI.
Ran the stylesheet via command line without problems.
Maybe is not a problem with the base uri, because it's resolving fine. Also, I can use the doc() function fine.
I've tried with the following Saxon-B versions: 18.104.22.168, 22.214.171.124
It seems that when using the .NET API, the CollectionURIResolver in use is always the DotNetCollectionURIResolver, and this cannot easily be changed (but see below). This will only resolve a collection URI if the URI has been registered using Processor.RegisterCollection().
I think the reason this mechanism was introduced was to satisfy the requirement in the spec that when you retrieve a document using collection(), then get its URI using document-uri(), then use that as an argument to doc(), you get the same document back. This can only be made to work if URIs returned by the collection URI resolver are dereferenced using the same XmlResolver as is used for the doc() function.
But clearly this is not very friendly, and it's clearly inappropriate that it should be possible to process a directory by name when using the command line, but not when using the API. I think that to fix this, I will change the DotNetCollectionURIResolver so that if the URI has not been registered, the code falls back to handle it using the (Java) StandardCollectionURIResolver, which handles URIs that refer to a directory.
I won't be able to fix this instantly, however.
In the meantime, it might be possible to work around it by getting the Processor to use the Java collection URI resolver instead. Try this:
If you do this, RegisterCollection() will not work.
If it works from the command line but not from the API, then the most likely explanation is that you are getting the base URI of the stylesheet module wrong.
Is the directory named in the error message
the directory you actually want?
I think the most likely cause is that you are processing the stylesheet without giving Saxon its base URI; without that, relative URIs such as ../App_Data/posts cannot be resolved.