Adding Javascript in XSLT
To add Javascript in XSLT ( for e.g. Dataview webpart or xslt of search results webpart),You need to either, reference a .js file in the header or you can add the javascript function in the dataview webpart's header itself.
The function will be added just after <xsl:template match="/"> and should be wraped in<!--[CDATA[.............................]]--></xsl:template>
For e.g. below will be your javascript code in xslt.
<xsl:template match="/"></xsl:template>
<script type="text/javascript"><![CDATA[
function Test()
{
alert("tested!");
}
]] </script>
Finally, To use this javascript in xslt , we will use xsl attribute href, as we are trying to call this function on click of a link.
So, the code is
<xsl:attribute name="href">#</xsl:attribute>
<xsl:attribute name="Onclick">Javascript:Test()</xsl:attribute>
0 comments:
Post a Comment