Results 1 to 3 of 3

Thread: How do I display the results of an xslt tranformation? RESOLVED

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    How do I display the results of an xslt tranformation? RESOLVED

    I'm hitting a web service and request records. These records are returned as an xml string. When I get this string I have to apply an xsl style sheet to the data and present it as an html table.

    If I create an xml file from the retruned string and apply the xsl stylesheet I created, it give nice results. I just can't figure out how to take the string returned and directly apply the style sheet to it and display the results in an asp page.

    Can someone point me in the right direction?
    Last edited by MarkT; May 30th, 2004 at 03:52 PM.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    XML allows inline style sheets and links

    Try appending the stylesheet at the top after the <XML> tag...
    try that first.

    If that fails or won't work for your project, here's a snippet I lifted out of our project that uses a XSLSortTransform on the elements..

    VB Code:
    1. 'the next three lines simply load XML from a database,( you can use a file or memorystream, whatever)..
    2.  'and assigns appends it a stringbuilder
    3.  While dreader.Read
    4.             xmlstring.Append(dreader(0))
    5.         End While
    6. [b] 'heres the meat[/b]
    7.         Dim xmldoc As New System.Xml.XmlDocument
    8.  
    9.         'here we assign the actual XML to an empty XMLdocument
    10.        xmldoc.LoadXml(xmlstring.ToString)
    11.  
    12.  
    13.        'Define a transform...
    14.         Dim myXslTransform As New XslTransform
    15.         'load the XSLT
    16.         myXslTransform.Load(Page.MapPath("DropDownTree.xslt"))
    17.         'create a readable stream from the transform
    18.         Dim xr As XmlReader = myXslTransform.Transform(xmldoc, Nothing)
    19.  
    20.  
    21.         'create a new empty doc        
    22.         Dim Sorteddoc As New System.Xml.XmlDocument
    23.  
    24.         'assign the transformed XML to the new empty doc
    25.         Sorteddoc.Load(xr)

    In reality, depending on the length of the XSLT... you could simply build a XSLT using a stringbuilder and create an XSLTransform from that... all inside your code.
    Last edited by nemaroller; May 27th, 2004 at 01:39 PM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Thanks!

    I ended up using an XML Control on the web form. I just set the DocumentContent property to the xml string and the TransformSource property to the xsl file. It seems to work pretty well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width