|
Subject: Re: [xsl] How I can include javscript code ? From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 10 Jul 2002 15:37:36 +0100 |
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] How I can include javscri, Julian Reschke | Thread | Re: [xsl] How I can include javscri, David Carlisle |
| RE: [xsl] How I can include javscri, Julian Reschke | Date | RE: [xsl] key() question?, Américo Albuquerque |
| Month |