public void ShouldTransformData()
		{
			string input = TestData.LogFileContents;
			string xslfile = TempFileUtil.CreateTempXmlFile(TestFolder, "samplestylesheet.xsl", TestData.StyleSheetContents);

			string output = new XslTransformer().Transform(input, xslfile, null);
			Assert.IsNotNull(output);
			Assert.IsTrue(! String.Empty.Equals(output), "Transform returned no data");
		}
		public void ShouldPassThroughXSLTArgs()
		{
			string input = TestData.LogFileContents;
			string xslfile = TempFileUtil.CreateTempXmlFile(TestFolder, "samplestylesheet.xsl", TestData.StyleSheetContentsWithParam);

			Hashtable xsltArgs = new Hashtable();
			xsltArgs["myParam"] = "myValue";
			string output = new XslTransformer().Transform(input, xslfile, xsltArgs);
			Assert.IsTrue(output.IndexOf("myValue") > 0);
		}
        /// <summary>
        /// Transforms the results.	
        /// </summary>
        /// <param name="xslFiles">The XSL files.</param>
        /// <param name="document">The document.</param>
        /// <returns></returns>
        /// <remarks></remarks>
		public string TransformResults(IList xslFiles, XPathDocument document)
		{
			StringBuilder builder = new StringBuilder();
			if (xslFiles == null)
				return builder.ToString();

			XslTransformer transformer = new XslTransformer();
			foreach (string xslFile in xslFiles)
			{
                Log.Trace("Transforming using file : {0}",xslFile);
				builder.Append(transformer.TransformToXml(xslFile, document));
			}
			return builder.ToString();
		}
Exemplo n.º 4
0
        public void Run(IIntegrationResult result)
        {
            foreach (FilePair Pair in this.FilePairs)
            {
                string XmlFilePath = Pair.XmlFile;
                if (!Path.IsPathRooted(XmlFilePath))
                {
                    XmlFilePath = Path.Combine(result.WorkingDirectory, XmlFilePath);
                }

                string XslFilePath = Pair.XslFile;
                if (!Path.IsPathRooted(XslFilePath))
                {
                    XslFilePath = Path.Combine(result.WorkingDirectory, XslFilePath);
                }

                string XslFileName = Path.GetFileName(XslFilePath);
                if (!File.Exists(XslFilePath))
                {
                    Log.Warning("File not Found: " + XslFileName);
                }

                WildCardPath Pattern = new WildCardPath(XmlFilePath);
                FileInfo[] Files = Pattern.GetFiles();
                foreach (FileInfo XmlFileInfo in Files)
                {
                    Log.Info(String.Format("Merging file {0} through {1}", XmlFileInfo, XslFileName));
                    if (XmlFileInfo.Exists)
                    {
                        string Data;
                        String Contents;
                        using (TextReader Reader = XmlFileInfo.OpenText())
                        {
                            Contents = Reader.ReadToEnd();
                        }
                        XslTransformer Transformer = new XslTransformer();
                        Data = Transformer.Transform(Contents, XslFilePath, new Dictionary<string, string>());
                        result.AddTaskResult((new XslMergerTaskResult(Data)));
                    }
                    else
                    {
                        Log.Warning("File not Found: " + XmlFileInfo);
                    }
                }
            }
        }