I think you've caught a bug in Xalan.  There seems to be a documentation bug in the 1.4 javadoc for TransformerFactory#setURIResolver.  Take a look at the getter which mentions the document function.
 
Thanks for the pointer.  I'll be wary of this if I use Xalan.
 
Steven
 
--------------------------------------------------------------
 
From: <matsuhashi@qu...>
 Re: URIResolver returns entire document instead of a subtree  
2006-05-17 05:23 
just to follow myself up, I tried the code with SAXON. I got (as you did)

returning the following node: leaf
<?xml version="1.0" encoding="utf-8"?>
<root>
   <leaf/>
</root>
Simply, Saxon and Xalan behaves differently.

MATSUHASHI,kazuaki
Japan

---------------------------------------------------
 
Hi, Steven,
I tried your code with Xalan in JDK1.4
With no change to your code, Xalan complained as follows:
      SystemId Unknown; Line #6; Column #-1; Can not load requested doc:
C:\temp\classes\any.uri (file not found)
      <?xml version="1.0" encoding="UTF-8"?>
Then I modified your code slightly :
    public static void main(String[] args) throws TransformerException,
ParserConfigurationException {
        TransformerFactory tfactory = TransformerFactory.newInstance();
        DocumentBuilder documentBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
-       tfactory.setURIResolver(new SampleResolver());
        Templates stylesheet = tfactory.newTemplates(new StreamSource(new
StringReader(XSLT)));
        Transformer transformer = stylesheet.newTransformer();
+      transformer.setURIResolver(new SampleResolver());
        DOMSource emptySource = new
DOMSource(documentBuilder.newDocument());
        transformer.transform(emptySource, new StreamResult(System.out));
    }
With this modification I got :
      returning the following node: leaf
      <?xml version="1.0" encoding="UTF-8"?>
      <leaf/>

Above experiment would imply that TrasformerFactory#setURIResolver() and
Transformer#setURIResolver() --- these two are not equivalent. I went back
to the JDK1.4 Javadoc. It was saying :
TranformerFactroy#setURIResolver()
      Set an object that is used by default during the transformation to
resolve URIs used in xsl:import, or xsl:include.
Transformer#setURIResolver();
      Set an object that will be used to resolve URIs used in document().
You wanted to resolve URL in document() fucntion so that you had to use
Transformer#setURIResolver() rather than
TransformerFactory#setURIResolver().
.... this was a lesson for me as well, Thank you, Steve, for the lesson.

MATSUHASHI, kazuaki
Japan


Blab-away for as little as 1/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.