RE: Including javascript files in HTML output

Subject: RE: Including javascript files in HTML output
From: Jonathan Asbell <jonathan.asbell@xxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2000 09:30:03 -0400
Javascript is hyper sensitive and non-strong typed.  You can not be sure,
when rendering html/javascript from xml that whitespace and text for that
matter will end up on the same line.  Also, your // needs to go right after
the <script> and right befor the </script> tags. See below:

try:

<SCRIPT LANGUAGE="JavaScript">
<xsl:text>&lt;!--//</xsl:text>
	<xsl:attribute name="SRC">
		<xsl:value-of select="."/></xsl:attribute>
<xsl:text>//--&gt;</xsl:text>
</SCRIPT>

or:

<SCRIPT LANGUAGE="JavaScript">
<![CDATA[<!--]]>
	<xsl:attribute name="SRC">
		<xsl:value-of select="."/></xsl:attribute>
<![CDATA[//-->]]>
</SCRIPT>

when it gets output it should look like:
<SCRIPT LANGUAGE="JavaScript">
<!--//
your script stuff

//-->
</script>

IF THE XSL DOES NOT OUT PUT THE JSAVASCRIPT IN THE FASHION ABOVE YOU CAN GET
ERRORS.  DESIGN YOUR XSL SO YOU GET THIS EXACT STYLE OF OUTPUT.  YOU MAY
HAVE TO PUT IN CARRAGE RETURN ESCAPED CHARACTERS, AND USE SEMICOLONS TO END
LINES (DONT RELY ON JAVASCRIPTS LAZY PERMISSIVENESS OF INTERPRETING A
CARRAGE RETURN AS A SEMICOLON).  ALSO PUT YOUR SEMICOLON RIGHT AFTER THE
ELEMENT THAT GENERATES THE LAST LINE ITEM OF CODE.

-----Original Message-----
From: Carlson, Thor [mailto:CarlsonT@xxxxxxx]
Sent: Wednesday, June 21, 2000 8:29 AM
To: 'xsl-list@xxxxxxxxxxxxxxxx'
Subject: Including javascript files in HTML output


Problem: I'm trying to include a JavaScript file "validate.js" in my HTML
output but IE5 is reporting a syntax error.  No error exists when I hard
code the JavaScript in the stylesheet.  The following is simplified for
readability:

Given the following XML fragment:

    <SCRIPTS>
        <SCRIPT>validate.js</SCRIPT>
    </SCRIPTS>

And the following stylesheet fragment:

    <xsl:for-each select="SCRIPT">
        <SCRIPT LANGUAGE="JavaScript">
            <xsl:attribute name="SRC">
                <xsl:value-of select="."/></xsl:attribute>//need
this</SCRIPT>
    </xsl:for-each>

My generated html result is:

    <SCRIPT LANGUAGE="JavaScript" SRC="validate.js">//need this</SCRIPT>

(I need to include the "//need this" without which the browsers do not
generate the closing </SCRIPT> tag, resulting in the display of an empty
page.)

My problem is the IE5 browser reports a syntax error.  The generated HTML is
correctly formed.  When the .js file contents are directly pasted into the
stylesheet, the syntax error is not reported.

Sample validate.js file:

    <xsl:text disable-output-escaping="yes">
    <![CDATA[
    <!-- hide javascript from older browsers
    function validate(form)
    {
        alert ('validate()!');
    }
    //-->
    ]]>
    </xsl:text>

Can anyone explain how to successfully include .js files?

Thank you.

- Thor

----------------------------------
Thor Carlson
Dun & Bradstreet
carlsont@xxxxxxx
973.605.6095 voice
973.605.6957 fax


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


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


Current Thread