Illustrates the XslTransform class : XML Transform « XML « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » XML » XML TransformScreenshots 
Illustrates the XslTransform class
Illustrates the XslTransform class

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/


/*
  Example20_3.cs illustrates the XslTransform class
*/

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

public class Example20_3 
{

    public static void Main() 
    {

        // use an XmlTextReader to open an XML document
        XmlTextReader xtr = new XmlTextReader("Cust3.xml");
        xtr.WhitespaceHandling = WhitespaceHandling.None;

        // load the file into an XmlDocuent
        XmlDocument xd = new XmlDocument();
        xd.Load(xtr);
        
        // load an XSLT file
        XslTransform xslt = new XslTransform();
        xslt.Load("Cust.xsl");

        // perform the transformation in memory
        MemoryStream stm = new MemoryStream();
        xslt.Transform(xd, null, stm);

        // and dump the results
        stm.Position = 1;
        StreamReader sr = new StreamReader(stm);
        Console.Write(sr.ReadToEnd());

        // close the reader
        xtr.Close();
    }

}

//File:Cust3.xml
/*
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Cust.xsl"?>
<NewDataSet>
    <Customers>
        <CustomerID>ALFKI</CustomerID>
        <CompanyName>Alfreds Futterkiste</CompanyName>
        <ContactName>Maria Anders</ContactName>
        <ContactTitle>Sales Representative</ContactTitle>
        <Address>Obere Str. 57</Address>
        <City>Berlin</City>
        <PostalCode>12209</PostalCode>
        <Country>Germany</Country>
        <Phone>030-0074321</Phone>
        <Fax>030-0076545</Fax>
    </Customers>
    <Customers>
        <CustomerID>BONAP</CustomerID>
        <CompanyName>A Company</CompanyName>
        <ContactName>Laurence Lebihan</ContactName>
        <ContactTitle>Owner</ContactTitle>
        <Address>12, rue des Bouchers</Address>
        <City>Marseille</City>
        <PostalCode>13008</PostalCode>
        <Country>France</Country>
        <Phone>91.24.45.40</Phone>
        <Fax>91.24.45.41</Fax>
    </Customers>
</NewDataSet>

*/

//File:Cust.xsl
/*
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body>
    <xsl:for-each select="/NewDataSet/Customers">
        <p><h2>Customer</h2>
         <br><b><xsl:value-of select="CustomerID"/></b></br>
         <br><xsl:value-of select="CompanyName"/></br>
         <br><xsl:value-of select="ContactName"/></br></p>
    </xsl:for-each>
</body>
</html>


*/

           
       
Related examples in the same category
1. Use XslCompiledTransform
2. Perform an XSL Transform
3. Read command line input and do the xml xsl translation
4. XML transformation: transform XML file to HTML file
w___w__w__.___j__a___va2_s___.c__o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.