468,765 Members | 1,005 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

XPATH document-function doesn't support absolute filepaths

Hallo!

When using the XPATH document() function to load a new XML document, we
are coming across problems, because XALAN seems to have problems with
absolute paths. XALAN always assumes that the path is relative to the
current directory. So if we e.g. are in "c:\xslt_scripts" and are trying
to load an XML file from "c:\xml_files\test.xml" it ist trying to open a
file with the following absolute path:
"c:\xslt_scripts\c:\xml_files\test.xml".
The weird thing however is that in some cases it works. Actually we
configure which XML file is to be used in a Java-Bean config-file. When
we just paste the full path to the current location of the XML file into
the config file, it works, but when we construct the path using a
place-holder (@xmlDir) which is further replaced with the actual
Dir-path, it doesn't work, although the path to the XML file - displayed
in the log of our application - is still the same.

Has someone experienced this strange behaviour too?
Any help appreciated!
Vitali Gontsharuk
Aug 17 '05 #1
4 5653


Vitali Gontsharuk wrote:

When using the XPATH document() function to load a new XML document,
XPath 1.0 has no function named document, only XSLT 1.0 knows that function.
we
are coming across problems, because XALAN seems to have problems with
absolute paths. XALAN always assumes that the path is relative to the
current directory. So if we e.g. are in "c:\xslt_scripts" and are trying
to load an XML file from "c:\xml_files\test.xml" it ist trying to open a
file with the following absolute path:
"c:\xslt_scripts\c:\xml_files\test.xml".


I don't know what Xalan does but usually the argument is treated as a
URI reference and "c:\xml_files\test.xml" is not a URI so you would at
least need
file:///C:/xml_files/test.xml
if you want to load from the file system.

As for resolving relative URIs, the base URI used depends on the second
argument to the document function, here is what the spec says about
that: "The URI reference may be relative. The base URI (see [3.2 Base
URI]) of the node in the second argument node-set that is first in
document order is used as the base URI for resolving the relative URI
into an absolute URI. If the second argument is omitted, then it
defaults to the node in the stylesheet that contains the expression that
includes the call to the document function."
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 17 '05 #2
Martin Honnen wrote:


Vitali Gontsharuk wrote:

When using the XPATH document() function to load a new XML document,

XPath 1.0 has no function named document, only XSLT 1.0 knows that
function.
we

are coming across problems, because XALAN seems to have problems with
absolute paths. XALAN always assumes that the path is relative to the
current directory. So if we e.g. are in "c:\xslt_scripts" and are
trying to load an XML file from "c:\xml_files\test.xml" it ist trying
to open a file with the following absolute path:
"c:\xslt_scripts\c:\xml_files\test.xml".

I don't know what Xalan does but usually the argument is treated as a
URI reference and "c:\xml_files\test.xml" is not a URI so you would at
least need
file:///C:/xml_files/test.xml
if you want to load from the file system.

As for resolving relative URIs, the base URI used depends on the
second argument to the document function, here is what the spec says
about that: "The URI reference may be relative. The base URI (see [3.2
Base URI]) of the node in the second argument node-set that is first
in document order is used as the base URI for resolving the relative
URI into an absolute URI. If the second argument is omitted, then it
defaults to the node in the stylesheet that contains the expression
that includes the call to the document function."

OK, now I've tried it in any combinations and it still doesn't work!!!
Actually I still have some problems understanding, how the function
should be called if i need to load a document whose absolute path name
is e.g. "C:\xml_files\test.xml":
- document('file://c:/xml_files/test.xml')?
- document('file://c:\xml_files\test.xml')?
- document('file:///c:/xml_files/test.xml')?
- document('file:///c:\xml_files\test.xml')?

or with two parameters (according to the spec, this shouldn't be the
case, but I still tried this...):
- document('test.xml','file://c:\xml_files')?
- document('test.xml','file://c:\xml_files\')?
- document('test.xml','file://c:/xml_files')?
- document('test.xml','file://c:/xml_files/')?
- document('file://test.xml','file://c:/xml_files/')?
etc...
Could anyone make that function work with absolute paths???

Thanks,
Vitali

Aug 19 '05 #3
In article <de**********@wsc10.lrz-muenchen.de>,
Vitali Gontsharuk <go******@in.tum.de> wrote:
Actually I still have some problems understanding, how the function
should be called if i need to load a document whose absolute path name
is e.g. "C:\xml_files\test.xml":
This one:
- document('file:///c:/xml_files/test.xml')?


-- Richard
Aug 19 '05 #4
Richard Tobin wrote:
In article <de**********@wsc10.lrz-muenchen.de>,
Vitali Gontsharuk <go******@in.tum.de> wrote:
Actually I still have some problems understanding, how the function
should be called if i need to load a document whose absolute path name
is e.g. "C:\xml_files\test.xml":


This one:
- document('file:///c:/xml_files/test.xml')?


-- Richard

Now I figured out what the problem was: within Java Xalan had been
explicitly preconfigured with a specific directory as basepath - that's
why even absolute file paths were considered as relative.
But thanks for your answers!
Aug 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joshua Beall | last post: by
reply views Thread by bdinmstig | last post: by
3 posts views Thread by Johannes Koch | last post: by
4 posts views Thread by Son KwonNam | last post: by
1 post views Thread by Hollywood | last post: by
8 posts views Thread by Joe Pannone | last post: by
3 posts views Thread by SD | last post: by
14 posts views Thread by Mikhail Teterin | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.