You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Taras Tielkes <ta...@xs4all.nl> on 2001/09/19 01:26:48 UTC

JAXP URIResolver is being called twice?

Hi,

I'm registering a custom URI resolver in the XSLT processor that shipped
with JAXP 1.1(.1?).

Here's the source (pardon the messy layout):
------------------------
import java.io.StringReader;
import java.io.FileOutputStream;

import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;

public class CustomURIResolver implements URIResolver
{
public static void main(String[] args)
{
try
{
String sourceXML = "<x/>";

StreamSource xsl = new StreamSource("resolve.xsl");
StreamSource xml = new StreamSource(new
StringReader(sourceXML));

TransformerFactory tf =
TransformerFactory.newInstance();

Transformer t = tf.newTransformer(xsl);
t.setURIResolver(new CustomURIResolver());

StreamResult r = new StreamResult(new
FileOutputStream("c:\\out.xml"));

t.transform(xml, r);
}
catch(Exception e)
{
e.printStackTrace();
}
}

public Source resolve(String relURI, String base)
{
System.err.println("[resolve] relURI = " + relURI + " + base
= " + base);

return null;
}
}
------------------------

The XSL is very simple:
------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:apply-templates select="document('dummy')"/>
</xsl:template>

</xsl:stylesheet>
-------------------------

The output however, is unexpected:
-------------------------
[resolve] relURI = dummy + base = file:/C://resolve.xsl
[resolve] relURI = dummy + base = file:/C://resolve.xsl
file:/C://resolve.xsl; Line 5; Column -1; Can not load requested doc:
C:\dummy (The system cannot find the file specified)

Of course, I understand the last line, but why is my resolver called twice?
Even when I actually return a valid Source subclass instance, the same
behaviour can be observed.

Am I missing something obvious?

Thanks in advance,
Taras Tielkes