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

    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&"
    "&objXMLHTTP.statusText&"<xmp>"&objXMLHTTP.ResponseText&"</xmp>"


    Please advise
    Thanks in advance
    Nivi
    nivi, Jul 7, 2006
    #1
    1. Advertising

  2. "nivi" <> wrote in message
    news:...
    > 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.
    Anthony Jones, Jul 8, 2006
    #2
    1. Advertising

  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

    Anthony Jones wrote:
    > "nivi" <> wrote in message
    > news:...
    > > 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.
    nivi, Jul 11, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Dean
    Replies:
    4
    Views:
    503
    Kevin Dean
    Sep 11, 2003
  2. Replies:
    1
    Views:
    3,573
    A. Bolmarcich
    May 27, 2005
  3. Rushi
    Replies:
    4
    Views:
    440
    Magnus Henriksson
    Dec 5, 2005
  4. Replies:
    0
    Views:
    515
  5. Tudor  Tihan
    Replies:
    5
    Views:
    109
Loading...

Share This Page