|
Subject: Re: [xsl] Content of Script element getting wrapped by CDATA From: "Joyce Babu" <joyce@xxxxxxxxxxxxx> Date: Thu, 23 Oct 2008 13:31:43 +0530 |
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 " " >
> <!ENTITY copy "©">
> <!ENTITY laquo "«" >
> <!ENTITY raquo "»">
> ]>
> <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 
 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('//<![CDATA[
',text(),'
//]]>')"/>
> </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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Content of Script element, Joyce Babu | Thread | RE: [xsl] Content of Script element, Michael Kay |
| RE: [xsl] Group on deep equal crite, Vladimir Nesterovsky | Date | RE: [xsl] Content of Script element, Michael Kay |
| Month |