当前位置: 首页>>代码示例>>C#>>正文


C# XslTransform.Transform方法代码示例

本文整理汇总了C#中System.Xml.Xsl.XslTransform.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# XslTransform.Transform方法的具体用法?C# XslTransform.Transform怎么用?C# XslTransform.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Xsl.XslTransform的用法示例。


在下文中一共展示了XslTransform.Transform方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public class Sample
{
  public static void Main()
  {

     // Create a DataSet and load it with customer data.
     DataSet dsNorthwind = new DataSet();        
     String sConnect;
     sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";  
     SqlConnection nwconnect = new SqlConnection(sConnect);
     String sCommand = "Select * from Customers where Region='WA'";
     SqlDataAdapter myDataAdapter = new SqlDataAdapter(sCommand, nwconnect);
     myDataAdapter.Fill(dsNorthwind,"Customers"); 

     // Load the DataSet into an XmlDataDocument.
     XmlDataDocument doc = new XmlDataDocument(dsNorthwind);   

     // Create the XslTransform object and load the stylesheet.
     XslTransform xsl = new XslTransform();     
     xsl.Load("customers.xsl");

     // Create an XPathNavigator to use in the transform.
     XPathNavigator nav = doc.CreateNavigator();

     // Create a FileStream object.
     FileStream fs = new FileStream("cust.html", FileMode.Create);
 
     // Transform the data.
     xsl.Transform(nav, null, fs, null);
  }
}
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:40,代码来源:XslTransform.Transform

示例2: Main

//引入命名空间
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample
{
  private const String filename = "books.xml";
  private const String stylesheet = "output.xsl";

  public static void Main()
  {
    //Load the stylesheet.
    XslTransform xslt = new XslTransform();
    xslt.Load(stylesheet);

    //Load the file to transform.
    XPathDocument doc = new XPathDocument(filename);
             
    //Create an XmlTextWriter which outputs to the console.
    XmlTextWriter writer = new XmlTextWriter(Console.Out);

    //Transform the file and send the output to the console.
    xslt.Transform(doc, null, writer, null);
    writer.Close();
  }
}
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:29,代码来源:XslTransform.Transform

示例3: Main

//引入命名空间
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample {

  public static void Main() {
   
    // Create a string containing the XSLT stylesheet.
    String xsltString =
    @"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
        <xsl:template match='bookstore'>
           <HTML>
              <HEAD>
                 <TITLE>Book Titles</TITLE>
             </HEAD>
             <BODY>
                <xsl:apply-templates select='book'/>
             </BODY>
          </HTML>
        </xsl:template>
        <xsl:template match='book'>
          <P><xsl:value-of select='title'/></P>
        </xsl:template>
        </xsl:stylesheet>";

    // Create the XslTransform object.
    XslTransform xslt = new XslTransform();

    // Load the stylesheet.
    StringReader rdr = new StringReader(xsltString);
    xslt.Load(new XPathDocument(rdr), null, null);

    // Transform the file and output an HTML string.
    string HTMLoutput;
    StringWriter writer = new StringWriter();
    xslt.Transform(new XPathDocument("books.xml"), null, writer, null);
    HTMLoutput = writer.ToString();
  }
}
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:43,代码来源:XslTransform.Transform

示例4: XmlUrlResolver

// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the XslTransform object.
XslTransform xslt = new XslTransform();

// Load the stylesheet.
xslt.Load("http://myServer/data/authors.xsl", resolver);

// Transform the file.
xslt.Transform("books.xml", "books.html", resolver);
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:12,代码来源:XslTransform.Transform

示例5: XslTransform

// Create the XslTransform object.
XslTransform xslt = new XslTransform();

// Load the stylesheet.
xslt.Load("titles.xsl");

// Create a resolver and specify the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential myCred;
myCred  = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain);  
resolver.Credentials = myCred;

// Transform the file using the resolver. The resolver is used
// to process the XSLT document() function.
XPathDocument doc = new XPathDocument("books.xml");
XmlReader reader = xslt.Transform(doc, null, resolver);

// Load the reader into a new document for more processing.
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(reader);
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:20,代码来源:XslTransform.Transform

示例6: XmlDocument

XmlDocument doc = new XmlDocument();
doc.Load("books.xml");

// Modify the XML file.
XmlElement root = doc.DocumentElement;
root.FirstChild.LastChild.InnerText = "12.95";

// Create an XPathNavigator to use for the transform.
XPathNavigator nav = root.CreateNavigator();

// Transform the file.
XslTransform xslt = new XslTransform();
xslt.Load("output.xsl");
XmlTextWriter writer = new XmlTextWriter("books.html", null);
xslt.Transform(nav, null, writer, null);
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:15,代码来源:XslTransform.Transform

示例7: XslTransform

//Create the XslTransform object.
XslTransform xslt = new XslTransform();

//Load the stylesheet.
xslt.Load("output.xsl");

//Transform the file.
xslt.Transform("books.xml", "books.html");
开发者ID:.NET开发者,项目名称:System.Xml.Xsl,代码行数:8,代码来源:XslTransform.Transform

示例8: Main

//引入命名空间
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public class MainClass {
   public static void Main() {
      try
      {
        XPathDocument doc = new XPathDocument( "Sample.xml" );

        StringWriter sw = new StringWriter();
        XmlTextWriter tw = new XmlTextWriter( sw );
        tw.Formatting = Formatting.Indented;
        tw.Indentation = 4;

        XslTransform tr = new XslTransform();
        tr.Load( "test.xslt" );

        tr.Transform( doc.CreateNavigator(), null, tw );
    
        tw.Close();
        sw.Close();
      }
      catch( Exception exc )
      {
          Console.WriteLine( exc.Message );
      }
    }
}
开发者ID:C#程序员,项目名称:System.Xml.Xsl,代码行数:34,代码来源:XslTransform.Transform


注:本文中的System.Xml.Xsl.XslTransform.Transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。