4

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??

1
  • This isn't an XSLT question, because support for calling JS functions is not a feature of XSLT. Therefore, I have re-tagged this to "xsltprocessor". A further note is that calling extension functions in XSLT is rarely justified and should be avoided as a rule. For examle, many wanted data items that are not available in the XSLT static/dynamic context, can be provided as parameters to the transformation. Commented Dec 24, 2010 at 16:18

2 Answers 2

4

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>
Sign up to request clarification or add additional context in comments.

2 Comments

I think you should alert to the OP that this not standar extension function implementation result in loading the script engine every time the function is called.
Unfortunately in this way you don't call a function on an external file; it is internal, in the .xsl.
2

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.