I'm migrating XSLT functions for working with DITA documents to XQuery. As part of this function package I have functions that resolve URI references from one document to another. This involves creating absolute URLs from relative URLs using a document or element as the base URI context.
The problem I'm running into is that the URLs used within BaseX are not absolute (that is, they don't start with "/".
For example, document-uri(root($node)) returns:
dfst^dfst-sample-project^develop/docs/tests/complex_map/complex_map.ditamap
not
/dfst^dfst-sample-project^develop/docs/tests/complex_map/complex_map.ditama p
This causes a problem for resolve-uri(), used like this:
resolve-uri($topicResourcePart, base-uri($topicref))
This fails under BaseX:
[FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo....
These libraries are intended to be generic XQuery so I'm trying to avoid having any BaseX-specific logic in these functions.
Is there workaround or other solution to this?
Obviously, this way of representing document URIs internally is not something that could be easily changed but it is definitely a problem in terms of the expectations of URI handling by built-in XQuery functions.
Thanks,
Eliot ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
Hi Eliot,
This fails under BaseX:
[FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo....
I think it also fails if the base URI starts with a slash. Try this for example:
resolve-uri('abc.xml', '/path/def.xml')
What result you would expect from this query, given that it did not raise an error?
Using string operations could be an alternative...
"replace($baseURI, '/[^*]+$', $topicResourcePart)
...but I am not sure if this fulfills all needs.
Christian
Obviously, this way of representing document URIs internally is not something that could be easily changed but it is definitely a problem in terms of the expectations of URI handling by built-in XQuery functions.
Thanks,
Eliot ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
Yes, resolve-uri('foo', '/bar') also fails.
If I do base-uri('/foo') I get "file:/foo", which is a bit unexpected since I'm in the context of the BaseX system and not in the context of the file system (at least that's why my head thinks: BaseX itself may have different ideas).
I think what I expect is either that BaseX interprets all URIs not prefixed with "file:/" as relative to the BaseX repository, so rather than "dbname/path/to/doc" the URL format would be"/dbname/path/to/doc" or there is a BaseX-specific scheme that is used with all absolute URIs, e.g. "basex:/dbname/path/to/doc". That would remove any potential ambiguity about the intent of a given URL.
Thus, document-uri(root($node)) would return either "/foo/bar" or "basex:/foo/bar", but not "foo/bar".
Cheers,
E. ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
On 4/17/15, 12:07 PM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi Eliot,
This fails under BaseX:
[FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo....
I think it also fails if the base URI starts with a slash. Try this for example:
resolve-uri('abc.xml', '/path/def.xml')
What result you would expect from this query, given that it did not raise an error?
Using string operations could be an alternative...
"replace($baseURI, '/[^*]+$', $topicResourcePart)
...but I am not sure if this fulfills all needs.
Christian
Obviously, this way of representing document URIs internally is not something that could be easily changed but it is definitely a problem in terms of the expectations of URI handling by built-in XQuery functions.
Thanks,
Eliot ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
BTW, my workaround for now is to check to see if base-uri() returned an absolute URL and if it did not, I use my existing code for constructing URLs to simply combine the relative URL with the parent of the result of base-uri(), otherwise I use resolve-uri(). That's a sufficiently-general solution that is not explicitly BaseX specific.
Cheers,
E.
————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
On 4/17/15, 12:07 PM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi Eliot,
This fails under BaseX:
[FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo....
I think it also fails if the base URI starts with a slash. Try this for example:
resolve-uri('abc.xml', '/path/def.xml')
What result you would expect from this query, given that it did not raise an error?
Using string operations could be an alternative...
"replace($baseURI, '/[^*]+$', $topicResourcePart)
...but I am not sure if this fulfills all needs.
Christian
Obviously, this way of representing document URIs internally is not something that could be easily changed but it is definitely a problem in terms of the expectations of URI handling by built-in XQuery functions.
Thanks,
Eliot ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
basex-talk@mailman.uni-konstanz.de