adkt
3/19/2018 - 5:35 AM

Javascript in XSLT

How to use JavaScript in XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:ms="urn:schemas-microsoft-com:xslt"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:adm="urn:my-scripts"
	exclude-result-prefixes="ms">

	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	
	<!-- c# scripts -->
	<msxsl:script language="JavaScript" implements-prefix="adm">  
		 <![CDATA[  
		 function circumference(radius){  
		   var pi = 3.14;  
		   var circ = pi*radius*2;  
		   return circ;  
		}  
		]]>  
	</msxsl:script>
	
	<xsl:template match="/">  
	    <xsl:value-of select="adm:circumference(5)"/> 
    </xsl:template>

</xsl:stylesheet>