Project

Profile

Help

XMLFilters created w/SAXON 6.5

Added by Anonymous over 18 years ago

Legacy ID: #3652630 Legacy Poster: Pete (pete-carey)

I realize that bugs are not being fixed for SAXON 6.x, but I wanted to confirm some mysterious behavior. I am using SAXON's SAXTransformerFactory to create an XMLFilter from an XSLT stylesheet. I then create a SAXSource that uses this filter as its XMLReader. When I run that SAXSource through a transform, the source seems to forget its "systemID". In my final transform, the value of saxon:system-id() is an empty string. Furthermore, any calls to the XSLT document(filename, /) function do not resolve correctly. Strange thing is, this occurs with the TinyTree model, and not with the standard tree. Here is some code: File xmlFile = new File("C:/example.xml"); File xslFile1 = new File("C:/filter.xsl"); File xslFile2 = new File("C:/transform.xsl"); Source xslSource = new StreamSource(xslFile1.toURL().toString()); TransformerFactory factory = TransformerFactory.newInstance(); XMLFilter reader = ((SAXTransformerFactory)factory).newXMLFilter(xslSource); InputSource inSource = new InputSource(xmlFile.toURL().toString()); SAXSource xmlSource = new SAXSource(reader, inSource); Transformer tranny = factory.newTransformer( new StreamSource(xslFile2.toURL().toString())); tranny.transform(xmlSource, new StreamResult(System.out)); The "filter" XSLT is a trivial "identity" transform that merely uppercases all element names in the document. The "final" transform simply prints the value of saxon:system-id(). In my java above, if I add: factory.setAttribute(SAXON_TREE_MODEL, SAXON_STD_TREE); Then the "saxon:system-id()" function works correctly. Of course, I'm more concerned with document() resolving correctly; I've just used saxon:system-id() to illustrate what I think is the crux of the issue. So what I am seeing is this: if you want to use XMLFilters (created from XSLT) w/SAXON, you should probably force the TransformerFactory to use the standard tree model... (??) Any comments would be appreciated. --PETE


Replies (2)

RE: XMLFilters created w/SAXON 6.5 - Added by Anonymous over 18 years ago

Legacy ID: #3652686 Legacy Poster: Michael Kay (mhkay)

A suggestion: after InputSource inSource = new InputSource(xmlFile.toURL().toString()); SAXSource xmlSource = new SAXSource(reader, inSource); add xmlSource.setSystemId(xmlFile.toURL().toString()) In JDK 1.5 I think the systemID of the SAXSource and that of the InputSource are always the same but I'm not sure this has always been true. It's safest to set both. I can't immediately see where the code is different between the two tree models but it's not intrinsically suprising that they should handle this case differently.

RE: XMLFilters created w/SAXON 6.5 - Added by Anonymous over 18 years ago

Legacy ID: #3652968 Legacy Poster: Pete (pete-carey)

I tried your suggestion (w/both JDK 1.4 and 1.5), but alas, it made no difference. Thanks for the response, --PETE

    (1-2/2)

    Please register to reply