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

Re: How I can include javscript code ?

Subject: Re: How I can include javscript code ?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 10 Jul 2002 15:37:36 +0100
javscript cdata
Hi Charles,

> And if you don't want to type the <![CDATA[ ]]> tags in manually,
> you can use the cdata-section-elements attribute of the <xsl:output>
> element like this:
>
> <xsl:output cdata-section-elements="script">

Using a CDATA section in the stylesheet and getting a CDATA section in
the result are unrelated.

A CDATA section in the stylesheet is interpreted in just the same way
as a text node in which all the less-than signs and ampersands had
been escaped. So you could use:

<xsl:template match="/">
  <html>
    <head>
      <script language="JavaScript">
        function twiZone(Node){
          if(Node &lt; 1){
            alert("This one.");
          }
        }
      </script>
    </head>
    <body onload="twiZone(3)">

    </body>
  </html>
</xsl:template>

and the stylesheet will appear in exactly the same way to the XSLT
processor as if you used:

<xsl:template match="/">
  <html>
    <head>
      <script language="JavaScript">
        <![CDATA[
        function twiZone(Node){
          if(Node < 1){
            alert("This one.");
          }
        }
        ]]>
      </script>
    </head>
    <body onload="twiZone(3)">

    </body>
  </html>
</xsl:template>

The same goes for CDATA sections in the source document -- they're
simply not part of XSLT's data model.

Using the cdata-section-elements attribute on xsl:output, on the other
hand, affects how text nodes are output -- whether the less-than signs
and ampersands that they contain are escaped individually or whether
the entire text node is wrapped in a CDATA section. In either of the
above, if the script element's text nodes should be wrapped in CDATA
sections, you'll get:

      <script language="JavaScript">
        <![CDATA[
        function twiZone(Node){
          if(Node < 1){
            alert("This one.");
          }
        }
        ]]>
      </script>

otherwise you'll get:

      <script language="JavaScript">
        function twiZone(Node){
          if(Node &lt; 1){
            alert("This one.");
          }
        }
      </script>

The HTML output method doesn't wrap the script (or style) element's
content in a CDATA section, and doesn't escape the less-than signs or
ampersands; this is to ensure compatibility with legacy HTML
processors.
      
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.