XSl transformation not happening in asp page

Discussion in 'ASP General' started by nivi, Jul 7, 2006.

  1. nivi

    nivi Guest

    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 .......

    I do know that when this output file is opened in a browser it is a
    neatly (xsl) transformed page
    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&"

    Please advise
    Thanks in advance
    nivi, Jul 7, 2006
    1. Advertisements

  2. The transform is here being performed by the browser. The server has simply
    sent the XML.
    Again the ResponseText will simply contain XML text.
    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

    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

    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) &
    ElseIf Left(oNewMatch.SubMatches(1),1) <> "/" Then
    ResolvePath = oOrigMatch.SubMatches(0) & oOrigMatch.SubMatches(1) &
    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.


    Anthony Jones, Jul 8, 2006
    1. Advertisements

  3. nivi

    nivi Guest

    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, Jul 11, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.