本文整理汇总了C#中System.Xml.Xsl.XslCompiledTransform.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# XslCompiledTransform.Transform方法的具体用法?C# XslCompiledTransform.Transform怎么用?C# XslCompiledTransform.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Xsl.XslCompiledTransform
的用法示例。
在下文中一共展示了XslCompiledTransform.Transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildNavigator
public void BuildNavigator(string modelFilePath)
{
XmlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;
XmlTextReader tr = new XmlTextReader(modelFilePath);
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(this.stylesheetFilesPath + Path.DirectorySeparatorChar + "ModelTree.xsl",null,resolver);
XmlTextWriter tw = new XmlTextWriter(this.htmlFilesPath + Path.DirectorySeparatorChar + "ModelTree.htm", Encoding.UTF8);
XsltArgumentList al = new XsltArgumentList();
al.AddParam("modelBrowser","",this.localizer.GetValue("Globals","ModelBrowser"));
al.AddParam("glossary","",this.localizer.GetValue("Globals","Glossary"));
al.AddParam("stakeholders", "", this.localizer.GetValue("Globals", "Stakeholders"));
transform.Transform(tr,al,tw,null);
tw.Close();
tr.Close();
tr = new XmlTextReader(modelFilePath);
transform.Load(this.stylesheetFilesPath + Path.DirectorySeparatorChar + "HomePage.xsl",null,resolver);
tw = new XmlTextWriter(this.htmlFilesPath + Path.DirectorySeparatorChar + "main.htm",Encoding.UTF8);
al = new XsltArgumentList();
AssemblyName an = this.GetType().Assembly.GetName();
al.AddParam("version","",an.Version.ToString(3));
al.AddParam("model", "", this.localizer.GetValue("Globals", "Model"));
al.AddParam("author", "", this.localizer.GetValue("Globals", "Author"));
al.AddParam("company", "", this.localizer.GetValue("Globals", "Company"));
al.AddParam("creationDate", "", this.localizer.GetValue("Globals", "CreationDate"));
al.AddParam("exportPrintDate", "", this.localizer.GetValue("Globals", "ExportPrintDate"));
al.AddParam("now", "", Convert.ToString(DateTime.Now, DateTimeFormatInfo.InvariantInfo));
al.AddParam("release", "", this.localizer.GetValue("Globals", "Release"));
transform.Transform(tr,al,tw,null);
tw.Close();
tr.Close();
}
示例2: description_Click
/// <summary>
/// Displays the description of the project that is clicked.
/// </summary>
/// <param name="sender">Link on the project name</param>
/// <param name="e">Arguments given to this command (project id)</param>
public void description_Click(Object sender, EventArgs e)
{
ProjectAccess projectAccess = new ProjectAccess();
// gets path to the xslt file
string path = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, @"xslt\fullProjectDescription.xslt");
// Gets id of the project that must be displayed
LinkButton description = sender as LinkButton;
int idProject = Int32.Parse((string)description.CommandArgument);
// Gets project data from database
Project project = projectAccess.getProject(idProject);
List<Technology> technos = projectAccess.getTechnologyProject(idProject);
// Loads xslt file and executes the transformation to html. Result is stored in a StringWriter.
string xml = "<project>\n";
xml += "<title>" + project.Name + "</title>\n";
xml += "<abreviation>" + project.Abreviation + "</abreviation>\n";
xml += "<description>" + project.Description + "</description>\n";
xml += "<nbStudent>" + project.NbStudents + "</nbStudent>\n";
xml += "<technologies>\n";
foreach(Technology techno in technos){
xml += "<technology>" + techno.Name + "</technology>\n";
}
xml += "</technologies>\n";
xml += "</project>\n";
XPathDocument doc = new XPathDocument(new StringReader(xml));
XslCompiledTransform xslt = new XslCompiledTransform();
StringWriter sw = new StringWriter();
xslt.Load(path);
// get image from database
byte[] image = projectAccess.getImage(idProject);
if (image != null)
{
string encodedImage = "data:image/jpg;base64,";
encodedImage += base64Encode(image);
XsltArgumentList argsList = new XsltArgumentList();
argsList.AddParam("IMAGE", "", encodedImage);
xslt.Transform(doc, argsList, sw);
}
else
xslt.Transform(doc, null, sw);
descriptionPanel.Controls.Add(new LiteralControl(sw.ToString()));
}
示例3: runTransform
public static bool runTransform(string xmlPath, string xsltPath, string outputPath, XsltArgumentList argList)
{
XmlTextReader reader = null;
XmlWriter writer = null;
try
{
XsltSettings xslt_set = new XsltSettings();
xslt_set.EnableScript = true;
xslt_set.EnableDocumentFunction = true;
// Load the XML source file.
reader = new XmlTextReader(xmlPath);
// Create an XmlWriter.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = new UTF8Encoding();
settings.OmitXmlDeclaration = false;
writer = XmlWriter.Create(outputPath, settings);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xsltPath, xslt_set, new XmlUrlResolver());
if (argList == null)
xslt.Transform(reader, writer);
else
xslt.Transform(reader, argList, writer);
reader.Close();
writer.Close();
return true;
}
catch (Exception err)
{
try
{
if (reader != null)
reader.Close();
if (writer != null)
writer.Close();
throw (err);
}
catch (Exception err2)
{
MessageBox.Show(err2.ToString());
return false;
}
}
}
示例4: Main
public static void Main()
{
XslCompiledTransform xsltStyle = new XslCompiledTransform();
xsltStyle.Load("../../catalogstyle.xslt");
xsltStyle.Transform("../../catalog.xml", "../../catalog.html");
Console.WriteLine("catalog.html created");
}
示例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: 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;
}
示例7: Main
static int Main (string [] args)
{
if (args.Length != 2) {
Console.WriteLine ("Usage: mono gen-apidiff-html.exe <diff_dir> <html_file>");
return 1;
}
string diff_dir = args[0];
string out_file = args[1];
var all = new XmlDocument ();
all.AppendChild(all.CreateElement ("assemblies"));
foreach (string file in Directory.EnumerateFiles(diff_dir, "*.apidiff")) {
Console.WriteLine ("Merging " + file);
var doc = new XmlDocument ();
doc.Load (file);
foreach (XmlNode child in doc.GetElementsByTagName ("assembly")) {
XmlNode imported = all.ImportNode (child, true);
all.DocumentElement.AppendChild (imported);
}
}
var transform = new XslCompiledTransform ();
transform.Load ("mono-api.xsl");
var writer = new StreamWriter (out_file);
Console.WriteLine (String.Format ("Transforming to {0}...", out_file));
transform.Transform (all.CreateNavigator (), null, writer);
writer.Close ();
return 0;
}
示例8: Main
public static void Main()
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XsltPath);
xslt.Transform(CataloguePath, HtmlPath);
Console.WriteLine("Successfully transformed in catalogue.html");
}
示例9: TransformXml
private void TransformXml()
{
XslCompiledTransform xslTransformer = new XslCompiledTransform();
xslTransformer.Load( Server.MapPath( AttributeValue("XSLTFile") ) );
Rock.Web.Cache.Page rootPage;
if ( AttributeValue( ROOT_PAGE ) != string.Empty )
{
int pageId = Convert.ToInt32( AttributeValue( ROOT_PAGE ) );
if ( pageId == -1 )
rootPage = PageInstance;
else
rootPage = Rock.Web.Cache.Page.Read( pageId );
}
else
rootPage = PageInstance;
int levelsDeep = Convert.ToInt32( AttributeValue( NUM_LEVELS ) );
XDocument pageXml = rootPage.MenuXml( levelsDeep, CurrentUser );
StringBuilder sb = new StringBuilder();
TextWriter tw = new StringWriter( sb );
xslTransformer.Transform( pageXml.CreateReader(), null, tw );
phContent.Controls.Clear();
phContent.Controls.Add( new LiteralControl( sb.ToString() ) );
}
示例10: transform
public static string transform(this string xml, string xslt, IDictionary parameters)
{
var trans = new XslCompiledTransform();
trans.Load(xslt.asXPathNavigable(), XsltSettings.TrustedXslt, new FilePathXmlResolver(myapp.files));
var args = XsltStandardExtension.PrepareArgs();
if (null != parameters)
{
foreach (var parameter in parameters.Keys)
{
var nameorns = parameter.ToString();
var paramorext = parameters[parameter];
bool ext = true;
if (paramorext is XPathNavigator || paramorext is XPathNavigator || paramorext is string || paramorext is ValueType)
{
ext = false;
}
if (ext)
{
args.AddExtensionObject(nameorns, paramorext);
}
else
{
args.AddParam(nameorns, string.Empty, paramorext);
}
}
}
var sw = new StringWriter();
trans.Transform(xml.asXPathNavigable(), args, sw);
return sw.ToString();
}
示例11: TransformOneXML
public void TransformOneXML(FileInfo xmlFile, FileInfo targetFile)
{
Steps.Log.Debug("Brug ProcessStartInfo class");
Steps.Log.Debug("Skriv 'Transform -s:source -xsl:stylesheet -o:output'");
Steps.Log.DebugFormat("Dvs: 'Transform -s:{0} -xsl:{1} -o:{2}'", xmlFile.FullName, XSLTFile.FullName,
targetFile);
try
{
XPathDocument myXPathDocument = new XPathDocument(xmlFile.FullName);
var myXslTransform = new System.Xml.Xsl.XslCompiledTransform();
XmlTextWriter writer = new XmlTextWriter(targetFile.FullName, Encoding.UTF8);
myXslTransform.Load(XSLTFile.FullName);
myXslTransform.Transform(myXPathDocument, null, writer);
writer.Close();
string id = xmlFile.Name.Replace("dataextract", "").Replace(".xml", "");
string o = @"""";
string[] lines = File.ReadAllLines(targetFile.FullName, Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
lines[i] = lines[i].Replace(" xmlns=" + o + o, "").Replace("Creator", "Creator " + id).Replace("1</eadid>", id+"</eadid>");
}
File.WriteAllLines(targetFile.FullName, lines, Encoding.UTF8);
}
catch (Exception e)
{
Steps.Log.Debug(e);
}
}
示例12: BuildRDLCStream
public static Stream BuildRDLCStream(
DataSet data, string name, string reportResource)
{
using (MemoryStream schemaStream = new MemoryStream())
{
// save the schema to a stream
data.WriteXmlSchema(schemaStream);
schemaStream.Seek(0, SeekOrigin.Begin);
// load it into a Document and set the Name variable
XmlDocument xmlDomSchema = new XmlDocument();
xmlDomSchema.Load(schemaStream);
xmlDomSchema.DocumentElement.SetAttribute("Name", data.DataSetName);
// Prepare XSL transformation
using (var sr = new StringReader(reportResource))
using (var xr = XmlReader.Create(sr))
{
// load the report's XSL file (that's the magic)
XslCompiledTransform xform = new XslCompiledTransform();
xform.Load(xr);
// do the transform
MemoryStream rdlcStream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(rdlcStream);
xform.Transform(xmlDomSchema, writer);
writer.Close();
rdlcStream.Seek(0, SeekOrigin.Begin);
// send back the RDLC
return rdlcStream;
}
}
}
示例13: TransformHtml
public static void TransformHtml(XmlSerializer serializer, object report, Type reportType, string outputFilePath, GeneratorConfiguration generatorConfiguration, string xsltFile)
{
var xmlOutputWriter = new StringWriter();
serializer.Serialize(xmlOutputWriter, report);
XslCompiledTransform xslt = new XslCompiledTransform();
var xsltSettings = new XsltSettings(true, false);
XmlResolver resourceResolver;
var reportName = reportType.Name.Replace("Generator", "");
using (var xsltReader = GetTemplateReader(reportType, reportName, xsltFile))
{
resourceResolver = new XmlResourceResolver();
xslt.Load(xsltReader, xsltSettings, resourceResolver);
}
var xmlOutputReader = new XmlTextReader(new StringReader(xmlOutputWriter.ToString()));
XsltArgumentList argumentList = new XsltArgumentList();
argumentList.AddParam("feature-language", "", generatorConfiguration.FeatureLanguage.Name);
argumentList.AddParam("tool-language", "", generatorConfiguration.ToolLanguage.Name);
using (var xmlTextWriter = new XmlTextWriter(outputFilePath, Encoding.UTF8))
{
xslt.Transform(xmlOutputReader, argumentList, xmlTextWriter, resourceResolver);
}
}
示例14: UIButton6_TouchUpInside
partial void UIButton6_TouchUpInside(UIButton sender)
{
var xslt = new XslCompiledTransform();
using (var stringReader = new StringReader(txtXslt.Text))
{
using(var xmlReader = XmlReader.Create(stringReader))
{
xslt.Load(xmlReader);
}
}
using (var stringReader = new StringReader(txtXml.Text))
{
using (var xmlreader = XmlReader.Create(stringReader))
{
try
{
var stringBuilder = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(stringBuilder))
{
xslt.Transform(xmlreader, xmlWriter);
}
txtResult.Text = stringBuilder.ToString();
}
catch(Exception ex)
{
txtResult.Text = ex.Message;
}
}
}
}
示例15: Mutate
/// <summary>
/// Mutate a WiX document as a string.
/// </summary>
/// <param name="wix">The Wix document element as a string.</param>
/// <returns>The mutated Wix document as a string.</returns>
public override string Mutate(string wixString)
{
try
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(this.transform, XsltSettings.TrustedXslt, new XmlUrlResolver());
using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(wixString)))
{
using (StringWriter stringWriter = new StringWriter())
{
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
xmlSettings.IndentChars = " ";
xmlSettings.OmitXmlDeclaration = true;
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, xmlSettings))
{
xslt.Transform(xmlReader, xmlWriter);
}
wixString = stringWriter.ToString();
}
}
}
catch (Exception ex)
{
this.Core.OnMessage(UtilErrors.ErrorTransformingHarvestedWiX(this.transform, ex.Message));
return null;
}
return wixString;
}