Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2006, 01:10 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default <?javax.xml.transform.disable-output-escaping ?>

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 ?>&lt;script&gt;...&lt;/script&gt;<?javax.xml.transform.disable-output-escaping ?>

I've already Google'd for that, extensively - and found several related posts - but not a solution...

Thanks
Robert


 
Old August 25th, 2006, 06:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old August 27th, 2006, 06:51 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael.

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...

Are common techniques to accomplish that?

 
Old August 27th, 2006, 07:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old August 27th, 2006, 08:51 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Why are you generating the script element as text, rather than as a regular element node? This is the root of your trouble
Muhahaha! That one's cured! - Thanks!

Also thanks for the background information. I was coming from the Microsoft world - that, I think, says it all.

 
Old January 5th, 2011, 07:28 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default follow these simple steps to get rid of that

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.

You should be set.

Mark
http://www.nosle.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I transform XSLT without the <?xml?> tag? nadavvin XSLT 4 June 10th, 2007 09:25 AM
Finding an alternative to disable-output-escaping nickbond XSLT 4 November 15th, 2006 05:28 PM
Disable-Output-Escaping in .NET Transform tclancy XSLT 3 March 1st, 2006 09:27 AM
Escaping < and > barnaclebarnes XSLT 4 October 5th, 2004 08:56 AM
copy-of with disable-output-escaping? andrin XSLT 5 July 16th, 2004 04:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.