Javascript called from an xsl:what is wrong here?

wxdqz

New Member
Hi there,

I have the following xsl in which I am calling an javascript function "ChangeParentNodeName".
When I apply this xsl to the following xml, I am getting a javascript error "Object required....Error returned from property or method call".
Where am i going wrong...?

Here is my xml:
<?xml-stylesheet type="text/xsl" href=http://www.webdeveloper.com/forum/archive/index.php/"C:\Temp\NewTest.xsl"?>
<Objects>
<AssetAllocation ID="45" Red="51" Green="51" Blue="255">
<SecurityAllocation GSecID="11" TaId="0" SecName="LUCENT TECHNOLOGIES INC" Ticker="LU" SecType="" Value="1262.512" Percentage="0.2849" Quantity="501"/>
<SecurityAllocation GSecID="12" TaId="0" SecName="LUCENT TECHNOLOGIES INC" Ticker="LU" SecType="" Value="1262.522" Percentage="0.2849" Quantity="501"/>
<SecurityAllocation GSecID="13" TaId="0" SecName="LUCENT TECHNOLOGIES INC" Ticker="LU" SecType="" Value="1262.542" Percentage="0.2849" Quantity="501"/>
<SecurityAllocation GSecID="14" TaId="0" SecName="LUCENT TECHNOLOGIES INC" Ticker="LU" SecType="" Value="1262.572" Percentage="0.2849" Quantity="501"/>
</AssetAllocation>
</Objects>


*****************************************************************
And my xsl is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:MyScript="http://www.abcsoftec.com/abcde">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="inpXml" select="."/>
<xsl:variable name="newXml" select="MyScript:ChangeParentNodeName(string($inpXml))"/>
<!--Now print the output-->
<xsl:copy-of select="msxml:node-set($newXml)"/>
</xsl:template>
<msxml:script language="JavaScript" implements-prefix="MyScript"><![CDATA[
function ChangeParentNodeName(inpXml)
{

var oXmlDom=new ActiveXObject("Msxml2.DOMDocument");
var sXml=inpXml;

oXmlDom.async=false;
oXmlDom.loadXML(sXml);

var oFirstChildNode=oXmlDom.firstChild;
var oAttrs=oFirstChildNode.attributes;
var oNewXmlNode=null;
var oAttr=null;

oNewXmlNode = oXmlDom.createElement("NewAssetAllocation");

for (var i = 0; i < oAttrs.length; i++)
{
oAttr = oXmlDom.createAttribute(oAttrs.item(i).name);
oAttr.value = oAttrs.item(i).value;
oNewXmlNode.setAttributeNode(oAttr);
}


for (var j=0;j < oFirstChildNode.childNodes.length;j++)
{
oNewXmlNode.appendChild(oFirstChildNode.childNodes(j));
}

oXmlDom.firstChild.appendChild(oNewXmlNode);
oXmlDom.removeChild(oFirstChildNode);
return oXmlDom;
}
]]></msxml:script>
</xsl:stylesheet>



Thanks in advance..
livehed
 
Back
Top