本文整理汇总了C#中System.Xml.Xsl.XslCompiledTransform类的典型用法代码示例。如果您正苦于以下问题:C# XslCompiledTransform类的具体用法?C# XslCompiledTransform怎么用?C# XslCompiledTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XslCompiledTransform类属于System.Xml.Xsl命名空间,在下文中一共展示了XslCompiledTransform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRecord
/// <summary>
/// Processes the record.
/// </summary>
protected override void ProcessRecord()
{
this.WriteVerbose("Formatting log");
using (var xmlReader = new StringReader(this.Log))
{
var xpath = new XPathDocument(xmlReader);
using (var writer = new StringWriter())
{
var transform = new XslCompiledTransform();
Func<string, string> selector = file => !Path.IsPathRooted(file) ? Path.Combine(Environment.CurrentDirectory, file) : file;
foreach (var fileToLoad in this.FormatFile.Select(selector))
{
this.WriteVerbose("Loading format file " + fileToLoad);
using (var stream = File.OpenRead(fileToLoad))
{
using (var reader = XmlReader.Create(stream))
{
transform.Load(reader);
transform.Transform(xpath, null, writer);
}
}
}
this.WriteObject(writer.GetStringBuilder().ToString(), false);
}
}
}
示例2: Transform
public static string Transform (string xml, string xslFile, IDictionary<string, string> xslParams)
{
XslCompiledTransform xslTrans = new XslCompiledTransform ();
xslTrans.Load (xslFile);
return Transform (xml, xslTrans, xslParams);
}
示例3: Main
public static void Main()
{
XslCompiledTransform xsltStyle = new XslCompiledTransform();
xsltStyle.Load("../../catalogstyle.xslt");
xsltStyle.Transform("../../catalog.xml", "../../catalog.html");
Console.WriteLine("catalog.html created");
}
示例4: GenerateReport
public bool GenerateReport(string fileName)
{
bool retCode = false;
ResetReportViwer();
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(rptXslPath);
if ( File.Exists(fileName) == true)
{
XPathDocument myXPathDoc = new XPathDocument(fileName);
StringWriter sw = new StringWriter();
XmlWriter xmlWriter = new XmlTextWriter(sw);
// using makes sure that we flush the writer at the end
xslt.Transform(myXPathDoc, null, xmlWriter);
xmlWriter.Flush();
xmlWriter.Close();
string xml = sw.ToString();
HtmlDocument htmlDoc = axBrowser.Document;
htmlDoc.Write(xml);
retCode = true;
}
else
{
retCode = false;
}
return retCode;
}
示例5: Main
static int Main(string[] args)
{
Console.WriteLine("XMLTo v0.1 [www.mosa-project.org]");
Console.WriteLine("Copyright 2009 by the MOSA Project. Licensed under the New BSD License.");
Console.WriteLine("Written by Philipp Garcia ([email protected])");
Console.WriteLine();
Console.WriteLine("Usage: XMLTo <xml file> <xsl file> <output file>");
Console.WriteLine();
if (args.Length < 3)
{
Console.Error.WriteLine("ERROR: Missing arguments");
return -1;
}
try {
XPathDocument myXPathDoc = new XPathDocument(args[0]);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(args[1]);
XmlTextWriter myWriter = new XmlTextWriter(args[2], null);
myXslTrans.Transform(myXPathDoc, null, myWriter);
return 0;
}
catch (Exception e) {
Console.Error.WriteLine("Exception: {0}", e.ToString());
return -1;
}
}
示例6: MigrateUsingXslt
protected static void MigrateUsingXslt(TextReader xslStream, TextReader xmlStream, string destinationFilePath)
{
var transform = new XslCompiledTransform();
using (xslStream)
{
using (xmlStream)
{
using (var destinationStream = new StreamWriter(destinationFilePath))
{
var xslReader = XmlReader.Create(xslStream);
transform.Load(xslReader);
xslReader.Close();
xslStream.Close();
var reader = XmlReader.Create(xmlStream);
var settings = new XmlWriterSettings { Indent = true };
var writer = XmlWriter.Create(destinationStream, settings);
transform.Transform(reader, writer);
var tempfiles = transform.TemporaryFiles;
if (tempfiles != null) // tempfiles will be null when debugging is not enabled
{
tempfiles.Delete();
}
writer.Close();
reader.Close();
destinationStream.Close();
}
xmlStream.Close();
}
}
}
示例7: SparqlXsltWriter
/// <summary>
/// Creates a new SPARQL XSLT Writer
/// </summary>
/// <param name="stylesheetUri">Stylesheet URI</param>
public SparqlXsltWriter(String stylesheetUri)
{
//Load the Transform
this._transform = new XslCompiledTransform();
XsltSettings settings = new XsltSettings();
this._transform.Load(stylesheetUri, settings, null);
}
示例8: TransformXml
/// <summary>
/// Perform the xml translation
/// </summary>
/// <param name="xmlRaw"></param>
/// <param name="xslSheet"></param>
/// <returns></returns>
public static XmlDocument TransformXml(XmlDocument xmlRawClean, XslCompiledTransform xslSheet)
{
XmlDocument xmlTransform = null;
XmlTextWriter xmlWriter = null;
try
{
XPathDocument xmlClean = ConvertXmlDocumentToXPathDocument(xmlRawClean);
string sTempPath = FileUtilities.GetUniqueTempFileName();
xmlWriter = new XmlTextWriter(sTempPath, null);
xslSheet.Transform(xmlClean, null, xmlWriter);
xmlWriter.Close();
xmlTransform = new XmlDocument();
xmlTransform.Load(sTempPath);
// try to clean up the file we created
try
{
File.Delete(sTempPath);
}
catch
{
}
}
catch (Exception ex)
{
throw new Exception("TransformXml", ex.InnerException);
}
return xmlTransform;
}
示例9: TransformXml
public static String TransformXml(XmlTextReader xsltReader, XmlTextReader xmlReader)
{
// Create required writer for output
StringWriter stringWriter = new StringWriter();
XmlTextWriter transformedXml = new XmlTextWriter(stringWriter);
// Create a XslCompiledTransform to perform transformation
XslCompiledTransform xsltTransform = new XslCompiledTransform();
try
{
xsltTransform.Load(xsltReader);
xsltTransform.Transform(xmlReader, new XsltArgumentList(), transformedXml);
}
catch (XmlException xmlEx)
{
// TODO : log - "Could not load XSL transform: \n\n" + xmlEx.Message
throw;
}
catch (XsltException xsltEx)
{
// TODO : log - "Could not process the XSL: \n\n" + xsltEx.Message + "\nOn line " + xsltEx.LineNumber + " @ " + xsltEx.LinePosition)
throw;
}
catch (Exception ex)
{
// TODO : log
throw;
}
return stringWriter.ToString();
}
示例10: Main
static void Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("You have not entered the correct parameters");
return;
}
string xmlfile = args[0];
string xslfile = args[1];
string outfile = args[2];
try
{
var doc = new XPathDocument(xmlfile);
var transform = new XslCompiledTransform();
var settings = new XsltSettings(true, true);
transform.Load(xslfile, settings, new XmlUrlResolver());
var writer = new XmlTextWriter(outfile, null);
transform.Transform(doc, null, writer);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
示例11: ShouldAllowAnXsltToBeRunSuccessfully
public void ShouldAllowAnXsltToBeRunSuccessfully()
{
string xhtmlPage = "http://localhost/webdriver/xhtmlTest.html";
driver.Get(xhtmlPage);
XPathNavigator navigator = driver.CreateNavigator();
XmlDocument xslDoc = new XmlDocument();
xslDoc.LoadXml(
@"<?xml version=""1.0""?>
<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">
<xsl:template match=""/"">
<xsl:copy-of select="".""/>
</xsl:template>
</xsl:stylesheet>");
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(xslDoc);
StringBuilder output = new StringBuilder();
xsl.Transform(navigator, new XsltArgumentList(), new StringWriter(output));
String result = output.ToString();
// Do we get text in the body of the transformed document?
Assert.IsTrue(result.Contains("XHTML Might Be The Future"), "No text from the body of the page");
// Do we get tag's?
Assert.IsTrue(result.Contains("<"), "No tags appear to have been opened");
Assert.IsTrue(result.Contains("</body"), "The body tag has not been closed. Check that tags are being output");
// Do we get the page's title?
Assert.IsTrue(result.Contains("XHTML Test Page"), "No title seen");
}
示例12: BeforeSendRequest
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
if (!request.IsEmpty)
{
XmlReader bodyReader = request.GetReaderAtBodyContents().ReadSubtree();
MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream);
if (transform == null)
{
transform = new XslCompiledTransform(true);
var reader = XmlReader.Create(new StringReader(Properties.Resources.XmlCleaner));
transform.Load(reader);
}
transform.Transform(bodyReader, writer);
stream.Flush();
stream.Seek(0, SeekOrigin.Begin);
bodyReader = XmlReader.Create(stream);
Message changedMessage = Message.CreateMessage(request.Version, null, bodyReader);
changedMessage.Headers.CopyHeadersFrom(request.Headers);
changedMessage.Properties.CopyProperties(request.Properties);
request = changedMessage;
}
return null;
}
示例13: Main
static void Main()
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("../../style.xslt");
xslt.Transform("../../../CatalogHolder/catalogue.xml", "../../catalogue.html");
Console.WriteLine("result saved as catalogue.html");
}
示例14: ToHtml
private string ToHtml()
{
if (Services.StrandsCache.Contains(this))
{
return Services.StrandsCache.Read(this);
}
else
{
var transform = new XslCompiledTransform(true);
var arguments = new XsltArgumentList();
var settings = new XsltSettings();
var readersettings = new XmlReaderSettings();
//string xslsrc = (!string.IsNullOrEmpty(this.DisplayType)) ? "/XMLList.xsl" : "/Strands.xsl";
//var xslfile = (this.Name == "themes") ? HttpContext.Current.Server.MapPath(this._xslAppUrl + "/StrandList.xsl") : HttpContext.Current.Server.MapPath(this._xslAppUrl + xslsrc);
var xslfile = HttpContext.Current.Server.MapPath(this._xslAppUrl + ((!string.IsNullOrEmpty(this.DisplayType)) ? "XMLList.xsl" : this.XslName));
settings.EnableDocumentFunction = true;
settings.EnableScript = true;
readersettings.DtdProcessing = DtdProcessing.Parse;
readersettings.ValidationType = ValidationType.None;
transform.Load(xslfile, settings, new XmlUrlResolver());
arguments = TransformArguments(this);
using (XmlReader reader = XmlReader.Create(this.GetDirectoryPath(), readersettings))
{
System.IO.StringWriter writer = new System.IO.StringWriter();
transform.Transform(reader, arguments, writer);
return Services.StrandsCache.Write(this, writer.ToString());
}
}
}
示例15: TransformClaimDocumentToFoXml
public string TransformClaimDocumentToFoXml(ClaimDocument document)
{
FormDocument form = new FormDocument();
foreach (var claim in document.Claims)
{
if (claim.Type == ClaimTypeEnum.Professional)
{
var pages = _professionalTransformation.TransformClaimToClaimFormFoXml(claim);
form.Pages.AddRange(pages);
}
else if (claim.Type == ClaimTypeEnum.Institutional)
{
var pages = _institutionalTransformation.TransformClaimToClaimFormFoXml(claim);
form.Pages.AddRange(pages);
}
else
form.Pages.AddRange(_dentalTransformation.TransformClaimToClaimFormFoXml(claim));
}
var xml = form.Serialize();
var transformStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.X12.Hipaa.Claims.Services.Xsl.FormDocument-To-FoXml.xslt");
var transform = new XslCompiledTransform();
if (transformStream != null) transform.Load(XmlReader.Create(transformStream));
var outputStream = new MemoryStream();
transform.Transform(XmlReader.Create(new StringReader(xml)), new XsltArgumentList(), outputStream);
outputStream.Position = 0;
return new StreamReader(outputStream).ReadToEnd();
}