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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.