[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] Content of Script element getting wrapped by CDATA
From: "Joyce Babu" <joyce@xxxxxxxxxxxxx>
Date: Thu, 23 Oct 2008 11:49:00 +0530

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
Keywords