I am using xalan-j_2_3_1 and have created a URIResolver to deal with my
special paths. When document() is called with a trailing element name
the uri is resolved 3 times. It seems like a bug, but maybe I am just
missing something? I have been working with xalan for only the last
couple of days. I have searched the mailing list archives and xalan site
and have found very little that actually discusses the URIResolver. If
there is another place to look for information I would appreciate
knowing about it.
Here is the code for a test app that demonstrates this behavior.
/****************/
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class test {
static public void main(String[] args) {
System.out.println("XALAN XSLT TEST");
try {
// Create xsl source
StreamSource xslSource = new StreamSource(new File(args[0]));
// Create xml source
StreamSource xmlSource = new StreamSource(new File(args[1]));
// Create transformer
TransformerFactory tFactory = TransformerFactory.newInstance();
/// output the xslt
Transformer transformer = tFactory.newTransformer(xslSource);
transformer.setURIResolver(new myURIResolver());
System.out.println("Transform");
transformer.transform(xmlSource, new StreamResult(new
File("output.xml")));
} catch ( Exception e ) {
e.printStackTrace();
}
System.out.println("\nDONE");
}
public static class myURIResolver implements URIResolver {
// URIReslover
public Source resolve(String href, String base)
throws TransformerException {
if ( !href.startsWith("hps://") )
return null;
System.out.println("got href: '" + href + "' base: '" + base +
"'");
StreamSource source =
new StreamSource(
new StringReader(
"<root><element>static value</element></root>")
);
return source;
}
}
}
/****************/
Here is the stylesheet:
/****************/
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:value-of
select="document('hps://my/path/goes/here')/elementname"/>
</xsl:template>
</xsl:stylesheet>
/****************/
Here is the console output:
/****************/
XALAN XSLT TEST
Transform
got href: 'hps://my/path/goes/here' base: 'null'
got href: 'hps://my/path/goes/here' base: 'null'
got href: 'hps://my/path/goes/here' base: 'null'
DONE
/****************/
Thanks,
Josh Canfield