/// <summary>
        /// Loads the XSLT file using specified path, settings and stylesheet resolver.
        /// </summary>
        /// <param name="path">The URL to the XSLT file.</param>
        /// <param name="settings">XSLT settings.</param>
        /// <param name="stylesheetResolver">The stylesheet resolver.</param>
        /// <returns><see cref="XslCompiledTransform" /> object that can transform the input.</returns>
        public virtual XslCompiledTransform LoadXslt(string path, XsltSettings settings, XmlResolver stylesheetResolver)
        {
            var xslt = new XslCompiledTransform();
            xslt.Load(path, settings, stylesheetResolver);

            return xslt;
        }
Exemple #2
0
        public void CreateCodeBaseXML()
        {
            try
            {
                package = Package.Open(fileCodeBase);

                XmlDocument sharedString = GetPartFile(OfficeFilePart.ShareString, 0);
                sharedString.Save(Common.SHARED_STRING);
                XmlDocument sheet = GetPartFile(OfficeFilePart.Sheet, 1);

                XsltArgumentList xsltArgListSheet = new XsltArgumentList();
                XsltSettings settings = new XsltSettings(true, true);
                XslCompiledTransform xslTransSheet = new XslCompiledTransform();
                xslTransSheet.Load(Common.XSLT_CODE_BASE, settings, new XmlUrlResolver());
                xsltArgListSheet.AddParam("prmDocSharedStrings", "", sharedString.CreateNavigator());
                string sOutXmlSheet = System.String.Empty;
                using (FileStream fs = new FileStream(Common.XML_CODE_BASE, FileMode.Create))
                {
                    xslTransSheet.Transform(sheet.CreateNavigator(), xsltArgListSheet, fs);
                }

                XslCompiledTransform xslRowSheet = new XslCompiledTransform();
                xslRowSheet.Load(Common.XSLT_TO_ROW);
                xslRowSheet.Transform(Common.XML_CODE_BASE, Common.XML_ROW);

            }
            finally
            {
                package.Close();
            }
        }
 public static CompilerErrorCollection CompileToType(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver, bool debug, TypeBuilder typeBuilder, string scriptAssemblyPath)
 {
     QilExpression expression;
     if (stylesheet == null)
     {
         throw new ArgumentNullException("stylesheet");
     }
     if (typeBuilder == null)
     {
         throw new ArgumentNullException("typeBuilder");
     }
     if (settings == null)
     {
         settings = XsltSettings.Default;
     }
     if (settings.EnableScript && (scriptAssemblyPath == null))
     {
         throw new ArgumentNullException("scriptAssemblyPath");
     }
     if (scriptAssemblyPath != null)
     {
         scriptAssemblyPath = Path.GetFullPath(scriptAssemblyPath);
     }
     CompilerErrorCollection errors = new Compiler(settings, debug, scriptAssemblyPath).Compile(stylesheet, stylesheetResolver, out expression).Errors;
     if (!errors.HasErrors)
     {
         if (GeneratedCodeCtor == null)
         {
             GeneratedCodeCtor = typeof(GeneratedCodeAttribute).GetConstructor(new Type[] { typeof(string), typeof(string) });
         }
         typeBuilder.SetCustomAttribute(new CustomAttributeBuilder(GeneratedCodeCtor, new object[] { typeof(XslCompiledTransform).FullName, "4.0.0.0" }));
         new XmlILGenerator().Generate(expression, typeBuilder);
     }
     return errors;
 }
