Question ASP.NET and XSL...new to .NET

stats

Member
Joined
Jan 15, 2009
Messages
11
Programming Experience
1-3
I'm really new to .NET but I'm good with XSL. I'm trying to use XslCompiledTransform to run the XSL off of .NET. When I try to run my code I don't get any errors but the output is blank. Am I doing something really small and stupid or am I completely off? This is starting to drive me nuts and I've been searching all over for help. If you have any idea can you please help me? Thanks.

VB.NET:
Imports System
Imports System.Xml.Xsl ' contains class XslCompiledTransform

Partial Class Default2
    Inherits System.Web.UI.Page
    Sub Page_Load()
        Dim transformer As XslCompiledTransform

        transformer = New XslCompiledTransform() ' create transformer
        transformer.Load("shs_nba_standings.xsl") ' load and compile the style sheet

        transformer.Transform("NBA_TEAM_STANDINGS.XML", "standings.html")
        Response.Write(System.IO.File.ReadAllText("standings.html"))
    End Sub
End Class
 
Use Server.MapPath to get absolute path. You don't get any errors? I get a "Could not find file : c:\wrongpath\test.xsl" debug message in browser and is thrown back to Visual Studio where I get a FileNotFoundException pointing to the offending line. How weird is that not getting debugging help from Visual Studio? It's one of the three main functionalities of VS after all.

You can also write directly to OutputStream without going through file system. Example:
VB.NET:
Dim transformer As New System.Xml.Xsl.XslCompiledTransform() 
transformer.Load(Server.MapPath("test.xsl"))
transformer.Transform(Server.MapPath("test.xml"), Nothing, Response.OutputStream)
Response.End()
 
Yeah the Server.MapPath cleared up my main problem. I actually was getting errors but wasn't really looking in the right place. I'm still trying to figure this whole thing out but my page works. Thanks a lot for the reply. I expected to get a bunch of **** for not knowing anything. Thanks again.
 
Also note that if all you need to do is transform and display you can use the Xml control instead, just add it to page in from Toolbox in Designer and select the source documents (DocumentSource and TransformSource), the paths for these will display as "~/test.xsl" after selection, no code is needed.
 
Back
Top