Subject: Re: [xsl] Import ASP Request Object into XSLT From: "David B. Bitton" <david@xxxxxxxxxxxxxx> Date: Wed, 03 Apr 2002 23:14:59 -0500 |
-- David B. Bitton david@xxxxxxxxxxxxxx www.codenoevil.com Code Made Fresh DailyT ----- Original Message ----- From: "Julie M. Gephart" <julie@xxxxxxxxxxxxxxx> To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, April 03, 2002 4:25 PM Subject: [xsl] Import ASP Request Object into XSLT > I generate lots of forms using XSLT on the server side to return HTML to the > client. When there is an error that requires me to re-present the form to > the user, I'd like to preserve whatever they just submitted from the Request > object. I have been able to successfully use other ASP objects in my XSLT > by using the addObject method with an XSL Processor, but I have not been > able to find a way to make it work with Request (or Request.Form or > Request.QueryString). Below is code that works for using the ASP Session > object - can anyone make something similar work with Request? > > > <% 'ASP VBS code > > 'Put something into a session variable > Session("TESTVARIABLE") = "TestValue" > > sXML="<xml></xml>" 'xml unimportant in this example > sXSLpath = server.MapPath("mystylesheet.xsl") > > 'Create the Template and Processor objects > Set xmlDoc = server.CreateObject ("Msxml2.FreeThreadedDOMDocument.3.0") > xmlDoc.async = false > xmlDoc.loadXML(sXML) > Set xslt = server.CreateObject("MSXML2.XSLTemplate.3.0") > Set xslDoc = server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0") > xslDoc.async = false > xslDoc.load(sXSLpath) > xslt.stylesheet = xslDoc > Set xslProc = xslt.createProcessor() > xslProc.input = xmlDoc > > xslProc.addObject Session, "urn:ASPSession" > xslProc.transform > sOutput = xslProc.output > response.write sOutput > > %> ok, first problem is here. you should be setting the ouput property of the processor to the Response object like this: xslProc.output = Response then transforming like this: xslProc.transform this sends the ouput of the processor directly to the IStream interface of the Response object. Now, the only benefit to using the processor at all is caching the processed XSLT stylesheet in the ASP Application object. This is my utility function: function getProcessor(sXML, sStyleSheet) set oXML = server.createobject("MSXML2.FreeThreadedDOMDocument.4.0") oXML.async = false oXML.loadXML sXML If Not IsObject(application(sStyleSheet)) Then set oXSL = server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0") oXSL.async = false oXSL.load (server.MapPath(sStyleSheet & ".xsl")) set oTMP = server.CreateObject("MSXML2.XSLTemplate.4.0") oTMP.stylesheet = oXSL.documentElement Application.Lock set Application(sStyleSheet) = oTMP Application.UnLock set oXSL = nothing set oTMP = nothing End if set getProcessor = application(sStyleSheet).createProcessor getProcessor.input = oXML.documentElement getProcessor.output = Response set oXML = nothing end function This function returns an XSL processor object. Once you have it back, just call the transform() method. > > XSLT: ("mystylesheet.xsl") > <?xml version="1.0"?> > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > xmlns:Session="urn:ASPSession" > > > <xsl:output method="html" indent="yes"/> > > <xsl:template match="/"> > Session Test value=<xsl:value-of > select="Session:get-Contents('TESTVARIABLE')"/> > </xsl:template> > > </xsl:stylesheet> > > I would think that "Request:get-QueryString('TestVar')" would be an > identical structure to "Session:get-Contents('TestVar')", but apparently it > is not. > As for reading values from the Request object inside the stylesheet, you should be passing them into the stylesheet as xsl:param's. Add this to the top of the stylesheet just after the xsl:stylesheet <xsl:param name="foo"/> and you set this by adding a parameter value to the template processor's parameter collection like this: xslProc.addParameter "foo", Request.QueryString("foo") Do this before you call transform ( I mention this for posterity's sake) and then you can reference this value anywhere inside the stylesheet by using the param name $foo, so to test, add this: <xsl:value-of select="$foo"/> and you should get the value that was passed in from the querystring. I hope this helped. :) > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Import ASP Request Object int, Julie M. Gephart | Thread | Re: [xsl] Import ASP Request Object, murali meraga |
RE: [xsl] RE: Next node name, Casadome, Francisco | Date | RE: [xsl] Replacing Attributes, stevenson |
Month |