Create Stylesheet : Xslt « XML « C# / CSharp Tutorial






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

public class CreateStylesheet {
  private const string ns = "http://www.w3.org/1999/XSL/Transform";

  public static void Main(string [] args) {
    XmlTextWriter writer = new XmlTextWriter(Console.Out);
    writer.Formatting = Formatting.Indented;

    writer.WriteStartDocument();

    writer.WriteStartElement("xsl","stylesheet",ns);
    writer.WriteAttributeString("version","1.0");

    writer.WriteStartElement("xsl:output");
    writer.WriteAttributeString("method","html");
    writer.WriteEndElement();

    //Create Root Template 
    writer.WriteStartElement("xsl:template");
    writer.WriteAttributeString("match","/");

    writer.WriteStartElement("html");

    writer.WriteStartElement("head");

    writer.WriteStartElement("title");
    writer.WriteString("Hardware | Online Catalog");
    writer.WriteEndElement(); 

    writer.WriteEndElement(); 

    writer.WriteStartElement("xsl:apply-templates");

    writer.WriteEndElement(); 
    writer.WriteEndElement(); 
    writer.WriteEndElement(); 
    
    //Create Inventory Template
    writer.WriteStartElement("xsl:template");
    writer.WriteAttributeString("match","inventory");

    writer.WriteStartElement("body");
    writer.WriteAttributeString("bgcolor","#FFFFFF");

    writer.WriteStartElement("h1");
    writer.WriteString("Hardware");
    writer.WriteEndElement(); 

    writer.WriteStartElement("h2");
    writer.WriteString("Online Catalog");
    writer.WriteEndElement(); 

    writer.WriteStartElement("xsl:apply-templates");
    writer.WriteEndElement();

    writer.WriteEndElement(); 
    writer.WriteEndElement(); 

    writer.WriteEndElement(); 
    writer.WriteEndDocument();
  }

}








30.25.Xslt
30.25.1.Xslt Argument List
30.25.2.Create Stylesheet