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 November 15th, 2006, 12:51 PM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Finding an alternative to disable-output-escaping

Can anyone help me with this XSLT problem? I'm a novice so the solution may be obvious to you but I've been stuck on it for 2 days! It involves finding an alternative to using disable-output-escaping = "yes", as this method has stopped working since I switched my web hosting service. My old web host used PHP4 with Sabletron 1.0 and my new service uses PHP5 with libxslt Version 1.1.15

I'm building a simple CMS for a web site and am storing all the content in XML files. In particular I have a node value which contains HTML so it's stored as CDATA. Here's an example snippet of my XML...

   <content>
   <article><![CDATA[<p>Hello world</p>]]></article>
   </content>

I'm transforming this XML via PHP with an XSLT stylesheet that contains, amongst other things, the following...

   <div><xsl:value-of disable-output-escaping="yes" select="/content/article"/></div>

Using my old set-up (Sabletron) the HTML output was unescaped and came out the way I wanted i.e.

    <div><p>Hello world</p></div>

But with the new set-up the resulting HTML is...

    <div>&lt;p&gt;Hello world&lt;/p&gt;</div>

... obviously not what i want.

I've searched the web looking for alternatives to disable-output-escaping but can only find advice about not using it - no suggested alternatives. Is there a better way of getting that HTML from the XML node and outputting it 'as is' in the transformation??

Help gratefully received

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

Not easy without extensions. The best approach is to change your XML design. The purpose of CDATA is to say "the stuff in here might look like markup, but it isn't really - I want you to treat it as ordinary character text"; and that's exactly the opposite of what you want to say. So ideally, make the HTML well-formed XHTML, and store it directly in the article element without CDATA.

The alternative, which does require extensions, is to extract the text and put it through an XML parser, so that xsl:copy-of does the right thing.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 15th, 2006, 02:29 PM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael,

I don't have any control over the extensions so I'll take your first suggestion. The HTML stored in the XML will be coming from editors typing it into a FORM so I will have to do some validating and rewriting to put it into an XML structure that I can work with. It's a pity that disable-output-escaping isn't generally supported because it's such a useful feature.

Incidently, what are the extensions I would require?

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


>Incidently, what are the extensions I would require?

In Saxon, there's saxon:parse(). In other processors you could write something similar yourself as an extension function: something that takes a string is input, throws it at an XML parser, and returns the document node at the root of the resulting tree.

>It's a pity that disable-output-escaping isn't generally supported because it's such a useful feature.

Horribly useful. Its problem is that it breaks the architectural boundary between the transformation engine and the serializer. On the one hand this allows the XSLT coder to stray out of the transformation space and into the serialization space, which would otherwise be impossible. On the other hand, it eliminates the possibility of decoupling the transformation from the serialization, which is what you often want to do. Firefox, for example, doesn't support d-o-e because it doesn't actually serialize the output of the transformation: its renderer works directly from the tree representation.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 15th, 2006, 05:28 PM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just tried taking the html out of CData and then using xsl:copy-of and it worked!





Similar Threads
Thread Thread Starter Forum Replies Last Post
<?javax.xml.transform.disable-output-escaping ?> robbert XSLT 5 January 5th, 2011 07:28 PM
escaping < char tclotworthy XSLT 16 September 21st, 2007 04:31 PM
Disable-Output-Escaping in .NET Transform tclancy XSLT 3 March 1st, 2006 09:27 AM
Alternative print output for fo generated pdf Ma7T XSLT 0 August 2nd, 2005 08:27 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.