XSLTGeneral questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Hi there, I'm using javax.xml.transform.Transformer.TransformerFactory to transform an XML document by an XSLT document.
In the XSLT document, there are commands like, <xsl:text disable-output-escaping="yes"><![CDATA[
<script>...</script></xsl:text>
The resulting document will look like, <?javax.xml.transform.disable-output-escaping ?><script>...</script><?javax.xml.transform.disable-output-escaping ?>
I've already Google'd for that, extensively - and found several related posts - but not a solution...
The JAXP interface specifies that disable-output-escaping requests are passed in this way from the XSLT transformer to a user-written ContentHandler. This will only happen if you don't serialize the output directly. It's best not to use d-o-e unless you are serializing the output (actually, it's best not to use it at all).
Michael Kay http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
The "ContentHandler" is a DOM4J DocumentResult object in my case.
Quote:
quote:This will only happen if you don't serialize the output directly.
I didn't understand that, sorry.
Quote:
quote:It's best not to use d-o-e unless you are serializing the output (actually, it's best not to use it at all).
In my understanding, using d-o-e breaks the rule that the XSL transformer should be able to produce the result tree in one pass. A second pass will be necessary.
Nevertheless, it's obvious that I need to integrate the <script> tags into the document, at any rate...
disable-output-escaping is an instruction to the serializer, that is the component that turns the result tree into lexical XML. If your result is not lexical XML but a DOM4J DocumentResult, then d-o-e has no meaning. The XSLT 2.0 spec says that in such cases it should be ignored. But the JAXP spec takes into account that when you send to a ContentHandler, the ContentHandler might be acting as a serializer and might want to know about the request to disable-output-escaping. So it defines this processing instruction to convey the request.
Why are you generating the script element as text, rather than as a regular element node? This is the root of your trouble: you're thinking in terms of generating lexical XML rather than generating a result tree.
Michael Kay http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Use a StreamResult parser, insetad of DOMResult
transformer.setOutputProperty(OutputKeys.OMIT_XML_ DECLARATION,"yes");
if you are working with only part of the html page.