Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT with VBScript function

Status
Not open for further replies.

kevnhowe

IS-IT--Management
Sep 7, 2009
2
US
I am trying to parse a string in an xml element to imported into Access. I have created the following xslt with a vbscript function to accomplish this. I'm getting the following error when browsing the xml in IE: "Microsoft VBScript runtime error Wrong number of arguments or invalid property assignment line = 4, col = 0"

xslt:

<xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:myfunc="urn:extra-functions">
<msxsl:script language="VBScript" implements-prefix="myfunc">
<![CDATA[
Dim length, pos, string2
function ordernum(x)
pos=InStr(x,"-")
length=Len(x)
string2=(length-pos)
ordernum=Right(x,string2)
end function
]]>
</msxsl:script>
<xsl:template match="OrderList">
<html>
<body>
<h1>Orders</h1>
<table width="640">
<xsl:for-each select="Order">
<tr>
<td>
<xsl:value-of select="myfunc:eek:rdernum(@id)"/>
</td>
<td>
<xsl:value-of select="NumericTime"/>
</td>
<td>
<xsl:value-of select="Entry-Point"/>
</td>
<td>
<xsl:value-of select="Referer"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Any help would be much appreciated
 
[1] There are some delicate requirements on the arguments. If you pass some node, it is a nodelist you need to pass.

[1.1]
><xsl:value-of select="myfunc:eek:rdernum(@id)"/>
[tt]<xsl:value-of select="myfunc:eek:rdernum([blue]@*[/blue])"/>[/tt]

[1.2] the function
[tt]function ordernum(x)
for i=0 to x.length-1
if x(i).name="id" then
pos=InStr(x,"-")
length=Len(x)
string2=(length-pos)
ordernum=Right(x,string2)
exit function
end if
next
ordernum=chr(&ha0)
end function
[/tt]
[2] If you consider id being hard coded in the function is not flexible enough, you can do this.

[2.1]
><xsl:value-of select="myfunc:eek:rdernum(@id)"/>
[tt]<xsl:value-of select="myfunc:eek:rdernum([blue]@*,'id'[/blue])"/>[/tt]

[2.2] ...with the function modified like this.
[tt]function ordernum(x,s)
for i=0 to x.length-1
if x(i).name=s then
pos=InStr(x,"-")
length=Len(x)
string2=(length-pos)
ordernum=Right(x,string2)
exit function
end if
next
ordernum=chr(&ha0)
end function
[/tt]
[3] The statements in the function is not very concisely written. Also, the function as such can also be achieved by pure xslt 1.0 built-in function and is not a compelling reason to use necessarily extension function. It is a good instance to exercise extension, though. I am not criticizing.
 
tsuji, thanks for the reply, and I appreciate the level of detail you go into for your solution. I've figured out a simple fix; though, it's probably is not as simple as the built-in function you refer to. This is my first attempt at xslt, so I'm not familiar with all of its functions.

It worked by changing the value-of line to:
<xsl:value-of select="myfunc:eek:rdernum(string(@id))" />

I am open to and appreciate constructive criticism. I've cleaned up the function a little bit:
function ordernum(x)
Dim pos, str, num
pos=InStrRev(x,"-")
str=len(x)
num=(str-pos)
ordernum=Right(x,num)
end function

The string I'm looking for is always followed by the last dash in the xml field, where, there may be more than one dash. This logic seems to be the simplest way to find exactly what I'm looking for.
 
[4] use xslt built-in function
>I've figured out a simple fix; though, it's probably is not as simple as the built-in function you refer to.
If you are interested, it looks like this.
[tt] <td>
<xsl:value-of select="substring-after(@id,'-')" />
</td>[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top