|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionOnce I started interest in XML/XSL I found that it is impossible to access ASP objects such as The ideaWell, the trick is that even XSL cannot access ASP objects, ASP itself sure can. So I'll just create a simple VBScript class with functions which allows retrieving Class ASPObjects
'returns Request object variables
'QType here represents a collection
' (QueryString, Form or Server(ServerVariables))
Public Function GetRequestVariable(Key, QType)
Select Case lcase(QType)
Case "querystring"
GetRequestVariable = CStr(Request.QueryString(Key).Item)
Case "form"
GetRequestVariable = CStr(Request.Form(Key).Item)
Case "server"
GetRequestVariable = CStr(Request.ServerVariables(Key).Item)
Case Else
GetRequestVariable = CStr(Request(Key).Item)
End Select
End Function
'returns Session object variables
Public Function GetSessionVariable(Key)
GetSessionVariable = Session(Key)
End Function
'sets Session object variable
Public Function SetSessionVariable(Key, Value)
Session(Key) = Value
SetSessionVariable = ""
End Function
End Class
How to useNow I'll talk how to use the class above in your XSL/XSLT. After creating '##### test.asp #####
'Loading XML and XSL somewhere
...
set xslProc = xslt.CreateProcessor()
set xasp = new ASPObjects 'creating our object
'adding it to XSL template
call xslProc.addObject(xasp, "urn:asp-objects")
call xslProc.Transform()
TransformXML = xslProc.output
Set xasp = Nothing 'and don't forget to free memory :)
...
Now when we have passed our object to XSL template, let's see how it can be used. First of all add another namespace ( <!--test.xslt-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xasp="urn:asp-objects">
<!--namespace added above-->
<xsl:template match="/">
<!--display value of Request.QueryString("hello")-->
<xsl:value-of
select="xasp:GetRequestVariable('hello','querystring')" />
<!--set value of Session("username")-->
<xsl:value-of
select="xasp:SetSessionVariable('username','Me!')" />
</xsl:template>
...
</xsl:stylesheet>
That's all actually. I told you it wasn't that hard :). Now you can extend the class so it will work with
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||