ASP.NET
  Home arrow ASP.NET arrow XSL Transformation in C# by Jochen Hofmann
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

XSL Transformation in C# by Jochen Hofmann
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2001-11-17

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    XSL Transformation in C# by

    A C# class That can transform an XMLDocument to HTML (Text) or or an XMLDocument. It is very flexible and provides several overloads for the transform method. You can post this class to your C# or XML section. Any comments / improvements to the code are appreciated. Jochen....

    Here's a sample How to call the class:
    XSLTransform objTrans = new XSLTransform();
    Response.Write(objTrans.Transform("d:\projects\test.xml","d:\test.xsl"));

    Here is the code for the Class

    using System;
    
    using System.Xml;
    using System.Xml.Xsl;
    using System.Xml.XPath;
    using System.IO;

    namespace KontoDotNet3
    {
    ///
    /// Zusammenfassungsbeschreibung fĂĽr XSLTransform.
    ///

    public class XSLTransform
    {
    private string strXSLFile;
    public string XSLFile
    {
    set
    {
    strXSLFile = value;
    }
    get
    {
    return strXSLFile;
    }
    }

    public XSLTransform()
    {

    }
    public XSLTransform(string sXSLFile)
    {
    strXSLFile = sXSLFile;
    }

    public string Transform(ref XmlDocument xd)
    {
    XPathNavigator xdNav = xd.CreateNavigator();
    XslTransform tr = new XslTransform();
    tr.Load(strXSLFile);
    StringWriter sw = new StringWriter();
    tr.Transform(xdNav,null,sw);
    return sw.ToString();
    }

    public string Transform(ref XmlDocument xd, ref XmlDocument xsl)
    {
    XPathNavigator xdNav = xd.CreateNavigator();
    XslTransform tr = new XslTransform();
    tr.Load(new XmlNodeReader(xsl));
    //Bug in DotNet Beta 2
    normal: tr.Load(xsl);
    StringWriter sw = new StringWriter();
    tr.Transform(xdNav,null,sw);
    return sw.ToString();
    }

    public string Transform(string sXMLDocument, string sXSLFile)
    {
    XmlDocument xd = new XmlDocument();
    xd.Load(sXMLDocument);
    XPathNavigator xdNav = xd.CreateNavigator();
    XslTransform tr = new XslTransform();
    tr.Load(sXSLFile);
    StringWriter sw = new StringWriter();
    tr.Transform(xdNav,null,sw);
    return sw.ToString();
    }

    public string Transform(string sXMLDocument)
    {
    XmlDocument xd = new XmlDocument();
    xd.Load(sXMLDocument);
    XPathNavigator xdNav = xd.CreateNavigator();
    XslTransform tr = new XslTransform();
    tr.Load(strXSLFile);
    StringWriter sw = new StringWriter();
    tr.Transform(xdNav,null,sw);
    return sw.ToString();
    }

    public void Transform(ref XmlDocument xd, ref XmlDocument xsl, _
    ref XmlDocument retXD)

    {
    XPathNavigator xdNav = xd.CreateNavigator();
    XslTransform tr = new XslTransform();
    tr.Load(new XmlNodeReader(xsl));
    //Bug in DotNet Beta 2 normal: tr.Load(xsl);
    StringWriter sw = new StringWriter();
    tr.Transform(xdNav,null,sw);
    retXD.LoadXml(sw.ToString());
    }

    }
    }


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! Download DB2 9.5 for Linux, Unix, and Windows

    Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Functional Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Try IBM Rational Asset Manager V7.0 online!

    You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek