0

Please take a look at the code of getAssociatedStylesheet(Source source, String media, String title, String charset) throws TransformerConfigurationException in TransformerFactoryImpl class:

The definition of above function is ignoring the XMLReader I've passed in as a argument through source parameter (which is essentially a SAXSource object). The above function is creating a new XMLReader after creating a new SAXParserFactory object. Because of this, the problem that we are facing is, that while parsing the input XML file, it goes on parsing the DOCTYPE section and the external DTD specified through Public ID and System ID. Now since, our XMLReader is not used to parse the XML file, the EntityResolver registered with the reader isn't used, and hence external DTD is not resolved, and therefore getAssociatedStylesheet function fails with an exception.

However, if you take a look at the other function public Templates newTemplates(Source source) throws TransformerConfigurationException in TransformerFactoryImpl class. This function specifically checks, if the source argument passed in is a SAXSource, and if it is, then if XMLReader is present in the source, then it doesn't create the new XMLReader object.

Is this a bug? Any thoughts?

XalanJ Version: 2.7.1 Source file path: src\org\apache\xalan\processor\TransformerFactoryImpl.java

Thanks! Harsh Gupta Adobe Systems

HarshG
  • 267
  • 1
  • 3
  • 10
  • You mention Xalan in your list of tags, but this is the only clue you are talking about Xalan. Even with this information, you need to say which version of Xalan (the JDK version or the Apache version?) There are many implementations of the JAXP transformation interfaces, so talking about the method names doesn't tell us which implementation you are using. – Michael Kay Aug 19 '13 at 16:16
  • Michael Kay: Sorry for the missed information... Have edited the question. – HarshG Aug 20 '13 at 10:39

2 Answers2

1

Since Saxon is perfectly able to find the associated stylesheet, with the registered custom entity resolver, therefore whenever transformation is happening with XalanJ, we are using Saxon for getting the associated Stylesheet.

And once we get the associated stylesheet, we pass the input file, and the stylesheet to Xalan for transformation.

HarshG
  • 267
  • 1
  • 3
  • 10
0

Yes, I agree with you. This appears to violate the expectations inherent in the specification of the SAXSource class.

The Saxon implementation uses the XMLReader supplied.

The JDK Xalan and Apache Xalan version appear to be the same in this respect.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Michael, what is the way out now? I've seen Saxon implementation as well, and it is working perfectly. – HarshG Aug 22 '13 at 08:08
  • Well, if a piece of software has a bug then you have three options: try to get it fixed, work around it, or use alternative software. In this situation I would of course suggest switching to Saxon, but there may be valid reasons you can't do that. – Michael Kay Aug 22 '13 at 16:28