XML transformation: transform XML file to HTML file : XML Transform « XML « C# / C Sharp

XML transformation: transform XML file to HTML file

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

  public class XSLDemo
    static void Main(string[] args)
      XslTransform xslt = new XslTransform();
      XPathDocument xDoc = new XPathDocument("Books.xml");
      XmlTextWriter writer = new XmlTextWriter("Books.html", null);
      xslt.Transform(xDoc, null, writer, new XmlUrlResolver());
      StreamReader stream = new StreamReader("Books.html");
  <book category="A">
  <book category="B">
    <title>title 2</title>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/" >

<head><title>A list of books</title></head>
.headerClass { background-color=#ffeedd; }
<B>List of books</B>
<table border="1">
  <td class="headerClass">Title</td>
  <td class="headerClass">Author</td>
  <td class="headerClass">Price</td>
<xsl:for-each select="//books/book">
  <td><xsl:value-of select="title"/></td>
  <td><xsl:value-of select="author"/></td>
  <td><xsl:value-of select="price"/></td>




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.Illustrates the XslTransform classIllustrates the XslTransform class
5.Perform an XSL Transformation using XML and XSL content and with some XSLT arguments
6.Xslt Transformation Helper