Caching of documents (loaded with the document() function) does not work when URI is relative ---------------------------------------------------------------------------------------------
Key: XALANJ-2429 URL: https://issues.apache.org/jira/browse/XALANJ-2429 Project: XalanJ2 Issue Type: Bug Components: XSLTC Reporter: Erin Harris The XSLTC processor caches documents based on their absolute URI but if there is a URIResolver and a relative URI was specified in the call to document() then the cached version will not be found. Using the test case below the output shows that there are two document loads (the message from the URIResolver appears twice): Loading: test_2.xml Loading: test_2.xml <?xml version="1.0" encoding="UTF-8"?><out> test_2.xml test_2.xml </out> However if the value of the doc variable in test.xsl is changed to an absolute path (such as 'd:/test/xslt/test_2.xml') then the output shows that there is only one load (the message from the URIResolver only appears once): Loading: d:/test/xslt/test_2.xml <?xml version="1.0" encoding="UTF-8"?><out> test_2.xml test_2.xml </out> This is because the document is cached using the relative URI but retrieved using the absolute URI. MyTransform.java ---------------- // Imported TraX classes import javax.xml.transform.TransformerFactory; import javax.xml.transform.Transformer; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; import javax.xml.transform.URIResolver; // Imported java classes import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.IOException; public class MyTransform { public static void main(String[] args) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { if (args.length < 2) { System.out.println("Usage: SimpleTransform <stylesheet> <input document>"); System.exit(1); } String xslName = args[0]; String xmlName = args[1]; System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"); TransformerFactory tFactory = TransformerFactory.newInstance(); tFactory.setURIResolver(new MyResolver()); Transformer transformer = tFactory.newTransformer(new StreamSource(xslName)); transformer.transform(new StreamSource(xmlName), new StreamResult(System.out)); } public static class MyResolver implements URIResolver { public Source resolve(String href, String base) { System.out.println("Loading: " + href); return new StreamSource(href); } } } test.xsl: ------------ <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="doc" select="'test_2.xml'"/> <xsl:template match='/'> <out> <xsl:value-of select="document($doc)/doc"/> <xsl:value-of select="document($doc)/doc"/> </out> </xsl:template> </xsl:stylesheet> test.xml: ------------ <?xml version="1.0"?> <doc> test.xml </doc> test_2.xml: -------------- <?xml version="1.0"?> <doc> test_2.xml </doc> -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]