[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] script and xsl
Subject: Re: [xsl] script and xsl From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 7 Mar 2002 14:43:33 +0000 |
Hi Alia, > I got this msg in my XSL file (knowing that I'm using MSXML3 parser > and IE5): Microsoft VBScript runtime error Object doesn't support > this property or method: 'node.selectSingleNode' > > And this is my code: > <?xml version="1.0"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:msxsl="urn:schemas-microsoft-com:xslt" > xmlns:xslscript="http://mycompany.com/mynamespace" version="1.0"> > <msxsl:script language="vbScript" implements-prefix="xslscript"> > function calcul(node) > m=Node.selectSingleNode("Sales").text > n=node.selectSingleNode("UnitCost").text > calcul=m*n > end function > </msxsl:script> > > And I'm calling it this way: > <xsl:value-of select="xslscript:calcul(me) "/> The problem that you're experiencing is because the argument to the calcul function is a DOM NodeList, not a DOM Node. You can't pass single nodes to extension functions because XPath doesn't have a 'node' as a data type, only node sets. You have to find the first node in the node list to get the node for which you want to calculate the value: function calcul(node) m = node.item(0).selectSingleNode("Sales").text n = node.item(0).selectSingleNode("UnitCost").text calcul = m*n end function But again, there's no need to do this calculation through an extension function, at least in this context. You could just use: <xsl:value-of select="me/Sales * me/UnitCost" /> There's usually a way to do these kinds of things using XPath or XSLT, and it's a lot better to use those ways rather than creating your own extension functions to handle them. First, it means that your stylesheet can be used with processors other than MSXML. Second, it's more efficient because the processor doesn't have to start up a new VBScript environment in order to run the functions. If you can't work out how to do something using XPath or XSLT, just ask and we should be able to help - don't worry, we *will* tell you if your problem can best be solved through an extension function :) Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] script and xsl, Julian Reschke | Thread | Re: [xsl] script and xsl, Corey_Haines |
RE: [xsl] inline call to external p, Hunsberger, Peter | Date | Re: [xsl] Multiple attributes prese, Mike Ferrando |
Month |