Inserting JavaScript into XSLT

March 12th, 2009 | Categories: JavaScript, MOSS, SharePoint, XSLT

When inserting JavaScript code into XSLT dataForm webpart it can sometimes get tricky. Sometimes SharePoint designer messes up our code or we have huge trouble with & signs,… the best way to insert the JavaScript code block into XSLT data view is to enclose it with xsl:text and cdata. Below is the sample:

<xsl:text disable-output-escaping=”yes”>
<![CDATA[
<script type=”text/javascript”>
(your JavaScript code here)
</script>
]]>
</xsl:text>

  1. Dell
    April 22nd, 2009 at 22:48
    Reply | Quote | #1

    I tried this, but it failed for ie6. The warning message is "In Internet Explorer 6 the tag <xsl:text> is not permitted". Do you have a fix that will work for both ie6 and ie7?

  2. m0gwai
    September 19th, 2009 at 20:34
    Reply | Quote | #2

    hi, try this:

    <![CDATA[
    document.write("foo, bar");
    ]]>

  3. Kristina
    December 17th, 2009 at 14:33
    Reply | Quote | #3

    This works great for me in IE6 and firefox but not in safari. Is there a way to get javascript working for safari in xslt?