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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL VBScript problem

Status
Not open for further replies.

flash05

IS-IT--Management
Jan 13, 2005
2
CA
I'm new to XSL / XML and trying out some basic VBscript in XSL. I can't seem to get any values out of VBScript and I've tried looking and asking everywhere on what may be wrong. I can't seem to find why this doesn't work. Here is the XML I have:

<?xml version="1.0" encoding="iso-8859-1"?>

<?xml-stylesheet type="text/xsl" href="C:\PathTo.xsl"?>

<greeting>Hello, world!</greeting>


and the XSL I have:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xslscript="xmlns:vbs="urn:schemas-sqlxml-org:vbs">

<msxsl:script language="VBScript" implements-prefix="vbs">
<![CDATA[
Dim x
x=1
]]>

</msxsl:script>
<xsl:template match="/">
<html>
<head>
<title>Today's greeting</title>
</head>
<body>
<p><xsl:value-of select="vbs:x"/></p>
<p><xsl:value-of select="greeting"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

The Hello, world! comes out on in Internet Explorer but no value of 1 from the VBScript.
It seems as if the VBScript doesn't even run because I can add something like 'number = 1' in the VBScript without using a corresponding 'Dim number' and the script still runs, no expected undeclared variable error.
I have tried MSXMLv2 3.0 and 4.0sp2. Anyone know why this doesn't work?
 
As far as I know... you have to make an XSL:Variable...

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xslscript="[URL unfurl="true"]http://www.domain.com/mynamespace"[/URL]    
xmlns:vbs="urn:schemas-sqlxml-org:vbs">

[b]<xsl:variable name="x" select="1" />[/b]

<xsl:template match="/">
   <html>
   <head>
      <title>Today's greeting</title>
   </head>
   <body>
      <p><xsl:value-of select="$x"/></p>
    <p><xsl:value-of select="greeting"/></p>
   </body>
   </html>
</xsl:template>
</xsl:stylesheet>

Please prove me wrong...
There are some cases where I would like to use script in XSL also... ;-)
 
Hi CubeE101,

The xsl:variable does work. But I'm trying to run a VBScript as above so I can run a function to show current date. As far as I know I need to run a script with a function like VBScript in order to get the current date value. The above would be the simplest script I can think of to test but I can't seem to get it to work.
Anyone have any ideas?
 
You might try using a document.write command...
But that will only show up on the final html, because it will be processed by the client's browser...

Such as...
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xslscript="[URL unfurl="true"]http://www.domain.com/mynamespace"[/URL]    
xmlns:vbs="urn:schemas-sqlxml-org:vbs">
<xsl:template match="/">
   <html>
   <head>
      <title>Today's greeting</title>
   </head>
   <body>
      <p>[b]<script language="vbscript">document.write date</script>[/b]</p>
    <p><xsl:value-of select="greeting"/></p>
   </body>
   </html>
</xsl:template>
</xsl:stylesheet>

Hope this helps ;-)
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top