[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Pass XSL variable into VBS function

I want to create a function in VBS at the top of an XSLT document, how do I pass an xsl variable into it?
  • 6
  • 6
1 Solution
Geert BormansCommented:
do you call the XSLT from a VBS

or do you have a VBS inside your XSLT as an extension function?

from your question it seems the latter
simply put the variable as a parameter in your vbs function call
eg. myscript:myfunction($myxslvariable)


BeenSwankAuthor Commented:
this is the relevant code:

  Function CatTransform()
    Dim catArr(36, 1)
    catArr(0, 0) = "KIDS"
    catArr(1, 0) = "DRAMATHILLER"
    catArr(2, 0) = "COMEDY"
    catArr(3, 0) = "HORROR"
    catArr(4, 0) = "WORLD"
    catArr(5, 0) = "ACTION"
    catArr(6, 0) = "THRILLER"
    catArr(7, 0) = "SCIFI"
    catArr(8, 0) = "DOCUMENTARY"
    catArr(9, 0) = "MUSICAL"
    catArr(10, 0) = "ANIMATION"
    catArr(11, 0) = "ROCKPOPURBAN"
    catArr(12, 0) = "JAZZLATIN"
    catArr(13, 0) = "WORLDFOLK"
    catArr(14, 0) = "HERITAGE"
    catArr(15, 0) = "TOURIST"
    catArr(16, 0) = "FAIRS"
    catArr(17, 0) = "WALKSTALKSTOURS"
    catArr(19, 0) = "CIRCUS"
    catArr(20, 0) = "MUSEUMEXHIBITION"
    catArr(21, 0) = "DANCE"
    catArr(22, 0) = "URBAN"
    catArr(23, 0) = "ROCKPOP"
    catArr(24, 0) = "JAZZWORLD"
    catArr(25, 0) = "TALKLECTURES"
    catArr(26, 0) = "READINGSBOOK"
    catArr(27, 0) = "FAMILYCHILDREN"
    catArr(28, 0) = "SEASONAL"
    catArr(29, 0) = "SPORT"
    catArr(30, 0) = "DRAMAMUSICDANCECLASS"
    catArr(31, 0) = "MUSICALCABARET"
    catArr(32, 0) = "PLAY"
    catArr(33, 0) = "KIDSPANTO"
    catArr(34, 0) = "DANCEPERFORMANCE"
    catArr(0, 1) = "Children"
    catArr(1, 1) = "Drama"
    catArr(2, 1) = "Comedy/Romantic Comedy"
    catArr(3, 1) = "Horror"
    catArr(4, 1) = "World"
    catArr(5, 1) = "Action"
    catArr(6, 1) = "Thriller"
    catArr(7, 1) = "Sci-Fi"
    catArr(8, 1) = "Documentary"
    catArr(9, 1) = "Musical"
    catArr(10, 1) = "Animation"
    catArr(11, 1) = "Rock/Pop/Urban/Dance"
    catArr(12, 1) = "Jazz/Latin"
    catArr(13, 1) = "World/Folk"
    catArr(14, 1) = "Heritage"
    catArr(15, 1) = "Tourist Attraction"
    catArr(16, 1) = "Fairs/Markets/Shows"
    catArr(17, 1) = "Walks/Tours"
    catArr(18, 1) = "Family/Children's Activity"
    catArr(19, 1) = "Circus"
    catArr(20, 1) = "Museum Exhibition"
    catArr(21, 1) = "Dance"
    catArr(22, 1) = "Urban"
    catArr(23, 1) = "Rock/Pop"
    catArr(24, 1) = "Jazz/World"
    catArr(25, 1) = "Talks/Lectures/Workshops/Courses"
    catArr(26, 1) = "Readings/Book Signings/Poetry"
    catArr(27, 1) = "Family/Children's Activity"
    catArr(28, 1) = "Seasonal/Religious"
    catArr(29, 1) = "Sport"
    catArr(30, 1) = "Drama/Music/Dance Class"
    catArr(31, 1) = "Musical/Cabaret"
    catArr(32, 1) = "Play"
    catArr(33, 1) = "Children's/Panto"
    catArr(34, 1) = "Dance Performance"
    catArr(35, 1) = "Public Gallery Exhibition"
    catArr(36, 1) = "Private Gallery Exhibition"
  dim check, cat, result
  for i = 0 to 36
    check=InStr(catArr(i, 0),txt,cat,0)
    if check = 1 then
         result = result & ",&nbsp;" & catArr(i, 1)
    end if
End Function

<xsl:variable name="cat">
      <xsl:for-each select="categories/category">
          <xsl:value-of select="."/>
      <xsl:for-each select="subcategories/subcategory">
          <xsl:value-of select="."/>  
<xsl:value-of select="user:CatTransform($cat)"/>
Geert BormansCommented:
doesn't that work?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

BeenSwankAuthor Commented:
nope this is the error (I modified the check part btw):

msxml3.dll error '80020009'

Microsoft VBScript compilation error Invalid character line = 86, col = 18 (line is offset from the start of the script block). check=InStr(1,$cat,SPECIAL,0)

/ukdp/XpathQTest.asp, line 17
Geert BormansCommented:
maybe you have to cast the nodeset to a string first

<xsl:value-of select="user:CatTransform(string($cat))"/>
BeenSwankAuthor Commented:
No, that doesnt even work in a simple example:

Function CatTransform
   CatTransform = cstr(date)
End Function

<xsl:value-of select="user:CatTransform(string($cat))"/>


msxml3.dll error '80004005'

System error: -2146827838. Error occurred during a call to property or method 'CatTransform'.

/ukdp/XpathQTest.asp, line 66
Geert BormansCommented:
Did you actually test the VBS function
does <xsl:value-of select="user:CatTransform('KIDS')"/> work?

maybe there is something wrong with the VBS function

What is in the categories and subcategories?
It is not clear at all what you want to pass as a argument to the function
In the VBS, you can't assume that a nodeset is an array
It should be a string here, so  along concatenation

Maybe you should post an example of the XML
and what you want the VBS to do

If you simply want to mapp KIDS to children,
then there is a pure XSLT way to create lookup tables
That will be a lot more convenientand will work accross XSLT processors

I can show you how to...
I have a feeling that the problem is a lot deeper than just passing the variable


BeenSwankAuthor Commented:
Ok. the idea is in my XML it returns subcategories like this:

<?xml version="1.0" encoding="UTF-8"?>
         <category default="Yes">SPECIALEVENTS</category>
         <title_name>Lecture Theatre</title_name>
         <title_description>A series of illustrated lectures exploring themes from the current major exhibition.</title_description>

It just squashes them all together capitalised - no good for output. The idea was to then bolt the main category at the front resulting in eg: SPECIALEVENTSTALKLECTURES, send this variable ($cat) to the function then if it contains any item from the array (a list of all the used categories) return it as its formatted 'pair' So this becomes "Special Events, Talks/Lectures/Workshops/Courses" using InStr. I just need to be able to sucessfully pass $cat (the capitalised string) then it should be dooable.
BeenSwankAuthor Commented:
ok the function should read:

 dim check, cat, result
  for i = 0 to 36
    check=InStr($cat,catArr(i, 0),cat,0)
    if check = 1 then
         result = result & ",&nbsp;" & catArr(i, 1)
    end if
End Function
Geert BormansCommented:
- I assume you have tested your VBS function with a fixed string and you know this works
- I also assume that the function prototye takes one single string type argument
- I also assume that there is only one category and only one subcategory
then do this (throw away all the for-eaches)

<xsl:variable name="cat" select="string(concat(categories/category,subcategories/subcategory))" />
<xsl:value-of select="user:CatTransform($cat)"/>

now you get a nicely concatenated string


BeenSwankAuthor Commented:
There was an issue with the VBS syntax..... 'Function CatTransform(cat)' as opposed to 'Function CatTransform'

Thank you for your time :D
Geert BormansCommented:

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now