Exemple #4
0
        public void Transform(string inputFilePath, string outputFilePath, KeyValueConfigurationCollection settings)
        {
            var xsltTemplateReader = new XmlTextReader(inputFilePath);
            var emptyDocumentReader = XmlReader.Create(new System.IO.StringReader("<empty />"));

            var writerSettings = new XmlWriterSettings();
            //settings.ConformanceLevel = ConformanceLevel.Fragment;
            writerSettings.Indent = true;

            using (var outputWriter = XmlWriter.Create(outputFilePath, writerSettings))
            {
                var xsltSettings = new XsltSettings();

                XsltArgumentList argumentList = new XsltArgumentList();

                var extensions = new XsltExtensionMethods(settings);

                argumentList.AddExtensionObject("http://core.com/config", extensions);
                argumentList.AddExtensionObject("http://setty.net/config", extensions);

                var transformer = new XslCompiledTransform(true);
                transformer.Load(xsltTemplateReader, xsltSettings, null);
                transformer.Transform(emptyDocumentReader, argumentList, outputWriter);
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("You have not entered the correct parameters");
                return;
            }

            string xmlfile = args[0];
            string xslfile = args[1];
            string outfile = args[2];

            try
            {
                var doc = new XPathDocument(xmlfile);
                var transform = new XslCompiledTransform();
                var settings = new XsltSettings(true, true);
                transform.Load(xslfile, settings, new XmlUrlResolver());
                var writer = new XmlTextWriter(outfile, null);
                transform.Transform(doc, null, writer);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
        private string ToHtml()
        {
            if (Services.StrandsCache.Contains(this))
            {
                return Services.StrandsCache.Read(this);
            }
            else
            {
                var transform = new XslCompiledTransform(true);
                var arguments = new XsltArgumentList();
                var settings = new XsltSettings();
                var readersettings = new XmlReaderSettings();
                //string xslsrc = (!string.IsNullOrEmpty(this.DisplayType)) ? "/XMLList.xsl" : "/Strands.xsl";
                //var xslfile = (this.Name == "themes") ? HttpContext.Current.Server.MapPath(this._xslAppUrl + "/StrandList.xsl") : HttpContext.Current.Server.MapPath(this._xslAppUrl + xslsrc);
                var xslfile = HttpContext.Current.Server.MapPath(this._xslAppUrl + ((!string.IsNullOrEmpty(this.DisplayType)) ? "XMLList.xsl" : this.XslName));

                settings.EnableDocumentFunction = true;
                settings.EnableScript = true;
                readersettings.DtdProcessing = DtdProcessing.Parse;
                readersettings.ValidationType = ValidationType.None;
                transform.Load(xslfile, settings, new XmlUrlResolver());
                arguments = TransformArguments(this);
                using (XmlReader reader = XmlReader.Create(this.GetDirectoryPath(), readersettings))
                {
                    System.IO.StringWriter writer = new System.IO.StringWriter();

                    transform.Transform(reader, arguments, writer);
                    return Services.StrandsCache.Write(this, writer.ToString());
                }
            }
        }
        public void Transform()
        {
            var xsltTemplateReader = new XmlTextReader(_xsltPath);
            var emptyDocumentReader = XmlReader.Create(new System.IO.StringReader("<empty />"));

            var settings = new XmlWriterSettings();
            //settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.Indent = true;

            using (var outputWriter = XmlWriter.Create(_outputPath, settings))
            {
                var xsltSettings = new XsltSettings();

                XsltArgumentList argumentList = new XsltArgumentList();

                var extensions = new XsltExtensionMethods(_settings);

                argumentList.AddExtensionObject("http://core.com/config", extensions);
                argumentList.AddExtensionObject("http://paralect.com/config", extensions);

                var transformer = new XslCompiledTransform(true);
                transformer.Load(xsltTemplateReader, xsltSettings, null);
                transformer.Transform(emptyDocumentReader,argumentList, outputWriter);
            }
        }
 /// <summary>
 /// Creates a new SPARQL XSLT Writer
 /// </summary>
 /// <param name="stylesheetUri">Stylesheet URI</param>
 public SparqlXsltWriter(String stylesheetUri)
 {
     //Load the Transform
     this._transform = new XslCompiledTransform();
     XsltSettings settings = new XsltSettings();
     this._transform.Load(stylesheetUri, settings, null);
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="News"/> class.
 /// </summary>
 /// <param name="RssFeedTransformer">The RSS feed transformer.</param>
 /// <remarks>Documented by Dev02, 2007-11-28</remarks>
 public News(string RssFeedTransformer)
 {
     XmlDocument rssFeedTransformer = new XmlDocument();
     XsltSettings settings = new XsltSettings(false, true);     //disable scripts and enable document()
     rssFeedTransformer.LoadXml(RssFeedTransformer);
     xslTransformer.Load(rssFeedTransformer.CreateNavigator(), settings, new XmlUrlResolver());
 }
        /// <summary>
        /// Constructs a <b>Transformation</b> instance using the XSL source
        /// in the specified file.
        /// </summary>
        /// <param name="filename">The XSL filename.</param>
        public Transformation(string filename)
        {
            XsltSettings settings = new XsltSettings();
            settings.EnableScript = true;

            transformer.Load (Application.PathTo (filename), settings, null);
        }
Exemple #11
0
        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);
            }            
        }
