jerry.gadd
October 16th, 2003, 04:02 AM
I am trying to use javascript function inside an XSLT
I need to take several values from my source document and perform a function on them to determine several other values which I then want to put into my target document
I find the best way to pass multiple values to the javascript is to pass it a nodeset, but I want to results to be a node set also.
The problem is I get this error every time I attempt to pass back a nodeset.
"XSL transformation failed due to following error:
Function 'get_nodeset' did not return a value, or it returned a value that cannot be converted to an XSL data type."
Here is some example code that I wrote.
Please ignore the design, it is only to demonstrate the problem
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="http://exslt.org/js" extension-element-prefixes="js msxsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<msxsl:script language="JavaScript" implements-prefix="js">
<![CDATA[
function get_nodeset() {
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.loadXML("<root><a>1</a><b>2</b><c>3</c></root>");
return xmlDoc;
};
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:variable name="result" select="js:get_nodeset()"/>
<myroot>
<mya><xsl:value-of select="$result/root/a"/></mya>
<myb><xsl:value-of select="$result/root/b"/></myb>
<myc><xsl:value-of select="$result/root/c"/></myc>
</myroot>
</xsl:template>
</xsl:stylesheet>
I need to take several values from my source document and perform a function on them to determine several other values which I then want to put into my target document
I find the best way to pass multiple values to the javascript is to pass it a nodeset, but I want to results to be a node set also.
The problem is I get this error every time I attempt to pass back a nodeset.
"XSL transformation failed due to following error:
Function 'get_nodeset' did not return a value, or it returned a value that cannot be converted to an XSL data type."
Here is some example code that I wrote.
Please ignore the design, it is only to demonstrate the problem
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="http://exslt.org/js" extension-element-prefixes="js msxsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<msxsl:script language="JavaScript" implements-prefix="js">
<![CDATA[
function get_nodeset() {
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.loadXML("<root><a>1</a><b>2</b><c>3</c></root>");
return xmlDoc;
};
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:variable name="result" select="js:get_nodeset()"/>
<myroot>
<mya><xsl:value-of select="$result/root/a"/></mya>
<myb><xsl:value-of select="$result/root/b"/></myb>
<myc><xsl:value-of select="$result/root/c"/></myc>
</myroot>
</xsl:template>
</xsl:stylesheet>