How to call external javascript function in xsl?

I have one js file in which one function returns a value.

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

My javascript

function getUser() { return user; } 

In the xsl file, I want to check this value in conditon.

How can i do this?

+4
source share
2 answers

Although not standard, you can execute JavaScript functions from within your XSLT.

In 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> 
+4
source

Refer to the following

Also be sure to add DEFER attrinute.

  <SCRIPT LANGUAGE="javascript" DEFER="true"> <xsl:comment> function hiLite() { alert("hello"); } </xsl:comment> </SCRIPT> 
+2
source

Source: https://habr.com/ru/post/1333281/


All Articles