[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: script and xsl

Subject: Re: script and xsl
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 7 Mar 2002 14:43:33 +0000
vbscript selectsinglenode
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.