Exemplo n.º 1
0
        public SaxonDotNetTransform(string sTransformName, string sTargetLanguageCode)
            : base(sTargetLanguageCode)
        {
            // Create a Processor instance.
            m_processor = new Processor();
            m_compiler = m_processor.NewXsltCompiler();

            // Load transform from file
            var uri = new Uri(sTransformName);
            var errorList = new List<StaticError>();
            m_compiler.ErrorList = errorList;
            var t = m_compiler.Compile(uri);
            m_transformer = t.Load();
        }
Exemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
                return;

            if (disposing)
            {
                // free other managed objects that implement
                // IDisposable only
            }

            // release any unmanaged objects set the object references to null
            _processor = null;
            _compiler = null;
            _transformer = null;

            _disposed = true;
        }
        private static SVGImage.SVG.SVGImage _convert(XmlReader xml)
        {
            var processor = new Processor();

            // Load the source document
            XdmNode input = processor.NewDocumentBuilder().Build(xml);

            // Create a transformer for the stylesheet
            if (transformer == null)
            {
                var file = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "libs\\pMML2SVG\\pmml2svg.xsl");
                var xslt = XmlReader.Create(file);
                transformer = processor.NewXsltCompiler().Compile(xslt).Load();
            }

            // Set the root node of the source document to be the initial context node
            transformer.InitialContextNode = input;

            var ms = new MemoryStream();

            // Create a serializer
            var serializer = new Serializer();
            serializer.SetOutputStream(ms);

            // Transform the source XML
            transformer.Run(serializer);

            serializer.Close();

            ms.Position = 0;

            var img = new SVGImage.SVG.SVGImage();
            img.SetImage(ms);
            
            return img;
        }
Exemplo n.º 4
0
        private void SetParameterCollection(XsltTransformer transformer)
        {
            //AddExtensionObjects(args); //adds the Tridion XSLT Helper as well as any other objects from a derived class

            transformer.SetParameter(new QName("", "", "TEMPLATE_URI"), new XdmAtomicValue(m_Engine.PublishingContext.ResolvedItem.Template.Id.ToString()));

            //AddPositioningVariables(args);

            if (m_GetFromPackage) // Loop through all of the entries in the package, and add them argument list as parameters
            {
                var keyBuilder = new StringBuilder();
                var packageEntries = m_Package.GetEntries();
                var addedKeys = new List<string>(packageEntries.Count);

                foreach (KeyValuePair<String, Tridion.ContentManager.Templating.Item> pair in packageEntries)
                {
                    if (String.IsNullOrEmpty(m_ParPrefix) || (!String.IsNullOrEmpty(m_ParPrefix) && pair.Key.ToLower().StartsWith(m_ParPrefix)))
                    {
                        keyBuilder.Append(String.IsNullOrEmpty(m_ParPrefix) ? pair.Key : pair.Key.Substring(m_ParPrefix.Length)); //if used a prefix strip the prefix before entering the argument

                        var key = keyBuilder.ToString();

                        if (!addedKeys.Contains(key)) //package may contain duplicate keys
                        {
                            switch (pair.Value.ContentType.Value)
                            {
                                case "text/plain": //Plain text items are added as strings
                                    transformer.SetParameter(new QName("", "", key), new XdmAtomicValue(pair.Value.GetAsString()));
                                    break;
                                case "text/html": //HTML items are added as strings
                                    //args.AddParam(key, "", pair.Value.GetAsString());
                                    transformer.SetParameter(new QName("", "", key), new XdmAtomicValue(pair.Value.GetAsString()));
                                    m_Logger.Debug(String.Format("Added parameter '{0}' as String", key));
                                    break;
                                default: //Other items are added as XmlDocuments
                                    //args.AddParam(key, "", pair.Value.GetAsXmlDocument().ToString());
                                    transformer.SetParameter(new QName("", "", key), new XdmAtomicValue(pair.Value.GetAsXmlDocument().ToString()));
                                    m_Logger.Debug(String.Format("Added parameter '{0}' as XmlDocument", key));
                                    break;
                            }

                            addedKeys.Add(key);
                        }
                        else
                            Console.WriteLine(String.Format("argument collection already contains key: '{0}'", key));
                            Logger.Debug(String.Format("argument collection already contains key: '{0}'", key));

                        keyBuilder.Remove(0, keyBuilder.Length); //clear the stringbuilder before the next iteration
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void Load(XmlReader xmlReader)
 {
     _transformer = _compiler.Compile(xmlReader).Load();
 }
Exemplo n.º 6
0
 public void Load(string xslPath)
 {
     TextReader input = new StreamReader(xslPath);
     _transformer = _compiler.Compile(input).Load();
     input.Close();
 }
        /// <summary>
        /// Load the XSLT file
        /// </summary>
        public void Load(string filename, bool profilingEnabled = false)
        {
            //register our eval() function
            processor = new Processor();
            processor.RegisterExtensionFunction(new SaxonEvaluate(processor.NewXPathCompiler()));

            //tracing
            if (profilingEnabled)
            {
                var profile = new TimingTraceListener();
                processor.Implementation.setTraceListener(profile);
                processor.Implementation.setLineNumbering(true);
                processor.Implementation.setCompileWithTracing(true);
                processor.Implementation.getDefaultXsltCompilerInfo().setCodeInjector(new TimingCodeInjector());
                profile.setOutputDestination(new java.io.PrintStream("profile.html"));
            }

            //capture the error information
            var compiler = processor.NewXsltCompiler();
            compiler.ErrorList = errorList;

            //compile the stylesheet
            var relativeFilename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);
            try
            {
                var exec = compiler.Compile(XmlTextReader.Create(relativeFilename));

                //capture xsl:message output
                transform = exec.Load();
                transform.MessageListener = new SaxonMessageListener();
            }
            catch (Exception)
            {
                foreach (StaticError err in compiler.ErrorList)
                {
                    log.ErrorFormat("{0} ({1}, line {2})", err, err.ModuleUri, err.LineNumber);
                }
                throw;
            }
        }