Project

Profile

Help

Passing XML Tree as parameter to Transformer

Added by Anonymous over 19 years ago

Legacy ID: #3259307 Legacy Poster: Pranas (pranasb)

Conditions: 0. Use case - 2 transformations in the chain. 1-st using XML tree as parameter to transformer. 1. javax.xml.transform.TransformerFactory = com.saxonica.SchemaAwareTransformerFactory 2. The transformation uses XML tree as parameter: Transformer transformer = translet.newTransformer(); InputStream uiDataStrem = loader.getResourceAsStream("some.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); transformer.setParameter("ui-ref", factory.newDocumentBuilder().parse(uiDataStrem)); The result: Tranformation is incorrect. The Xerces created tree, but it was not recognised by Saxon. BUG?! The second atempt is to pass Saxon specific Tree implementations by setting Saxon Document builder Factory: javax.xml.parsers.DocumentBuilderFactory=net.sf.saxon.dom.DocumentBuilderFactoryImpl The result of trasformation is correct. BUT during attempt to process seccond xml streem the exceptions thrown: ; SystemID: ; Line#: 2532; Column#: -1 net.sf.saxon.trans.DynamicError: Cannot disable output escaping when writing a tree at net.sf.saxon.tinytree.TinyBuilder.characters(TinyBuilder.java:221) at net.sf.saxon.event.ProxyReceiver.characters(ProxyReceiver.java:202) at net.sf.saxon.event.ComplexContentOutputter.characters(ComplexContentOutputter.java:110) PLESE HELP. I need saxonsa8-4 to process data. The saxonsa8-4 should be supported.... Thanks Pranas Baliuka


Replies (1)

RE: Passing XML Tree as parameter to Transfor - Added by Anonymous over 19 years ago

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

Your call to Xerces will return a DOM Document node. Saxon will recognize this as the value of a stylesheet parameter provided that the DOM support module (saxon8-dom.jar) is on your classpath. However, this is not a good way to pass an XML document as a parameter to Saxon. It would be better to pass a JAXP StreamSource and let Saxon build the tree itself. In the most recent XSLT 2.0 draft (April 2005) error 1610 was removed, and disable-output-escaping is now ignored when writing to a temporary tree. This change was not implemented in Saxon 8.4, but will be made in the next release. I would recommend, however, that you don't use disable-output-escaping in these circumstances, since it does nothing and may confuse readers of your code. (In fact, I would recommend that you don't use d-o-e at all...) Note that these two problems are quite unrelated. Michael Kay

    (1-1/1)

    Please register to reply