Exemple #12
0
        /// <summary>
        /// Performs a XSL Transformation 
        /// </summary>
        /// <param name="styleSheet">Style Sheet path relative to Application Base directory</param>
        /// <param name="xslArguments">XSL Arguments</param>
        /// <param name="inputStream">Input Stream</param>
        /// <param name="outputStream">Out put Stream as Ref (output Stream is initialized if it is null</param>
        public void Transform(String styleSheet, Dictionary<String, String> xslArguments, Stream inputStream, ref Stream outputStream)
        {
            try
            {

                XsltSettings xsltSettings = new XsltSettings();
                xsltSettings.EnableScript = true;
                xsltSettings.EnableDocumentFunction = true;
                XsltArgumentList xslArgumentList = new XsltArgumentList();
                foreach (String key in xslArguments.Keys)
                {
                    xslArgumentList.AddParam(key, "", xslArguments[key]);
                }
                XslCompiledTransform transformer = new XslCompiledTransform();
                String stylesheetpath = AppDomain.CurrentDomain.BaseDirectory + styleSheet;
                transformer.Load(stylesheetpath, xsltSettings, new XmlUrlResolver());
                if (null == outputStream)
                {
                    outputStream = new MemoryStream();
                }
                StreamWriter streamWriter = new StreamWriter(outputStream);
                XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
                xmlReaderSettings.DtdProcessing = DtdProcessing.Ignore;
                XmlReader xmlReader = XmlReader.Create(inputStream, xmlReaderSettings);
                XmlTextWriter writer = new XmlTextWriter(outputStream,System.Text.Encoding.UTF8);
                writer.Formatting = Formatting.None;
                transformer.Transform(xmlReader, xslArgumentList, writer);

            }
            catch (Exception exception)
            {

                throw exception;
            }
        }
Exemple #13
0
 public void Execute()
 {
     var xmlresolver = new BSharpXmlResolver(Project);
     var xslt = new XslCompiledTransform();
     var xsltsettings = new XsltSettings(true,true);
     xslt.Load(_resolver.GetPath(TemplateUri),xsltsettings,xmlresolver);
     var classes = _resolver.GetClasses(ClassSelector);
    
     if (Batch)
     {
         
         var xml = new XElement("batch",classes.Select(_=>_.Compiled));
         var args = BuildArgs( classes, null);
         var path = _resolver.GetPath(OutputPath);
         Execute(xslt,xml,args,path);
     }
     else
     {
         foreach (var cls in classes)
         {
             var xml = cls.Compiled;
             var args = BuildArgs(classes, cls);
             var path =
                 _resolver.GetPath(OutputPath)
                     .Replace("_ns_", cls.Namespace)
                     .Replace("_name_", cls.Name)
                     .Replace("_proto_", cls.Prototype);
             Execute(xslt,xml,args,path);
         }
     }
     
 }
        protected override XmlDocument LoadXmlTestResult()
        {
            //transform MsTest result to nunit and return
            xmlTestResultDoc = new XmlDocument();
            xmlTestResultDoc.Load(reportParameters.XmlTestResult);
            namespaceURI = xmlTestResultDoc.SelectSingleNode("/*").NamespaceURI;

            var nameTable = GetNameTable();

            XslCompiledTransform xslt = new XslCompiledTransform();

            using (var xsltReader = new ResourceXmlReader(typeof(MsTestExecutionReportGenerator), "MsTestToNUnit.xslt", nameTable))
            {
                var resourceResolver = new XmlResourceResolver();
                var xsltSettings = new XsltSettings(true, false);
                xslt.Load(xsltReader, xsltSettings, resourceResolver);
            }

            var writerStream = new MemoryStream();
            using (var xmlTextWriter = new XmlTextWriter(writerStream, Encoding.UTF8))
            {
                xslt.Transform(xmlTestResultDoc, xmlTextWriter);
            }
            writerStream = new MemoryStream(writerStream.GetBuffer());
            XmlDocument result = new XmlDocument();
            result.Load(writerStream);
            return result;
        }
Exemple #15
0
        public static string XslTransInMemory(string xmlData, string xslData, XsltArgumentList argslist)
        {
            try
            {
                var xmlDoc = new XmlDocument();

                xmlDoc.LoadXml(xmlData);

                byte[] bytes     = System.Text.Encoding.UTF8.GetBytes(xslData);
                var    xslStream = new System.IO.MemoryStream(bytes)
                {
                    Position = 0
                };

                XmlReader xslStylesheet = default(System.Xml.XmlReader);
                xslStylesheet = new System.Xml.XmlTextReader(xslStream);

                var xslt = new System.Xml.Xsl.XslCompiledTransform();

                var settings = new System.Xml.Xsl.XsltSettings {
                    EnableDocumentFunction = true
                };

                xslt.Load(xslStylesheet, settings, null);

                var myWriter = new System.IO.StringWriter();
                xslt.Transform(xmlDoc, argslist, myWriter);

                return(myWriter.ToString());
            }
            catch (Exception ex)
            {
                return(ex.ToString() + " .............. " + xslData);
            }
        }
Exemple #16
0
		public static string Svg2Xaml(string svgFileName)
		{
			try
			{
				if (File.Exists(svgFileName) == false || File.Exists(Svg2XamlXslFile) == false)
					return null;

				var xslt = new XslCompiledTransform();
				var settings = new XsltSettings(true, true);
				xslt.Load(Svg2XamlXslFile, settings, new XmlUrlResolver());

				var xamlOfSvg = new StringBuilder();
				var xmlReaderSettings = new XmlReaderSettings();
				xmlReaderSettings.ConformanceLevel = ConformanceLevel.Document;
				xmlReaderSettings.DtdProcessing = DtdProcessing.Ignore;
				using (var xmlReader = XmlReader.Create(svgFileName, xmlReaderSettings))
				using (var xmlWriter = XmlWriter.Create(xamlOfSvg))
				{
					xslt.Transform(xmlReader, xmlWriter);
					return xamlOfSvg.ToString();
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ImageConverters.Svg2Xaml");
				return null;
			}
		}
        public string GetHtml(string transform_path, string xml)
        {
            string xsltPath = Server.MapPath(transform_path) + "\\sdctemplate.xslt";
            string csspath  = Server.MapPath(transform_path) + "\\sdctemplate.css";

            //3/10/2016 - change encoding to unicode
            System.IO.MemoryStream              stream    = new System.IO.MemoryStream(System.Text.UnicodeEncoding.ASCII.GetBytes(xml));
            System.Xml.XPath.XPathDocument      document  = new System.Xml.XPath.XPathDocument(stream);
            System.IO.StringWriter              writer    = new System.IO.StringWriter();
            System.Xml.Xsl.XslCompiledTransform transform = new System.Xml.Xsl.XslCompiledTransform();

            System.Xml.Xsl.XsltSettings settings = new System.Xml.Xsl.XsltSettings(true, true);

            System.Xml.XmlSecureResolver resolver = new System.Xml.XmlSecureResolver(new System.Xml.XmlUrlResolver(), csspath);
            try
            {
                transform.Load(xsltPath, settings, resolver);
                transform.Transform(document, null, writer);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(writer.ToString());
        }
Exemple #18
0
        public void GenerateRss()
        {
            var xsl = new XslCompiledTransform();
            var settings = new XsltSettings { EnableScript = true };
            xsl.Load("../../bookrss.xslt", settings, null);

            xsl.Transform("../../books.xml", "../../resultrss.xml");
        }
Exemple #19
0
        public void XMLToHtml()
        {
            var xsl = new XslCompiledTransform();
            var settings = new XsltSettings { EnableScript = true };
            xsl.Load("../../bookhtml.xslt", settings, null);

            xsl.Transform("../../books.xml", "../../result.html");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="XslCompiler">XslCompiler</see> class.
 /// </summary>
 public XslCompiler(string path, string assemblyFilename)
 {
     Path = path;
     Filename = assemblyFilename;
     TargetProcessor = ImageFileMachine.I386;
     XsltSettings = new XsltSettings();
     XmlResolver = new XmlUrlResolver();
     XmlResolver.Credentials = CredentialCache.DefaultCredentials;
 }
Exemple #21
0
        public IIR Execute(IIR predecessorIR)
        {
            var xmlIR = predecessorIR as XmlIR;
            if (xmlIR == null)
            {
                MessageEngine.Trace(Severity.Error, Resources.ErrorPhaseWorkflowIncorrectInputIRType, predecessorIR.GetType().ToString(), Name);
            }

            var xsltFileList = new List<string>();
            string xsltFolderPath = PathManager.GetToolSubpath(Settings.Default.SubPathXsltTransformFolder);
            foreach (string xsltFile in _xsltFiles.Split(';'))
            {
                if (!String.IsNullOrEmpty(xsltFile))
                {
                    xsltFileList.Add(Path.Combine(xsltFolderPath, xsltFile));
                }
            }

            var settings = new XsltSettings(true, false);
            var output = new XmlIR();

            // REVIEW: The approach I take here is to pipeline XSLT transforms using a MemoryStream.  This isn't great.
            //         In the next .NET Fx, they are expecting to fix XslCompiledTransform so it can pipeline more resonably.  This should be changed at that time.
            foreach (BimlFile bimlFile in xmlIR.BimlFiles)
            {
                XDocument document = bimlFile.XDocument;
                var intermediateXmlDocument = new XmlDocument();
                intermediateXmlDocument.Load(document.CreateReader());
                    if (!String.IsNullOrEmpty(xmlIR.TemplatePath))
                    {
                        foreach (string s in xsltFileList)
                        {
                            var xslt = new XslCompiledTransform();
                            var args = new XsltArgumentList();

                            args.AddParam("TemplatePath", String.Empty, xmlIR.TemplatePath);

                            xslt.Load(s, settings, new XmlUrlResolver());

                            var intermediateMemoryStream = new MemoryStream();
                            xslt.Transform(intermediateXmlDocument, args, intermediateMemoryStream);

                            intermediateMemoryStream.Position = 0;

                            intermediateXmlDocument = new XmlDocument();
                            intermediateXmlDocument.Load(intermediateMemoryStream);
                        }
                    }

                output.AddXml(bimlFile.FilePath, intermediateXmlDocument, bimlFile.EmitType, true);
            }

            output.SchemaSet = xmlIR.SchemaSet;
            output.DefaultXmlNamespace = xmlIR.DefaultXmlNamespace;
            return output;
        }
 /// <summary>
 /// This should be a part of the I/O layer
 /// </summary>
 public static void LoadFromPath(this XslCompiledTransform xslCompiledTransform, string path, XsltSettings settings, XmlResolver stylesheetResolver)
 {
     using (C1StreamReader streamReader = new C1StreamReader(path))
     {
         using (XmlReader xmlReader = XmlReader.Create(streamReader))
         {
             xslCompiledTransform.Load(xmlReader, settings, stylesheetResolver);
         }
     }
 }
Exemple #23
0
        private static void ApplyTransform(string sourceFile, string targetFile)
        {
            var transform = new System.Xml.Xsl.XslCompiledTransform();
            var settings = new XsltSettings(enableDocumentFunction: false, enableScript: true);

            transform.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "doc.xslt"), settings, new XmlUrlResolver());
            transform.Transform(sourceFile, targetFile);

            Console.WriteLine(String.Format("***{0}->{1}", sourceFile, targetFile));
        }
Exemple #24
0
		/// <summary>
		/// Loads the transformation from the specified stream
		/// </summary>
		/// <param name="store">The store to be used when resolving includes in the xslt stylesheet</param>
		/// <param name="stream">The stream to load the transformation from.</param>
		/// <param name="arguments">The arguments to arguments to use in the transformation.</param>
		/// <returns></returns>
		public IXsltTransform LoadTransform(IXsltTemplateResolver resolver, System.IO.Stream stream, XsltTransformationArguments arguments)
		{
			XslCompiledTransform transformer = new XslCompiledTransform();
			using (XmlReader reader = new XmlTextReader(stream))
			{
				XsltSettings settings = new XsltSettings(false,false);
				transformer.Load(reader, settings,
					new HelperTransformationResolver(resolver,
						XsltTransform.BuildTransformationHelper(arguments)));
			}
			return new XsltTransform(transformer, this);
		}
 public TripleSlashCommentTransformer()
 {
     var assembly = this.GetType().Assembly;
     var xsltFilePath = $"{assembly.GetName().Name}.Transform.TripleSlashCommentTransform.xsl";
     using (var stream = assembly.GetManifestResourceStream(xsltFilePath))
     using (var reader = XmlReader.Create(stream))
     {
         var xsltSettings = new XsltSettings(true, true);
         _transform = new XslCompiledTransform();
         _transform.Load(reader, xsltSettings, new XmlUrlResolver());
     }
 }
Exemple #26
0
        public static bool SendEmail(SPWeb web, string emailTo, string xslt, IDictionary xslValues)
        {
            XmlDocument xmlDoc;
            XPathNavigator xpathNavigator;
            XslCompiledTransform xslEmailTransform = new XslCompiledTransform();
            XsltArgumentList xslArguments;
            StringBuilder sbEmail;
            XmlTextWriter xmlWriter;
            XmlNode xmlNodeTitle;
            XmlDocument xmlEmail;
            XsltSettings settings = new XsltSettings(true, true);
            XmlUrlResolver resolver = new XmlUrlResolver();
            string subject = string.Empty;

            try
            {
                xslEmailTransform.Load(new XmlTextReader(xslt, XmlNodeType.Document, null), settings, resolver);

                xmlDoc = new XmlDocument();
                xmlDoc.AppendChild(xmlDoc.CreateElement("DocumentRoot"));
                xpathNavigator = xmlDoc.CreateNavigator();

                xslArguments = new XsltArgumentList();

                if (xslValues != null)
                {
                    foreach (DictionaryEntry xslEntry in xslValues)
                    {
                        xslArguments.AddExtensionObject(xslEntry.Key.ToString(), xslEntry.Value);
                    }
                }

                sbEmail = new StringBuilder();
                xmlWriter = new XmlTextWriter(new StringWriter(sbEmail));

                xslEmailTransform.Transform(xpathNavigator, xslArguments, xmlWriter);

                xmlEmail = new XmlDocument();
                xmlEmail.LoadXml(sbEmail.ToString());
                xmlNodeTitle = xmlEmail.SelectSingleNode("//title");

                subject = xmlNodeTitle.InnerText;

                return SendEmail(web, emailTo, subject, sbEmail.ToString());
            }
            catch (Exception ex)
            {
                Utils.LogError(ex);
                return false;
            }
        }
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            try
            {
                XslCompiledTransform Trans = new XslCompiledTransform();
                XsltSettings Set = new XsltSettings();
                Set.EnableScript = true;
                Trans.Load("dltransform.xsl", Set, null);

                Trans.Transform("License.xml", "YourLicense.html");
                Process.Start("YourLicense.html");
            }
            catch { }
        }
        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;
                }
            }
        }
