Friday, August 8, 2008

How to Inlucde A JS File in XSL

In my project, I need to include an external javascript(js) file in xsl. At first, I tried to include a script element in the head written in HTML syntax as :

<script language="Javascript" src="filename.js"></script>

When transfering to HTML, it became to:

<script language="Javascript" src="filename.js" />

Without the closing tag</script>, the script element was not recognized by the browser.

To solve this problem, I have tried a lot of methods, such as adding text to the empty script element as:

<script language="Javascript" src="filename.js">1</script>.

Although it worked fine, the useless text between script tag looked so unprofessional.

At last, I came across a way to make this work. Rather than including script as an element, I included a line of plain text using <xsl:text>:

<xsl:text disable-output-escaping="yes">&lt;script src="fsq.js" language="Javascript"</xsl:text><xsl:text disable-output-escaping="yes"> &gt;</xsl:text><xsl:text disable-output-escaping="yes">&lt;/script&gt;</xsl:text>

This line became <script language="Javascript" src="filename.js"></script> in HTML.

No comments: