[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: Thu, 23 Oct 2008 13:31:43 +0530
Re:  Content of Script element getting wrapped by CDATA
I have found an imperfect solution. I am not happy since it is not a
perfect XSLT solution. But atleast it does work.

Using the str_replace function of php, I replaced '<![CDATA' with
'//<![CDATA[' and ']]>' with '//]]>'.
str_replace(array('<![CDATA', ']]>'), array('//<![CDATA', '//]]>'), $output);
where $output is the result of the XSL Transformation.


Thanks a lot for the help Darcy.
Joyce

On Thu, Oct 23, 2008 at 11:49 AM, Joyce Babu <joyce@xxxxxxxxxxxxx> wrote:
> I tested the code, but I am getting errors on line
>>     <!--Identity Transform-->
>>     <xsl:template match="element()">
>>          <xsl:copy>
>>               <xsl:apply-templates select="@*,node()"/>
>>          </xsl:copy>
>>     </xsl:template>
>>     <xsl:template
>> match="attribute()|text()|comment()|processing-instruction()">
>>          <xsl:copy/>
>>     </xsl:template>
>
> The processor doesn't like the selectors "element()", "@*,node()" and
> "attribute()|text()|comment()|processing-instruction()".
>
> Using TestXSLT (http://www.entropy.ch/software/macosx/), I checked the
> code with Xalan, Sablotron, Libxslt and Saxon. And all of them showed
> errors.  Sablotron and PHP Libxslt showed the error was on line 41. If
> I change element() with node(), then the error is shown for the
> selector "@*,node()".
>
> @David - Unfortunately, it is not working. I am getting syntax error,
> since Javascript doesn't understand the statement <![CDATA[
>
> Here is my complete code
> <!-- XML code -->
> <?xml version="1.0"?>
> <root>
>  <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">//<![CDATA[
> alert('JOYCE');
> //]]></script>
>  </head>
> </root>
>
> <!--xsl code-->
> <?xml version="1.0"?>
> <!DOCTYPE xsl:stylesheet [
> <!ENTITY nbsp "&#160;" >
> <!ENTITY copy "&#169;">
> <!ENTITY laquo "&#171;" >
> <!ENTITY raquo "&#187;">
> ]>
> <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" 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"
> cdata-section-elements="script style" omit-xml-declaration="yes"/>
>
>  <!-- standard match to include all child elements -->
> <xsl:template match="/">
>  <html xml:lang="en" lang="en">
>    <!-- Include Header -->
>    <xsl:apply-templates select="/root/head" />
>    <body>
>
>    </body>
>  </html>
> </xsl:template>
>
> <!-- Identity Template -->
> <xsl:template match="script | style">
>  <xsl:copy>
>    <xsl:apply-templates select="@*"/>
>    <!--Note: The &#xA; characters at the end of the CDATA start tag
>    and before the CDATA end tag are important because the script
>    text may begin and end with new lines.-->
>    <xsl:value-of disable-output-escaping="yes"
> select="concat('//&lt;![CDATA[&#xA;',text(),'&#xA;//]]&gt;')"/>
>  </xsl:copy>
> </xsl:template>
>
> <!--Identity Transform-->
> <xsl:template match="node()">
>  <xsl:copy>
>     <xsl:apply-templates select="@*,node()"/>
>  </xsl:copy>
> </xsl:template>
>
> <xsl:template match="attribute()|text()|comment()|processing-instruction()">
>     <xsl:copy/>
> </xsl:template>
> </xsl:stylesheet>

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.