Exemple #29
0
        public VulcanEngine.IR.IIR Execute(IIR PredecessorIR)
        {
            XmlIR xmlIR = PredecessorIR as XmlIR;
            if (xmlIR == null)
            {
                _message.Trace(Severity.Error, Resources.ErrorPhaseWorkflowIncorrectInputIRType, PredecessorIR.GetType().ToString(), this.Name);
            }

            string XsltFolderPath = PathManager.GetToolSubpath(Settings.Default.SubPathXsltTransformFolder);
            string[] XsltFileNames = Directory.GetFiles(XsltFolderPath, "*.xsl");

            if (XsltFileNames.Length <= 0)
            {
                _message.Trace(Severity.Warning, Resources.WarningNoPreProcessorFound);
                return null;
            }

            XsltSettings settings = new XsltSettings(true, false);
            XmlIR output = new XmlIR();

            // REVIEW: The approach I take here is to pipeline XSLT transforms using a MemoryStream.  This isn't great.
            //         In the next .NET Fx, they are expecting to fix XslCompiledTransform so it can pipeline more resonably.  This should be changed at that time.
            foreach (XmlIRDocumentType docType in xmlIR.XDocuments.Keys)
            {
                foreach (XDocument xDocument in xmlIR.XDocuments[docType])
                {
                    XmlDocument intermediateXMLDocument = new XmlDocument();
                    intermediateXMLDocument.Load(xDocument.CreateReader());
                    foreach (string s in XsltFileNames)
                    {
                        XslCompiledTransform xslt = new XslCompiledTransform();
                        XsltArgumentList args = new XsltArgumentList();
                        args.AddParam("XSLTFolderPath", String.Empty, XsltFolderPath);

                        xslt.Load(s, settings, new XmlUrlResolver());

                        MemoryStream intermediateMemoryStream = new MemoryStream();
                        xslt.Transform(intermediateXMLDocument, args, intermediateMemoryStream);

                        intermediateMemoryStream.Position = 0;

                        intermediateXMLDocument = new XmlDocument();
                        intermediateXMLDocument.Load(intermediateMemoryStream);
                    }
                    output.AddXml(intermediateXMLDocument,docType);
                }
            }
            return output;   
        }
