Re: XSl transformation not happening in asp page by nivi
nivi
Tue Jul 11 13:16:05 CDT 2006
Hi Anthony,
Thanks a lot for the ideas and the code
That worked
I used the method 1, i already had the xsl style sheet
Thanks again,
Nivi
Anthony Jones wrote:
> "nivi" <Nivedita.Venugopal@gmail.com> wrote in message
> news:1152297117.667428.279740@m73g2000cwd.googlegroups.com...
> > Hi Gurus,
> >
> > I have a problem with the way my output gets displayed in my asp page
> > I have the UI in ASP which asks for input from a user on the asp page
> > and then passes that data to a perl file which further processes it and
> > passes it back to the asp in an xml format
> > Finally the asp page has to open the output in html in the same page.
> > The created xml file has the details to the xsl stylesheet .
> > but presently the o/p gets diaplyed in an xml format in the asp and not
> > in a html format
> > <?xml version="1.0"?>
> > <?xml-stylesheet .......
> > <component>.....</component>
> >
> > I do know that when this output file is opened in a browser it is a
> > neatly (xsl) transformed page
>
> The transform is here being performed by the browser. The server has simply
> sent the XML.
>
> > how do i make the output also appear the same way in my asp page
> > can i force the asp to understand it as a html?
> >
> > I am presently doing this in my asp
> > Response.Write "receive: "&objXMLHTTP.status&"
> > "&objXMLHTTP.statusText&"<xmp>"&objXMLHTTP.ResponseText&"</xmp>"
>
> Again the ResponseText will simply contain XML text.
>
> >
> >
> > Please advise
> > Thanks in advance
> > Nivi
> >
>
> If you want to perform the transform on your ASP server you will need to
> execute it yourself.
> I'll assume the remote server has specified the content type it is send is
> "text/xml" therefore the ResponseXML property should return an XML DOM.
>
> Dim oNode
> Dim sTransformResult
> Dim sTransformHref
>
> Set xml = objXMLHTTP.ResponseXML
>
> sTransformHRef = "<url goes here" 'Replace with the URL to the XSL
>
> Set xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
> xsl.async = false
> xsl.setProperty "ServerHTTPRequest", True
> xsl.load sTransformHref
>
> sTransformResult = oDOM.transformNode(xsl)
>
>
> Of course this presupposes that you know what the value of sTransformHref
> will be. If not then it needs to be
> harvested from the xml-stylesheet processing instruction in the DOM and then
> resolved to a full URL. Thats a lot more work. Add these functions to your
> page:-
>
> Function GetStyleSheetHRef(roDOM)
>
> Dim roDOM
>
> For Each oNode in roDOM.childNodes
> If oNode.nodeTypeString = "processinginstruction" Then
> If oNode.nodeName = "xml-stylesheet" Then
> GetStyleSheetHRef = ExtractHREF(oNode.nodeValue)
> Exit For
> End If
> End If
> Next
>
> End Function
>
> Function ExtractHREF(rsValue)
> Dim rgx
> Dim oMatches
>
> Set rgx = New RegExp
> rgx.pattern = "href=""(.*?)"""
> rgx.IgnoreCase = True
>
> Set oMatches = rgx.Execute(rsValue)
> If oMatches.Count > 0 Then
> ExtractHREF = oMatches.Item(0).SubMatches(0)
> End If
>
> End Function
>
> Function ResolvePath(rsOriginalPath, rsNewPath)
>
> Dim rgx
> Dim oOrigMatch
> Dim oNewMatch
>
> Set rgx = New RegExp
> rgx.pattern = "(https?\://.+?(?=/))?((?:.*/)*)(.*)$"
> rgx.IgnoreCase = True
>
> oNewMatch = rgx.Execute(rsNewPath)(0)
> oOrigMatch = rgx.Execute(rsOriginalPath)(0)
>
> If oNewMatch.SubMatches(0) <> "" Then
> ResolvePath = rsNewPath
> ElseIf oNewMatch.SubMatches(1) = "" Then
> ResolvePath = oOrigMatch.SubMatches(0) & oOrigMatch.SubMatches(1) &
> rsNewPath
> ElseIf Left(oNewMatch.SubMatches(1),1) <> "/" Then
> ResolvePath = oOrigMatch.SubMatches(0) & oOrigMatch.SubMatches(1) &
> rsNewPath
> Else
> ResolvePath = oOrigMatch.SubMatches(0) & rsNewPath
> End If
>
> End Function
>
>
> Obviously you will have the URL to the original XML you've retrieved and
> given that you have that in a variable called sOriginalHRef you can use this
> line of code to resolve sTransformHRef:-
>
> sTransformHRef = ResolvePath(sOriginalHRef, GetStyleSheetHRef(xml))
>
> Note this is untested code and doesn't handle exceptionals well.
>
> HTH,
>
> Anthony.