Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - function vbscript inside xsl >Thread Next - Re: function vbscript inside xsl Re: function vbscript inside xslTo: NULL Date: 6/2/2006 9:54:00 AM
"Ghena" <lastminutesud@g...> wrote in message
news:1149213787.868571.263230@i......
> I'm really in Hard situation:
> I must create a function able to get the currency value from an xml
> source.
>
> The function it will be similar to the following:
>
>
>
>
>
> after in a xsl stylesheet I must call the function in this way:
>
>
There are so many things wrong with this code it's difficult to know where
to begin.
> <msxsl:script language=VbScript" implements-prefix="vb">
>
> <![CDATA[
> function getCurrency(CODE)
>
> Dim XmlDocument, Rate
> Set XmlDocument = CreateObject("Msxml2.DOMDocument.3.0")
> XmlDocument.async = False
> If XmlDocument.load("valute1.xml") Then
> XmlDocument.setProperty "SelectionLanguage", "XPath"
> Set Rate =
>
XmlDocument.selectSingleNode("/CommandList/GetCurrencies/CurrencyList/Curren
cy/Code[.
> = 'CODE']/following-sibling::UsdRate[1]/text()")
'CODE' is a string literal you probably mean:-
'" & CODE & "'
However looking ahead CODE will be a nodeset anyway so that still won't
work. It should be more like:-
'" & CODE.nextNode().text & "'
> If Not Rate Is Nothing Then
> Document.write "Rate is " & Rate.data
> Else
> Document.write "No rate found."
> End If
What's document.write doing here? I don't think the XSLT processor provides
a document object or any object at all.
> Else
> Document.write "Parse error: " & _
> XmlDocument.parseError.reason
> End If
> END FUNCTION
This function doesn't return anything
Ditch all the document.write stuff just do:-
getCurrency = CDbl(rate.text)
> ]]>
> </msxsl:script>
>
> <xsl:variable name="value_currency"
> select="="{vb:getCurrency(Price/Currency)}"/>
There is a an odd number of " in the line above. I'm trying to work out
whether the whole
select="={pathhere}" would do anything useful but I can't see it.
I think you meant:-
select="vb:getCurrency(Price/Currency)"
but getCurrency will need those Document.Writes removed and modified to
return the value you are after.
> <xsl:value-of select="(Price/Amount) / $value_currency" />
>
> In this way it must to find the code currency e.g 'NOK' and get the
> relative value e.g 89.7704 and then do a conversion from NOK to USD.
>
> But It' doesnt work :)
>
Have you looked at the document() function.
<xsl:variable name="value_currency"
select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyLis
t/Currency/Code[. =
current()/Price/Currency)]/following-sibling::UsdRate[1])"/>
This looks like it might work and eliminates the VBScript
Anthony
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
