Akshata
Akshata

Reputation: 51

How to call external javascript function in xsl?

I have one js file in which one function is returning value.

I want to compare this value with xml value in xsl file.

My javascript is

function getUser()
{
   return user;
}

In xsl file i want to check this value in conditon.

How I can do that??

Upvotes: 4

Views: 14095

Answers (2)

LCJ
LCJ

Reputation: 22652

Refer following

  1. How To Include Client-Side Script Functions in an XSL Document
  2. Passing parameters to javascript script in xslt
  3. Row value is not available in javascript
  4. Calling Javascript within XSL after transformation in RSS Web Part

Also remember to add DEFER attrinute.

 <SCRIPT LANGUAGE="javascript" DEFER="true">
  <xsl:comment>

function hiLite()
 {
   alert("hello");
 }

</xsl:comment>
</SCRIPT>

Upvotes: 2

Mads Hansen
Mads Hansen

Reputation: 66714

Although it is not standard, it is possible to execute JavaScript functions from within your XSLT.

With MSXML you can use the msxsl:script extension element.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:user="http://mycompany.com/mynamespace">

<msxsl:script language="JScript" implements-prefix="user">
  function getUser()
  {
   return user;
  }

</msxsl:script>

<xsl:template match="/">
   <xsl:value-of select="user:getUser(.)"/>
</xsl:template>

</xsl:stylesheet>

Upvotes: 4

Related Questions