Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old February 2nd, 2007, 08:22 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT convertion help

Hi all,

I'm new to the forum, but came accross it though google, after checking it out it seems to be a really good source of info, so hopefully I'll become a bit more of an active member around here!

Im currently strting on converting alot of content to prepare it for an import into a cms system we use but am encountering a bit of a problem in doing so.

The content is in XML (of mixed format/standard) but i have to produce a new xml structure that the new cms will accept. What I would like to do is insert a section of an xml document (including tags) into a CDATA section in the final document, for example;

<content>
<p> ...data... </p>
<p> ...data... </p>
<p><a href="" title="">...</a></p>
</content>

Would be transformed into;
<content>
<![CDATA[
<p> ...data... </p>
<p> ...data... </p>
<p><a href="" title="">...</a></p>
]]>
</content>

After playing with something which im sure must be easy i just can't seem to figure it out, so any help would be massively appreciated.
Im using PHP to perform the transformation if that helps

Many thanks indeed

/Matt

  #2 (permalink)  
Old February 2nd, 2007, 08:47 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can't have tags inside a CDATA section. The whole purpose of CDATA is to tell the system that things that might look like tags aren't tags really. So you really need to review your design.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old February 2nd, 2007, 09:12 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is one of those cases where you might have to resort to using disable-output-escaping. It's not a nice feature, not all processors support it, and it only works if you are serializing the output. But it allows you to do:

<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:copy-of select="....."/>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>

It's often handy feature if you need to do "dirty" programming like this.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #4 (permalink)  
Old February 2nd, 2007, 10:00 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mhkay, thanks a lot for your reply it has sorted the problem for me.

I agree totally that the way the system is working at the moment is far from ideal, unfortunately the CMS system they are using forces this hand though, and means that what is actually xml markup is being stored as a string, making it much harder to then perform future transformations on.

I had actually tried the method you showed me, but i have failed to grasp the proper function of the disable-output-escaping

Once again, thanks a lot for the help, its greatly appreciated!

/Matt



Similar Threads
Thread Thread Starter Forum Replies Last Post
html to xml convertion using xslt moshaik BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 2 November 24th, 2008 10:33 AM
Convertion of CRect* to ULONG arun.sharma.kumar Visual C++ 1 June 5th, 2007 03:33 AM
pdf to word convertion amartya_mandal ASP.NET 1.0 and 1.1 Professional 2 April 17th, 2007 02:27 PM
Convertion schanda ASP.NET 1.0 and 1.1 Professional 1 March 23rd, 2006 02:53 PM
Convertion using Masks rtr1900 Classic ASP Databases 2 November 29th, 2005 06:28 AM





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