本文整理汇总了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);
}
}
示例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();
}
}
示例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();
}
}
示例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);
示例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);
示例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);
示例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");
示例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 );
}
}
}