/// <summary> /// Initializes a new instance of the <see cref="XsltView"/> class. /// </summary> /// <param name="viewInfo">Object that provides context information required for this view.</param> public XsltView(ViewInfo viewInfo) { Contract.Requires<ArgumentNullException>(viewInfo != null); this.viewInfo = viewInfo; processor = viewInfo.Processor; }
private void SummarizeOverview(XmlDocument resultDoc, string outputPath) { XmlElement resultElement = resultDoc.SelectSingleElement("/internationalization/result"); foreach (XmlElement categoryElem in resultElement.SelectNodes("category")) { XmlElement phrasesElement = categoryElem.AppendElement(resultDoc.CreateElement("phrases")); foreach (XmlElement resourceNode in categoryElem.SelectNodes("resources/resource")) { string resourceName = string.Concat( Regex.Replace(resourceNode.GetAttribute("path"), @"^.*?([^\\]+\\[^\\]+)$", "$1"), "/", resourceNode.GetAttribute("name")).Replace("\\", "/"); foreach (XmlElement phraseNode in resourceNode.SelectNodes("phrases/phrase")) { string phraseID = phraseNode.GetAttribute("id"); XmlElement targetPhrase = phrasesElement.SelectSingleElement(string.Format("phrase[@id='{0}']", phraseID)); if (targetPhrase == null) { targetPhrase = phrasesElement.AppendElement(resultDoc.CreateElement("phrase")); foreach (XmlAttribute attrNode in phraseNode.Attributes) { targetPhrase.SetAttribute(attrNode.Name, attrNode.Value); } } if (targetPhrase.SelectSingleNode(string.Format("resource[text()='{0}']", resourceName)) == null) targetPhrase.AppendElement(resultDoc.CreateElement("resource")).InnerText = resourceName; } } } if (processor == null) { processor = XsltTransform.Create(context, XsltPath); } StringBuilder text = new StringBuilder(); StringWriter writer = new StringWriter(text); processor.Transform(resultDoc, writer, context); string resultPath = Path.Combine(outputPath, string.Format(SummaryXmlName, arguments["category"])); string reportPath = Path.Combine(outputPath, string.Format(SummaryHtmlName, arguments["category"])); if (!Directory.Exists(outputPath)) { try { Directory.CreateDirectory(outputPath); Console.WriteLine("Created report directory at {0}", outputPath); } catch (Exception ex) { Console.WriteLine("Failed to create report directory location '{0}': {1}", outputPath, ex.Message); return; } } try { File.WriteAllText(reportPath, text.ToString()); Console.WriteLine("Saved report HTML to {0}", reportPath); } catch (Exception ex) { Console.WriteLine("Failed to write the result summary to the target location '{0}': {1}", reportPath, ex.Message); return; } try { resultDoc.Save(resultPath); Console.WriteLine("Saved report XML to {0}", resultPath); } catch (Exception ex) { Console.WriteLine("Failed to save the summary xml document to the target location '{0}': {1}", resultPath, ex.Message); return; } return; }
/// <summary> /// Initializes a new instance of the <see cref="Internationalizer"/> class, using the specified /// <paramref name="context"/>. /// </summary> /// <param name="context">The context under which the code is being executed.</param> public Internationalizer(SageContext context) { processor = XsltTransform.Create(context, XsltPath); this.context = new SageContext(context); }
public override string Apply(string content, SageContext context) { if (transform == null) transform = XsltTransform.Create(context, path); var result = new StringWriter(); var document = new CacheableXmlDocument(); document.LoadXml(content); document.DocumentElement.AppendChild(context.ToXml(document)); transform.Transform(document, result, context); return result.ToString(); }
/// <summary> /// Transforms the specified document. /// </summary> /// <param name="subject">The xml node to transform.</param> /// <param name="textWriter">The text writer to transform to.</param> /// <param name="stylesheet">The style sheet to use.</param> /// <param name="context">The context under which the code is executing.</param> public virtual void Transform(XmlNode subject, TextWriter textWriter, XsltTransform stylesheet, SageContext context) { Contract.Requires<ArgumentNullException>(subject != null); Contract.Requires<ArgumentNullException>(textWriter != null); Contract.Requires<ArgumentNullException>(stylesheet != null); Contract.Requires<ArgumentNullException>(context != null); stylesheet.Transform(subject, textWriter, context); }
/// <summary> /// Transforms the specified view context. /// </summary> /// <param name="viewContext">The view context.</param> /// <param name="textWriter">The text writer.</param> /// <param name="stylesheet">The template.</param> public virtual void Transform(ViewContext viewContext, TextWriter textWriter, XsltTransform stylesheet) { Contract.Requires<ArgumentNullException>(viewContext != null); Contract.Requires<ArgumentException>(viewContext.Controller is SageController); Contract.Requires<ArgumentNullException>(textWriter != null); Contract.Requires<ArgumentNullException>(stylesheet != null); SageController controller = (SageController) viewContext.Controller; XmlDocument requestXml; try { requestXml = controller.PrepareViewXml(viewContext); } catch (Exception ex) { if (ex is SageHelpException) throw; throw new SageHelpException(new ProblemInfo(ProblemType.ViewProcessingError), ex); } this.Transform(requestXml, textWriter, stylesheet, controller.Context); }