xsl-list
[Top] [All Lists]

Re: [xsl] Content of Script element getting wrapped by CDATA

2008-10-23 04:02:12
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(_at_)joycebabu(_dot_)com> 
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>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--