Hi,

Iam very new to XSLT and XML. I am trying to invoke a javascript function from inside my xslt documen. The javascript snippet is as follows:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:js="urn:custom-javascript" 
exclude-result-prefixes="msxsl js" > 

<msxsl:script language = "JavaScript" implements-prefix = "js">
<![CDATA[

function compareCsvs (firstString,secondString) {

var firstArray=firstString.split(",");
var secondArray = secondString.split(",");
var result = "";

if ((firstString == "") || (secondString == ""))
return firstString;

for ( var i = 0; i < firstArray.length ; i++){
if ( firstArray[i] == secondArray[i] ) {
result = result + firstArray[i];
} else {
result = result + "<font color=#FF0000>"+ firstArray[i] + "</font>";
}
if (i != (firstArray.length - 1)){
result = result + ",";
}
}
return result;
}

]]>
</msxsl:script>

But whenver I try to see the output in IE 8, I am getting the error:

"Microsoft JScript runtime error Object doesn't support this property or method line = 7, col = 3 (line is offset from the st..."

I have tried to look up a solution online, but have failed so far. Any help is really appreciated.

Thanks in Advance,
Z

What line is line 7 ? You can see if you choose to debug the javascript error in IE8. It will be the highlighted line.

Thanks for your reply.

The problem was not with the function, but with the way I was invoking it. Earlier I was invoking the function as follows:

<xsl:value-of select="js:compareCsvs(file1data,$file2data))"  />

As you can see I was not specifically typecasting the input arguements to string, which was causing the error. I changed it as follows to make it work.

<xsl:value-of select="js:compareCsvs(string($file1data),string($file2data),string($type))" disable-output-escaping="yes" />

.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.