How to call xpath document() with resolvable base references
I have an xml file which contains the name of another xml file:
within my stylesheet, I detect @href and open the document via the document() function
document(@href)
should call my URIResolver.resolve(fname,base) with base of the "Base URI of the node from which the the string of the first argument is calculated"
document(@href,.)
should call my URIResolver.resolve(fname,base) with base o开发者_JAVA百科f the "Base URI of the current node"
However in practice with Xalan/J
document(@href)
is blank
and
document(@href,.)
is giving current directory of my application
How do I set base so that my URIResolver can find the file?
Do note that this
document(@href)
It's equal to this
document(string(@href),@href)
and so maybe also to
document(string(@href),.)
From http://www.w3.org/TR/xslt#document:
When the document function has exactly one argument and the argument is a node-set, then the result is the union, for each node in the argument node-set, of the result of calling the document function with the first argument being the string-value of the node, and the second argument being a node-set with the node as its only member.
And then
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
But this:
document(string(@href))
Will use the stylesheet URI as resolver. Because:
When the first argument to the document function is not a node-set, the first argument is converted to a string as if by a call to the string function. This string is treated as a URI reference.
And then
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.
About the question
How do I set base so that my URIResolver can find the file?
Answer: use the second form and @xml:base
精彩评论