|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How I can include javscript code ?
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 < 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 < 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