Exemple #30
0
        public static void Xaml2Svg(string xaml, string svgFileName)
        {
            if (CheckXaml2SvgFiles() == false)
                return;

            var xslt = new XslCompiledTransform();
            var settings = new XsltSettings(true, true);
            xslt.Load(Xaml2SvgXslFile, settings, new XmlUrlResolver());

            using (var xmlReader = XmlReader.Create(new StringReader(xaml)))
            using (var xmlWriter = XmlWriter.Create(svgFileName))
            {
                xslt.Transform(xmlReader, xmlWriter);
            }
        }
        public FirebirdDataAccess(TCommonFireBirdDB manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            this.manager = manager;
            this.connection = manager.Connection;

            XsltSettings settings = new XsltSettings();

            this.xslt = new XslCompiledTransform();
            this.xslt.Load("fb2_text_annotation.xsl", settings, new XmlResourceResolver());
            format = new SevenZipFormat("other/7z.dll");
        }
Exemple #32
0
 public void Load(IXPathNavigable stylesheet, XsltSettings settings, XmlResolver resolver)
 {
     Load(stylesheet.CreateNavigator(), settings, resolver);
 }
Exemple #33
0
 private void Load(XPathNavigator stylesheet,
                   XsltSettings settings, XmlResolver resolver)
 {
     s = new Compiler(debugger).Compile(stylesheet, resolver, null);
 }
