public void SimpleTransformTest() { var xslt = Path.Combine(Helper.GetDataPath(), "Sample.xslt"); var output = Path.Combine(Helper.GetDataPath(), "Sample.xml"); if (File.Exists(output)) { File.Delete(output); } var transformer = new XsltTransformer(xslt, output, GetKeyValueCollection()); transformer.Transform(); XmlDocument doc = new XmlDocument(); doc.Load(output); var nameNodes = doc.SelectNodes("configuration/appSettings/add[@key = 'Name' and @value = 'Value']"); var emailNodes = doc.SelectNodes("configuration/appSettings/add[@key = 'Email' and @value = '*****@*****.**']"); var companyNodes = doc.SelectNodes("configuration/appSettings/add[@key = 'Company' and @value = 'IBM']"); Assert.AreEqual(nameNodes.Count, 1); Assert.AreEqual(emailNodes.Count, 1); Assert.AreEqual(companyNodes.Count, 1); }
protected override void Render(TextWriter outputFileName, bool withChildren) { XmlWriterSettings outputSettings = (this.UseOutputSettings) ? XsltTransformer.XslCompiledTransform.OutputSettings.Clone() : new XmlWriterSettings { Indent = true, Encoding = GetEncoding(), OmitXmlDeclaration = this.OmitXmlDeclaration }; outputSettings.ConformanceLevel = (ConformanceLevel)Enum.Parse(typeof(ConformanceLevel), this.ConformanceLevel); using (XmlWriter writer = XmlWriter.Create(outputFileName, outputSettings)) { Content content = this.ContextNode; //using (Stream response = content.GetXmlStream(withChildren, this.ChildrenSetting == "AllChildren")) content.ChildrenDefinition.AllChildren = this.ChildrenSetting == "AllChildren"; content.ChildrenDefinition.ContentQuery = this.CustomQueryFilter; using (Stream response = content.GetXml(withChildren)) { var xml = new XPathDocument(response); var xsltArguments = GetXsltArgumentList(); XsltTransformer.Transform(xml, xsltArguments, writer); } } }
static void Main(string[] args) { string xml = string.Empty; string xslt = string.Empty; string xmlSourceFile = string.Empty; string xsltTransformFile = string.Empty; string outputFile = string.Empty; StringBuilder errorLine = new StringBuilder(); StringBuilder argumentsPassedIn = new StringBuilder(); if (args.Length != 3) { errorLine.AppendLine("Faulty command line format. Not enough arguments. Check your command line format." + args.Length.ToString()); Console.WriteLine(errorLine.ToString() + "\n\nPress any key to quit program, and fix command line"); Console.ReadKey(); return; } xmlSourceFile = args.Where(c => c.Contains("/xml=")).FirstOrDefault(); xsltTransformFile = args.Where(c => c.Contains("/xsl=")).FirstOrDefault(); outputFile = args.Where(c => c.Contains("/out=")).FirstOrDefault(); argumentsPassedIn.AppendLine("\n\nHere are your arguments:"); argumentsPassedIn.AppendLine(xmlSourceFile); argumentsPassedIn.AppendLine(xsltTransformFile); argumentsPassedIn.AppendLine(outputFile); if (string.IsNullOrEmpty(xmlSourceFile) || string.IsNullOrEmpty(xsltTransformFile) || string.IsNullOrEmpty(outputFile)) { errorLine.AppendLine("Faulty command line format. Check your command line format. Make sure all file paths are surrounded by double quotes. " + "The switches required are xml=\"[your xml file name]\", xsl=\"[xslt stylesheet]\", and out=\"[your output file]\"" + argumentsPassedIn.ToString()); } xmlSourceFile = xmlSourceFile.Replace("/xml=", ""); xsltTransformFile = xsltTransformFile.Replace("/xsl=", ""); outputFile = outputFile.Replace("/out=", ""); xutil = new XmlUtility(); transformer = new XsltTransformer(); try { xml = xutil.ReadXmlFile(xmlSourceFile); xslt = transformer.ReadStyleSheet(xsltTransformFile); transformer.Transform(xml, xslt, outputFile); Console.WriteLine("Transformation succeeded"); } catch (Exception ex) { Console.WriteLine("Error in transformation: " + ex.Message + "\n\n" + errorLine.ToString() + argumentsPassedIn.ToString()); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public static void TransformXmlFile(string xmlFileFullPathAndName, string styleSheetFileFullPathAndName, string outputfileFullPathAndName) { var inputReader = new XmlUtility(); var transformer = new XsltTransformer(); string input = inputReader.ReadXmlFile(xmlFileFullPathAndName); string style = transformer.ReadStyleSheet(styleSheetFileFullPathAndName); transformer.Transform(input, style, outputfileFullPathAndName); }
private string TransformXmltoHtml(string xmlOutput) { string outputFilename = xmlOutput + ".html"; using (XmlWriter output = XmlWriter.Create(outputFilename)) { var input = new XPathDocument(xmlOutput); XsltTransformer.Transform(input, output); } return(outputFilename); }
private static bool Verify(string xsltRule, string content, string metadata, out TestResult result) { string jsonSchema = XsltTransformer.Transform(metadata, xsltRule); try { var jsonSchemaVerifier = new JsonSchemaVerifier(jsonSchema); return(jsonSchemaVerifier.Verify(content, out result)); } catch (Exception e) { if (!ExceptionHelper.IsCatchableExceptionType(e)) { throw; } throw new RuntimeException(e, jsonSchema); } }
public void XsltTransformer_TransformTest() { //prepare var templateProvider = new FileTemplate("TestTools/Content/ProductsOrder.xslt"); var templateData = new List <TemplateData> { new TemplateData(keyValueModel: null, objectModel: CreateObjectModel()) }; //invoke Stopwatch timer = Stopwatch.StartNew(); var target = new XsltTransformer(); Dictionary <string, string> filledTemplates = target.Transform(templateProvider, templateData); //assert Debug.WriteLine("Xslt time: " + timer.Elapsed); Assert.AreEqual(1, filledTemplates.Count); Assert.IsNotNull(filledTemplates.Values.First()); }
private static bool Verify(string xsltRule, string content, string metadata, out TestResult result) { string rng = XsltTransformer.Transform(metadata, xsltRule); try { var rngChecker = new RngVerifier(rng); return(rngChecker.Verify(content, out result)); } catch (Exception e) { if (!ExceptionHelper.IsCatchableExceptionType(e)) { throw; } throw new RuntimeException(e, rng); } }
public void ApplicatioSettings() { var xslt = Path.Combine(Helper.GetDataPath(), "ApplicationSettings.xslt"); var output = Path.Combine(Helper.GetDataPath(), "ApplicationSettings.xml"); if (File.Exists(output)) { File.Delete(output); } var expected = GetKeyValueCollection(); var transformer = new XsltTransformer(xslt, output, expected); transformer.Transform(); var actual = GetApplicationSettingsFromFile(output); Assert.AreEqual(expected.Count, actual.Count); }
public void ApplicatioSettings() { var xslt = Path.Combine(Helper.GetDataPath(), "ApplicationSettings.xslt"); var output = Path.Combine(Helper.GetDataPath(), "ApplicationSettings.xml"); if (File.Exists(output)) File.Delete(output); var expected = GetKeyValueCollection(); var transformer = new XsltTransformer(xslt, output, expected); transformer.Transform(); var actual = GetApplicationSettingsFromFile(output); Assert.AreEqual(expected.Count, actual.Count); }
public void SimpleTransformTest() { var xslt = Path.Combine(Helper.GetDataPath(), "Sample.xslt"); var output = Path.Combine(Helper.GetDataPath(), "Sample.xml"); if (File.Exists(output)) File.Delete(output); var transformer = new XsltTransformer(xslt, output, GetKeyValueCollection()); transformer.Transform(); XmlDocument doc = new XmlDocument(); doc.Load(output); var nameNodes = doc.SelectNodes("configuration/appSettings/add[@key = 'Name' and @value = 'Value']"); var emailNodes = doc.SelectNodes("configuration/appSettings/add[@key = 'Email' and @value = '*****@*****.**']"); var companyNodes = doc.SelectNodes("configuration/appSettings/add[@key = 'Company' and @value = 'IBM']"); Assert.AreEqual(nameNodes.Count, 1); Assert.AreEqual(emailNodes.Count, 1); Assert.AreEqual(companyNodes.Count, 1); }