SunQuest
 
       ASP.NET
  Home arrow ASP.NET arrow XSL Transformation in C# by Jochen Hofmann
Iron Speed
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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
     
    IBM developerWorks
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    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!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! Calling all CC Power Users – and those that would like to be!

    Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
    FREE! Go There Now!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Achieving True Agility -- How process can change the behavior of your tools

    Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    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! Trial download: IBM Lotus Forms V3.0

    Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format.
    FREE! Go There Now!


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

    Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET ARTICLES

    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...
    - Order-Related Modules for an ASP.NET AJAX Se...
    - User and Role Management for an ASP.NET AJAX...
    - Programming an ASP.NET AJAX Server-Centric B...

    Iron Speed




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway