Javascript in Data View Web Part XSLT

One of the great frustrations working with XSLT in Data View Web Parts is the very limited set of functions available in XSLT 1.0 available in SharePoint 2007. However (as in so many things) javascript offers a solution.

This method is the simplest I have found and is based on posts at SharepointalistProgrammingsharepoint and  Sharepointboris.

Inserting the javascript functions

The method here works for inline scripts, but would probably also work with script references

  1. Locate the root XSLT template
  2. Insert the script within a CDATA tag

Calling the javascript functions

xsl:attribute

One method is to use xsl:attribute to build a link and add an onclick attribute

using parameters and writing results back to template

This example takes the formatted modified date, passes it through a javascript function, and writes out the result

The countup() javascript function ends with document.write(var); to output the result into the xslt

uriencode the page location for use the source element of a link

This would be particularly useful for making DVWPs portable and for working with InfoPath Form Libraries.  See URI encode Source attribute in SharePoint 2007 Data View Web Part calling an InforPath form for a solution that uses these techniques.