Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: function vbscript inside xsl

From: "Anthony Jones" <Ant@------------.--->
To: 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




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent