[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Content of Script element getting wrapped by CDATA

Subject: Re: Content of Script element getting wrapped by CDATA
From: "Joyce Babu" <joyce@xxxxxxxxxxxxx>
Date: Wed, 22 Oct 2008 23:40:59 +0530
Re:  Content of Script element getting wrapped by CDATA
Thanks for the reply Darcy,

But if I provide the input xml like that, I am getting
<script type="text/javascript"><![CDATA[//

alert('JOYCE');
//]]></script>

ie, the CDATA tag that I inserted within the xml disappears. And a new
tag is added by the xslt processor, wrapping the content.

On Wed, Oct 22, 2008 at 11:30 PM, Darcy Parker <darcyparker@xxxxxxxxx> wrote:
>
> Hi Joyce,
>
> Standard practice is to format the output like this:
>
> <script content="text/javascript">
> // <![CDATA[
>
> javascript code here
>
> // ]]>
> </script>
>
> Note: The // are interpreted as comments to javascript, so it won't
> read the line with the CDATA opening and closing tags.  And it is
> critical to have the CDATA in the XML because some characters in
> javascript and not valid for text() nodes in XML.
>
> You could try writing your input XML like this.
>
> Darcy
> On Wed, Oct 22, 2008 at 1:24 PM, Joyce Babu <joyce@xxxxxxxxxxxxx> wrote:
> > I have PHP 5.2.6 and was trying to create my first XSL powered
> > website. I am trying to build a template system. In this, the XML
> > contains a head section, which is directly copied by the XSLT to the
> > output document.
> >
> > In my XML data, I tried to include a script element, and the content
> > of the tag is automatically wrapped in <![CDATA[ ]]> by the libxslt
> > processor (default php processor). Hence I am getting a syntax error
> > in my browser.
> >
> > Can anyone plz tell me how to fix it?
> >
> > Here is my xml code
> >
> > ----------------------------------------------------------
> > <?xml version="1.0"?>
> > <head>
> >  <title>XSLT</title>
> >  <link href="/manage/style.css" type="text/css" rel="stylesheet"/>
> >  <script src="/js/jquery.js" type="text/javascript"/>
> >  <script src="/js/tablesort.js" type="text/javascript"/>
> >  <script type="text/javascript">
> > alert('No Error');</script>
> > </head>
> > ----------------------------------------------------------
> > XSL Code
> > ----------------------------------------------------------
> >
> > <xsl:stylesheet version="1.0"
> >  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >  xmlns:php="http://php.net/xsl"
> >
> >  xsl:extension-element-prefixes="php"
> >  xmlns=""
> >>
> > <xsl:output method="xml" omit-xml-declaration="yes" standalone="no"
> > indent="no" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0
> > Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
> >
> > <xsl:template match="/">
> >  <html xml:lang="en" lang="en">
> >  <!-- Include Header-->
> >  <xsl:copy-of select="/root/head" />
> >  <body>
> >  </body>
> >  </html>
> > </xsl:template>
> > <!-- Identity Template -->
> > <xsl:template match="@*|node()">
> >  <xsl:copy-of select="." />
> > </xsl:template>
> >
> > </xsl:stylesheet>
> > ----------------------------------------------------------
> >
> > Output:
> > ----------------------------------------------------------
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
> >  <head>
> >    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
> >    <title>XSLT</title>
> >    <link href="/manage/style.css" type="text/css" rel="stylesheet" />
> >
> >    <script src="/js/jquery.js" type="text/javascript"></script>
> >    <script src="/js/tablesort.js" type="text/javascript"></script>
> >    <script type="text/javascript"><![CDATA[
> > alert('No Error');]]></script>
> >  </head>
> >  <body>
> >  </body>
> >  </html>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.