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

Using inline vbscript in HTML within XSL

Status
Not open for further replies.

techkate

Programmer
Feb 23, 2004
118
US
I have an xsl file that outputs html. What is the proper way to include inline vb scripting?

For example, when not working in xsl, I would typically do something like this:

Code:
<%
dim myVar = 'frak'
%>
<span><%= myVar%></span>

I've been playing around with escaping and such, but I can't quite get my finger on the way to do this within xsl.


Kate

[small]"Forever dork"[/small]

 
The way to access variables of the kind can be done like this.

[1] Embed a class to interface the variables on the asp page with the xsl document. It is inside the <% ... %> to begin with.
[tt]
<%
'something else

class asp_xsl
public function getgvar(x)
getgvar=eval(x)
end function
end class

'some other thing such as myVar
dim myVar
myVar="frak"
'etc etc
'such as the algorithm of xml and transformation like [3]
'etc etc
%>
[/tt]
[2] Then you script the xsl source file like this with a namespace (arbitrary) extension.
[tt]
<xsl:stylesheet version="1.0" xmlns:xsl=" [blue]xmlns:aspxsl="urn:asp-xsl-interfacing"[/blue]>
<!-- etc etc -->
<span>
<xsl:value-of select="aspxsl:getgvar('myVar')" />
</span>
<!-- etc etc -->
</xsl:stylesheet>
[/tt]
[3] Again back to the asp page. Inside the <% ... %> where you instantiate processors (xml parser and xsl processor), you use addobject method to attach the class to the xsl processor.
[tt]
set xslt=createobject("msxml2.xsltemplate.3.0")
set xslDoc=createobject("msxml2.freethreadeddomdocument.3.0")
set xmlDoc=createobject("msxml2.domdocument.3.0")
'etc etc including loading xml, xsl... with error handling ignored here

xslDoc.asyn=false
xslDoc.load path_to_xsl.xsl
'error handling
set xslt.stylesheet=xslDoc

xmlDoc.asyn=false
xmlDoc.load path_to_xml.xml
'error handling
set xslProc=xslt.createprocessor()
xslProc.input=xmlDoc
'this depends on how to use the transformed output
xslProc.output=response 'asp object
'now this is the main dish
[blue]set ointerface=new asp_xsl
xslProc.addObject ointerface, "urn:asp-xsl-interfacing"[/blue]
xslProc.transform()
[blue]set ointerface=nothing[/blue]
[/tt]
[4] That is the skeleton of how to get thing done. Most of transformation algorithm is quite standard though involved. (Actually the more advanced the thing looks, most often the easier it is.) If you are not familiar with that algor, check out msdn knowledge base for detail.

[5] The elaboration of the skeleton can be well beyond recognition. But the above contains the essential idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top