public XmlOutput Transform(XmlInput input, XsltArgumentList arguments, XmlOutput output) { if (input == null) { throw new ArgumentNullException("input"); } var xmlWriter = output.Destination as XmlWriter; var closeWriter = false; if (xmlWriter == null) { closeWriter = true; while (true) { var txtWriter = output.Destination as TextWriter; if (txtWriter != null) { if (MultiOutput) { var mw = new MultiXmlTextWriter(txtWriter, output.XmlResolver); if (CompiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { xmlWriter = XmlWriter.Create(txtWriter, CompiledTransform.OutputSettings); } break; } var strm = output.Destination as Stream; if (strm != null) { if (MultiOutput) { var mw = new MultiXmlTextWriter(strm, CompiledTransform.OutputSettings.Encoding, output.XmlResolver); if (CompiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { xmlWriter = XmlWriter.Create(strm, CompiledTransform.OutputSettings); } break; } var str = output.Destination as String; if (str != null) { if (MultiOutput) { var mw = new MultiXmlTextWriter(str, CompiledTransform.OutputSettings.Encoding); if (CompiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { var outputSettings = CompiledTransform.OutputSettings.Clone(); outputSettings.CloseOutput = true; // BugBug: We should read doc before creating output file in case they are the same xmlWriter = XmlWriter.Create(str, outputSettings); } break; } throw new Exception("Unexpected XmlOutput"); } } try { TransformToWriter(input, arguments, xmlWriter); } finally { if (closeWriter) { xmlWriter.Close(); } } return(output); }
/// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlOutput"/>. /// The <see cref="XsltArgumentList"/> provides additional runtime arguments. /// </summary> /// <param name="input">Default input XML document.</param> /// <param name="arguments">An <see cref="XsltArgumentList"/> containing the namespace-qualified /// arguments used as input to the transform. This value can be a null reference (Nothing in Visual Basic).</param> /// <param name="output">Represents the transformation's output.</param> /// <returns>Transformation output.</returns> public XmlOutput Transform(XmlInput input, XsltArgumentList arguments, XmlOutput output) { if (input == null) throw new ArgumentNullException("defaltDocument"); XmlWriter xmlWriter = output.destination as XmlWriter; bool closeWriter = false; if (xmlWriter == null) { closeWriter = true; while (true) { TextWriter txtWriter = output.destination as TextWriter; if (txtWriter != null) { if (multiOutput) { MultiXmlTextWriter mw = new MultiXmlTextWriter(txtWriter, output.XmlResolver); if (this.compiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { xmlWriter = XmlWriter.Create(txtWriter, this.compiledTransform.OutputSettings); } break; } Stream strm = output.destination as Stream; if (strm != null) { if (multiOutput) { MultiXmlTextWriter mw = new MultiXmlTextWriter(strm, this.compiledTransform.OutputSettings.Encoding, output.XmlResolver); if (this.compiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { xmlWriter = XmlWriter.Create(strm, this.compiledTransform.OutputSettings); } break; } String str = output.destination as String; if (str != null) { if (multiOutput) { MultiXmlTextWriter mw = new MultiXmlTextWriter(str, this.compiledTransform.OutputSettings.Encoding); if (this.compiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { XmlWriterSettings outputSettings = this.compiledTransform.OutputSettings.Clone(); outputSettings.CloseOutput = true; // BugBug: We should read doc before creating output file in case they are the same xmlWriter = XmlWriter.Create(str, outputSettings); } break; } throw new Exception("Unexpected XmlOutput"); } } try { TransformToWriter(input, arguments, xmlWriter); } finally { if (closeWriter) { xmlWriter.Close(); } } return output; }
private void TabChanged(object sender, System.EventArgs e) { int tab = tabControl.SelectedIndex; if (tab == 0) { return; } XmlDocument doc = editor.Document; XmlProcessingInstruction stylePi = doc.SelectSingleNode( "processing-instruction('xeditnet-xsl')") as XmlProcessingInstruction; if (stylePi == null) { MessageBox.Show(this, "No xeditnet-xsl processing instruction found"); return; } Uri baseUri = new Uri(doc.BaseURI); try { Uri uri = new Uri(baseUri, stylePi.Value); FileInfo fi = new FileInfo(baseUri.LocalPath); string outputDir = fi.DirectoryName; XslTransform xsl = new XslTransform(); xsl.Load(uri.AbsolutePath); MultiXmlTextWriter mxtw = new MultiXmlTextWriter(outputDir + "/_default.html", null); try { xsl.Transform(doc, null, mxtw, null); } finally { mxtw.Close(); } } catch (Exception ex) { MessageBox.Show(this, ex.Message); return; } Selection sel = editor.Selection; if (sel.IsEmpty) { return; } string file = "_default.html"; // TODO: M: deal better with entity ref at caret if (!sel.IsEmpty && sel.Start.Node.NodeType != XmlNodeType.EntityReference) { SelectionPoint sp = sel.Start; XmlElement n = sp.Node.SelectSingleNode("ancestor::*[@id != '']") as XmlElement; if (n != null) { file = n.GetAttribute("id") + ".html"; } } Uri currentPage = new Uri(baseUri, file); webBrowser.Navigate(currentPage.LocalPath); }
/// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlOutput"/>. /// The <see cref="XsltArgumentList"/> provides additional runtime arguments. /// </summary> /// <param name="input">Default input XML document.</param> /// <param name="arguments">An <see cref="XsltArgumentList"/> containing the namespace-qualified /// arguments used as input to the transform. This value can be a null reference (Nothing in Visual Basic).</param> /// <param name="output">Represents the transformation's output.</param> public void Transform(XmlInput input, XsltArgumentList arguments, XmlOutput output) { if (input == null) { throw new ArgumentNullException("defaltDocument"); } XmlWriter xmlWriter = output.destination as XmlWriter; bool closeWriter = false; if (xmlWriter == null) { closeWriter = true; while (true) { TextWriter txtWriter = output.destination as TextWriter; if (txtWriter != null) { if (multiOutput) { MultiXmlTextWriter mw = new MultiXmlTextWriter(txtWriter, output.XmlResolver); if (this.compiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { xmlWriter = XmlWriter.Create(txtWriter, this.compiledTransform.OutputSettings); } break; } Stream strm = output.destination as Stream; if (strm != null) { if (multiOutput) { MultiXmlTextWriter mw = new MultiXmlTextWriter(strm, this.compiledTransform.OutputSettings.Encoding, output.XmlResolver); if (this.compiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { xmlWriter = XmlWriter.Create(strm, this.compiledTransform.OutputSettings); } break; } String str = output.destination as String; if (str != null) { if (multiOutput) { MultiXmlTextWriter mw = new MultiXmlTextWriter(str, this.compiledTransform.OutputSettings.Encoding); if (this.compiledTransform.OutputSettings.Indent) { mw.Formatting = Formatting.Indented; } xmlWriter = mw; } else { XmlWriterSettings outputSettings = this.compiledTransform.OutputSettings.Clone(); outputSettings.CloseOutput = true; // BugBug: We should read doc before creating output file in case they are the same xmlWriter = XmlWriter.Create(str, outputSettings); } break; } throw new Exception("Unexpected XmlOutput"); } } try { TransformToWriter(input, arguments, xmlWriter); } finally { if (closeWriter) { xmlWriter.Close(); } } }