Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

collection() function .NET API

Max Toro
2008-09-18
2012-10-08
  • Max Toro
    Max Toro
    2008-09-18

    Hello Michael,
    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/
    URI: file:///C:/VSProjects/SaxonAsp/SampleWebsite/admin/post_list.axt
    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.

     
    • Max Toro
      Max Toro
      2008-09-18

      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: 9.0.0.6, 9.1.0.1

       
      • Michael Kay
        Michael Kay
        2008-09-20

        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:

        processor.setProperty(
        "http://saxon.sf.net/feature/collection-uri-resolver-class",
        "net.sf.saxon.functions.StandardCollectionURIResolver")

        If you do this, RegisterCollection() will not work.

        Michael Kay

         
    • Michael Kay
      Michael Kay
      2008-09-18

      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

      file:/C:/VSProjects/SaxonAsp/SampleWebsite/App_Data/posts/

      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.