XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Jack DavidsonSubject: Javascript called from an xsl:what is wrong here?
Author: Jack Davidson
Date: 31 May 2005 02:13 AM
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="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

Postnext
Ivan PedruzziSubject: Javascript called from an xsl:what is wrong here?
Author: Ivan Pedruzzi
Date: 06 Jun 2005 07:32 AM
Hi Jack,

Are you sure you want to use a script extension for this?
You can achieve the same result using pure XSLT 1.0

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | *">
<xsl:copy>
<xsl:apply-templates select="@* | *"/>
</xsl:copy>
</xsl:template>


<xsl:template match="AssetAllocation">
<NewAssetAllocation>
<xsl:copy-of select="@* | *"/>
</NewAssetAllocation>
</xsl:template>

</xsl:stylesheet>

Posttop
Jack DavidsonSubject: Javascript called from an xsl:what is wrong here?
Author: Jack Davidson
Date: 07 Jun 2005 06:31 AM
Thanks a lot Ivan...!it works perfectly for me...!actually I was looking for a solution using pure xsl only but since I cud not get it, I was using javascript to achieve the same...

thanks again...

Regards,
livehed

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.