Exemple #34
0
 private void CompileXsltToQil(object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
 {
     this.compilerResults = new Compiler(settings, this.enableDebug, null).Compile(stylesheet, stylesheetResolver, out this.qil);
 }
Exemple #35
0
 private void TestGenerate(XsltSettings settings)
 {
     this.CompileQilToMsil(settings);
 }
Exemple #36
0
 private void CompileQilToMsil(XsltSettings settings)
 {
     this.command        = new XmlILGenerator().Generate(this.qil, null);
     this.outputSettings = this.command.StaticData.DefaultWriterSettings;
     this.qil            = null;
 }
Exemple #37
0
 // SxS: This method does not take any resource name and does not expose any resources to the caller.
 // It's OK to suppress the SxS warning.
 public void Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
 {
     Reset();
     LoadInternal(stylesheet, settings, stylesheetResolver);
 }
Exemple #38
0
 // SxS: This method does not take any resource name and does not expose any resources to the caller.
 // It's OK to suppress the SxS warning.
 public void Load(IXPathNavigable stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
 {
     Reset();
     LoadInternal(stylesheet, settings, stylesheetResolver);
 }
        //------------------------------------------------
        // Test suites entry points
        //------------------------------------------------

        private QilExpression TestCompile(object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
        {
            Reset();
            CompileXsltToQil(stylesheet, settings, stylesheetResolver);
            return(_qil);
        }
 private void TestGenerate(XsltSettings settings)
 {
     Debug.Assert(_qil != null, "You must compile to Qil first");
     CompileQilToMsil(settings);
 }
 private void CompileXsltToQil(object stylesheet, XsltSettings settings, XmlResolver?stylesheetResolver, XmlResolver?originalStylesheetResolver)
 {
     _compilerErrorColl = new Compiler(settings, _enableDebug, null).Compile(stylesheet, stylesheetResolver, originalStylesheetResolver, out _qil);
 }
 private void CompileQilToMsil(XsltSettings settings)
 {
     _command       = new XmlILGenerator().Generate(_qil !, null) !;
     OutputSettings = _command.StaticData.DefaultWriterSettings;
     _qil           = null;
 }
Exemple #43
0
    // Code for input validation
    static int Idoit(string csv, string xsltstr, string outputcsvfile, bool outputheader, string xsdstr, out string firstErrors)
    {
        XDocument doc = ConvertCsvToXML(csv, new[] { "," });

        Upx upx;

        upx.startrectype63  = 0;
        upx.startrectype64  = 0;
        upx.outputrectype60 = false;

        firstErrors = "";
        if (outputheader == true && xsdstr.Length > 0)
        {
            int          errorcount = 0;
            string       errstr     = "";
            XmlSchemaSet schemas    = new XmlSchemaSet();
            schemas.Add("", System.Xml.XmlReader.Create(new StringReader(xsdstr)));

            doc.Validate(schemas, (o, e) =>
            {
                // Console.WriteLine("{0}", e.Message);
                if (e.Message.IndexOf("attribute is not declared") == -1)
                {
                    if (errorcount < 20)
                    {
                        errstr += e.Message + "\n";
                    }
                    errorcount++;
                }
            });

            if (errorcount > 0)
            {
                firstErrors = errstr;
                Console.WriteLine(errstr);
                return(errorcount);
            }
        }

        XDocument newDoc = new XDocument();

        using (System.Xml.XmlWriter writer = newDoc.CreateWriter())
        {
            System.Xml.Xsl.XslCompiledTransform xslt     = new System.Xml.Xsl.XslCompiledTransform();
            System.Xml.Xsl.XsltSettings         settings = new System.Xml.Xsl.XsltSettings()
            {
                EnableDocumentFunction = true
            };
            xslt.Load(System.Xml.XmlReader.Create(new StringReader(xsltstr)), settings, new System.Xml.XmlUrlResolver());
            xslt.Transform(doc.CreateReader(), writer);
            //System.Xml.Xsl.XslCompiledTransform xslt = new System.Xml.Xsl.XslCompiledTransform();
            //xslt.Load(System.Xml.XmlReader.Create(new StringReader(xsltstr)));
            //xslt.Transform(doc.CreateReader(), writer);
        }

        string ext = Path.GetExtension(outputcsvfile);

        if (ext == ".csv")
        {
            converttocsv(newDoc, outputcsvfile, "rec", RowDelimit.NewLine, ColumnDelimit.Comma, outputheader);
        }
        if (ext == ".upx")
        {
            Console.WriteLine("=======GENERATING UPX=========");
            converttoupx(newDoc, outputcsvfile, "rec", RowDelimit.NewLine, ColumnDelimit.Comma, outputheader, ref upx);
        }

        return(0);
    }
Exemple #44
0
 public void Load(string stylesheet, XsltSettings settings, XmlResolver resolver)
 {
     Load(new XPathDocument(stylesheet, XmlSpace.Preserve).CreateNavigator(), settings, resolver);
 }
Exemple #45
-1
        public static CompilerErrorCollection CompileToType(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver, TypeBuilder typeBuilder) {
            if (stylesheet == null)
                throw new ArgumentNullException(nameof(stylesheet));

            if (typeBuilder == null)
                throw new ArgumentNullException(nameof(typeBuilder));

            if (settings == null)
                settings = XsltSettings.Default;

            CompilerErrorCollection errors;
            QilExpression qil;

            // Get DebuggableAttribute of the assembly. If there are many of them, JIT seems to pick up a random one.
            // I could not discover any pattern here, so let's take the first attribute found.
            object[] debuggableAttrs = typeBuilder.Assembly.GetCustomAttributes(typeof(DebuggableAttribute), false);
            bool debug = debuggableAttrs.Length > 0 && ((DebuggableAttribute) debuggableAttrs[0]).IsJITTrackingEnabled;

            errors = new Compiler(settings, debug).Compile(stylesheet, stylesheetResolver, out qil).Errors;

            if (!errors.HasErrors) {
                new XmlILGenerator().Generate(qil, typeBuilder);
            }

            return errors;
        }