AddExtensionObject() публичный Метод

public AddExtensionObject ( string namespaceUri, object extension ) : void
namespaceUri string
extension object
Результат void
Пример #1
0
        public Program()
        {
            //Set the UI to the specified culture.
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(_culturename);

            //Create the XslTransform and load the stylesheet.
            //XslTransform xslt = new XslTransform();
            XslCompiledTransform xslt = new XslCompiledTransform();
            xslt.Load(_stylesheet);

            //Load the XML data file.
            XPathDocument doc = new XPathDocument(_filename);

            //Create an XsltArgumentList.
            XsltArgumentList xslArg = new XsltArgumentList();

            //Add an object to get the resources for the specified language.
            ResourceTranslator resTran = new ResourceTranslator("Resources.Resource");
            xslArg.AddExtensionObject("urn:myResTran", resTran);

            //Add an object to calculate the circumference of the circle.
            Calculate obj = new Calculate();
            xslArg.AddExtensionObject("urn:myObj", obj);

            //Create an XmlTextWriter to output to the console.
            XmlTextWriter writer = new XmlTextWriter(Console.Out);

            //Transform the file.
            xslt.Transform(doc, xslArg, writer, null);

            writer.Close();
        }
		public void Render(object source, HtmlTextWriter htmlWriter, TemplateDefinition liveDefinition)
		{
			var resolver = new PathResolver(liveDefinition.Folder);
			var hostPage = DNNContext.Current.Page;

			var args = new XsltArgumentList();
			args.AddExtensionObject("urn:ddrmenu", new XsltFunctions());
			args.AddExtensionObject("urn:dnngarden", new XsltFunctions());
			args.AddParam("ControlID", "", DNNContext.Current.HostControl.ClientID);
			args.AddParam("Options", "", ConvertToJson(liveDefinition.ClientOptions));
			args.AddParam("DNNPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Dnn)));
			args.AddParam("ManifestPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Manifest)));
			args.AddParam("PortalPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Portal)));
			args.AddParam("SkinPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Skin)));
			liveDefinition.TemplateArguments.ForEach(a => args.AddParam(a.Name, "", a.Value));

			HttpContext.Current.Items["Resolver"] = resolver;

			using (var xmlStream = new MemoryStream())
			{
				Utilities.SerialiserFor(source.GetType()).Serialize(xmlStream, source);
				xmlStream.Seek(0, SeekOrigin.Begin);
				xsl.Transform(XmlReader.Create(xmlStream), args, htmlWriter);
			}
		}
Пример #3
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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public new void Init(object objParam)
        {
            // Get parameter info
            _strPath = Path.Combine(@"TestFiles\", FilePathUtil.GetTestDataPath(), @"XsltApi\");

            xsltArg1 = new XsltArgumentList();

            MyObject obj1 = new MyObject(1, _output);
            MyObject obj2 = new MyObject(2, _output);
            MyObject obj3 = new MyObject(3, _output);
            MyObject obj4 = new MyObject(4, _output);
            MyObject obj5 = new MyObject(5, _output);

            xsltArg1.AddExtensionObject("urn:my-obj1", obj1);
            xsltArg1.AddExtensionObject("urn:my-obj2", obj2);
            xsltArg1.AddExtensionObject("urn:my-obj3", obj3);
            xsltArg1.AddExtensionObject("urn:my-obj4", obj4);
            xsltArg1.AddExtensionObject("urn:my-obj5", obj5);

            xsltArg1.AddParam("myArg1", szEmpty, "Test1");
            xsltArg1.AddParam("myArg2", szEmpty, "Test2");
            xsltArg1.AddParam("myArg3", szEmpty, "Test3");
            xsltArg1.AddParam("myArg4", szEmpty, "Test4");
            xsltArg1.AddParam("myArg5", szEmpty, "Test5");

            return;
        }
Пример #6
0
 /// <summary>
 /// 析构函数
 /// </summary>
 public XsltTemplate(_DbHelper c)
 {
     watch.Start();
     conn = c;
     _argList = new XsltArgumentList();
     _argList.AddExtensionObject("roclog:function", new _ALFun(conn));
     _argList.AddExtensionObject("sys:fun", new _ALFun(conn));
     //扩展部分
     foreach (object type in new SiteExpand().GetTypes(typeof(ITemplateFun).FullName))
     {
         ITemplateFun iae = ((ITemplateFun)type);
         _argList.AddExtensionObject(string.Format("expand:{0}", iae.URI), iae);
     }
 }
Пример #7
0
        void LoadCategory()
        {
            if (base.XSLTemplateID > 0)
            {
                int ParentCategoryID = 0;
                if (base.ContainerValue > 0)
                {
                    ParentCategoryID = base.ContainerValue;
                }
                else
                {
                    int.TryParse(Request.QueryString[CMSConfig.QueryString.CategoryID], out ParentCategoryID);
                }
                string categoryXML = CategoryManager.GetCategoryPublishXML(base.ModuleID, ParentCategoryID);

                string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
                xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);

                XsltArgumentList arguments = new XsltArgumentList();
                arguments.AddExtensionObject("CMS:UserControl", this);

                xmlCategory.DocumentContent = categoryXML;
                xmlCategory.TransformSource = xslPath;
                xmlCategory.TransformArgumentList = arguments;
                xmlCategory.DataBind();
            }
        }
Пример #8
0
        public static IGraph CreateNuspecGraph(XDocument nuspec, string baseAddress)
        {
            nuspec = NormalizeNuspecNamespace(nuspec);

            XslCompiledTransform transform = CreateTransform("xslt.nuspec.xslt");

            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddParam("base", "", baseAddress + "packages/");
            arguments.AddParam("extension", "", ".json");

            arguments.AddExtensionObject("urn:helper", new XsltHelper());

            XDocument rdfxml = new XDocument();
            using (XmlWriter writer = rdfxml.CreateWriter())
            {
                transform.Transform(nuspec.CreateReader(), arguments, writer);
            }

            RdfXmlParser rdfXmlParser = new RdfXmlParser();
            XmlDocument doc = new XmlDocument();
            doc.Load(rdfxml.CreateReader());
            IGraph graph = new Graph();
            rdfXmlParser.Load(graph, doc);

            return graph;
        }
Пример #9
0
        public static string Transform(string xml,string xslFile)
        {
            XslTransform transform = new XslTransform();
            XsltArgumentList args = new XsltArgumentList();
            //define the xslt rendering file
            //get the iterators for the root and context item
            XPathDocument xmlDoc = new XPathDocument(new StringReader(xml));
            XPathNavigator iter = xmlDoc.CreateNavigator();

            //define and add the xslt extension classes
            //Sitecore.Xml.Xsl.XslHelper sc = new Sitecore.Xml.Xsl.XslHelper();
            XsltHelper xslt = new XsltHelper();
            args.AddExtensionObject("http://www.rlmcore.vn/helper", xslt);

            //add parameters
            args.AddParam("item", "", iter);
            args.AddParam("currentitem", "", iter.Select("."));
            //define the stream which will contain the result of xslt transformation
            //StringBuilder sb = new StringBuilder();
            //TextWriter stream = new FileStream(new MemoryStream(Encoding.ASCII.GetBytes(sb.ToString())));
            System.IO.StringWriter stream = new System.IO.StringWriter();

            //load xslt rendering to XslTransform class
            transform.Load(xslFile);
            //perform a transformation with the rendering
            transform.Transform(iter, args, stream);

            return stream.ToString();
        }
Пример #10
0
        private void RenderRelatedNews()
        {
            if (Request.QueryString[ConstantsManager.NewsGUID] == null)
                return;
            //int _newsID = 0; Int32.TryParse(Request.QueryString[ConstantsManager.NewsID], out _newsID);
            //if (_newsID == 0)
            //    return;
            string guid = Request.QueryString[ConstantsManager.NewsGUID].ToString();

            NewsItem _news = NewsItemManager.GetByGUID(guid);
            if (null == _news)
                return;


            XmlDocument xDoc = NewsItemManager.GetNewsByKeywordAsXML(_news.Keywords, _news.ID);

            if (null == xDoc)
                return;


            XslTemplate xslTemplate = XslTemplateManager.GetByID(XSLID);
            if (null == xslTemplate)
                return;
            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddExtensionObject("obj:CategoryViewer", this);
            _news.Keywords = "";
            _news.ViewCount++;
            NewsItemManager.Update(_news);
            string _html = UtilitiesManager.TransformXMLWithXSLText(xDoc.OuterXml, xslTemplate.Details, arguments);
            dvData.InnerHtml = _html;

        }
Пример #11
0
        public static void XTransformToWriter(this Linq.XElement xmlDoc, TextWriter writer,
                    Linq.XElement xmlXslt = null, // Action<XslCompiledTransform> onXsltLoad = null, 
                    object xsltExtension = null,
                    string urn = "urn:request-info")
        {
            XslCompiledTransform trans = new XslCompiledTransform();
            //if (onXsltLoad != null)
            //    onXsltLoad(trans);
            //else
                trans.Load(xmlXslt.CreateReader());

            if (xsltExtension != null)
            {
                XsltArgumentList xslArg = new XsltArgumentList();
                xslArg.AddExtensionObject(urn, xsltExtension);

                // XTransformTo(trans, xmlDoc.CreateReader(), xslArg, writer);
                // var results = writer;
                XmlReader input = xmlDoc.CreateReader();
                XmlWriterSettings outputSettings = trans.OutputSettings;
                using (XmlWriter writerXml = XmlWriter.Create(writer, outputSettings))
                {
                    trans.Transform(input, arguments: xslArg, results: writerXml,
                          documentResolver: XmlNullResolver.Singleton); // XsltConfigSection.CreateDefaultResolver());
                    writerXml.Close();
                }
            }
            else
            {
                // trans.Transform(xmlDoc.CreateNavigator() as IXPathNavigable, arguments: null, results: writer);
                XTransformTo(trans, xmlDoc.CreateReader(), null, writer);
            }
        }
        void LoadMenuItem()
        {
            int menuID = 0;
            int.TryParse(Request.QueryString[CMSConfig.QueryString.MenuID], out menuID);

            if (base.XSLTemplateID > 0 && menuID > 0)
            {
                string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
                xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);

                XsltArgumentList arguments = new XsltArgumentList();
                arguments.AddExtensionObject("CMS:UserControl", this);

                Menu menu = new Menu();
                xmlMenu.DocumentContent = MenuManager.GetMenuItemTemplateXml(menuID, CMSContext.LanguageID, out menu);
                xmlMenu.TransformSource = xslPath;
                xmlMenu.TransformArgumentList = arguments;
                xmlMenu.DataBind();

                bool SetPageTitle = false;
                bool.TryParse(this.Attributes["SetPageTitle"], out SetPageTitle);

                if (SetPageTitle && menu != null)
                {
                    this.Page.Title = menu.Name;
                }
            }
        }
Пример #13
0
        void LoadGallery()
        {
            int CategoryId = 0;
            CategoryId = base.ContainerValue;
            if (CategoryId <= 0)
                int.TryParse(Request.QueryString[CMSConfig.QueryString.CategoryID], out CategoryId);

            if (base.XSLTemplateID > 0)
            {
                int PageSize = 10;
                if (!string.IsNullOrEmpty(Attributes["PageSize"]))
                {
                    PageSize = Convert.ToInt32(Attributes["PageSize"]);
                }
                int TotalCount = 0;
                string galleryXML = GalleryManager.GetGallerysPublishXML(CategoryId, Core.Enums.CMSEnums.GalleryType.Photo, 1, PageSize, ref TotalCount);

                string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
                xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);

                XsltArgumentList arguments = new XsltArgumentList();
                arguments.AddExtensionObject("CMS:UserControl", this);

                xmlGallery.DocumentContent = galleryXML;
                xmlGallery.TransformSource = xslPath;
                xmlGallery.TransformArgumentList = arguments;
                xmlGallery.DataBind();
            }
        }
Пример #14
0
        void NewsViewer_UC_Load(object sender, EventArgs e)
        {
            if (Request.QueryString[ConstantsManager.MenuID] == null)
                return;
            
            int _menuID = 0;

            Int32.TryParse(Request.QueryString[ConstantsManager.MenuID], out _menuID);
            if (_menuID == 0)
                return;
            XmlDocument xDoc = MenuItemManager.GetByIDasXml(_menuID);
            if (null == xDoc)
                return;
            XslTemplate xslTemplate = XslTemplateManager.GetByID(XSLID);

            if (null == xslTemplate)
                return;
            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddExtensionObject("obj:CategoryViewer", this);


            string _html = UtilitiesManager.TransformXMLWithXSLText(xDoc.OuterXml, xslTemplate.Details, arguments);
            dvData.InnerHtml = _html;

        }
Пример #15
0
        private void FillSitePath()
        {
            int CatalogValue = -1;
            if (!string.IsNullOrEmpty(CMSConfig.QueryString.CatalogID))
            {
                int.TryParse(Request.QueryString[CMSConfig.QueryString.CatalogID], out CatalogValue);
            }

            string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
            xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);

            XmlDocument xmlDoc = new XmlDocument();
            XmlElement rootElement = xmlDoc.CreateElement("Root");

            xmlDoc.AppendChild(rootElement);

            if (CatalogValue > 0)
            {
                Catalog Catalog = CatalogManager.GetCatalog(CatalogValue, CMSContext.LanguageID);
                if (Catalog != null)
                {
                    FillCatalogsXML(Catalog, xmlDoc, rootElement);

                    XsltArgumentList arguments = new XsltArgumentList();
                    arguments.AddExtensionObject("CMS:UserControl", this);


                    xmlCatalog.DocumentContent = xmlDoc.OuterXml;
                    xmlCatalog.TransformSource = xslPath;
                    xmlCatalog.TransformArgumentList = arguments;
                    xmlCatalog.DataBind();
                }
            }
        }
Пример #16
0
        void LoadMenu()
        {
            int menuID = 0;
            int.TryParse(Request.QueryString[CMSConfig.QueryString.MenuID], out menuID);

            if (base.XSLTemplateID > 0 && base.ContainerValue > 0)
            {
                string menuCategoryPath = CMSWebHelper.GetMenuPathByCategory(base.ContainerValue);
                menuCategoryPath = MenuManager.GetMenuCategoryXMLPath(menuCategoryPath, base.ContainerValue, CMSContext.LanguageID);

                string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
                xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);

                XsltArgumentList arguments = new XsltArgumentList();
                arguments.AddExtensionObject("CMS:UserControl", this);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(menuCategoryPath);

                XmlAttribute xmlAtt = xmlDoc.CreateAttribute("CurrentMenu");
                xmlAtt.Value = menuID.ToString();
                if (xmlDoc.ChildNodes.Count > 1 && xmlDoc.ChildNodes[1] != null)
                {
                    xmlDoc.ChildNodes[1].Attributes.Append(xmlAtt);
                }

                xmlMenu.DocumentContent = xmlDoc.OuterXml;
                xmlMenu.TransformSource = xslPath;
                xmlMenu.TransformArgumentList = arguments;
                xmlMenu.DataBind();
            }
        }
Пример #17
0
        /// <exclude />
        public static void Register(XsltArgumentList argumentList)
        {
            foreach(string providerName in XslExtensionsProviderRegistry.XslExtensionsProviderNames)
            {
                List<Pair<string, object>> extensions;
                try
                {
                    extensions = XslExtensionsProviderPluginFacade.CreateExtensions(providerName);
                }
                catch(Exception ex)
                {
                    string message = "Failed to get xsl extensions from provider '{0}'".FormatWith(providerName);
                    LoggingService.LogError("XslExtensionsManager", new InvalidOperationException(message, ex));
                    continue;
                }

                if(extensions != null)
                {
                    foreach (Pair<string, object> pair in extensions)
                    {
                        argumentList.AddExtensionObject(pair.First, pair.Second);
                    }
                }
            }
        }
        /// <summary>
        /// Return new instance of <see cref="XsltArgumentList"/> object with added <see cref="XsltScriptHelpers"/> as extension object.
        /// </summary>
        /// <returns>New instance of <see cref="XsltArgumentList"/>.</returns>
        public static XsltArgumentList GetDefaultArguments()
        {
            XsltArgumentList xslt_args = new XsltArgumentList ();
            xslt_args.AddExtensionObject ("urn:script", new XsltScriptHelpers ());

            return xslt_args;
        }
Пример #19
0
		public string Htmlize (XmlReader ecma_xml, Dictionary<string, string> extraArgs)
		{
			var args = new XsltArgumentList ();
			args.AddExtensionObject("monodoc:///extensions", ExtObject);
			foreach (var kvp in extraArgs)
				args.AddParam (kvp.Key, string.Empty, kvp.Value);

			return Htmlize(ecma_xml, args);
		}
Пример #20
0
 public static XDocument TransformResponse( this XElement element)
 {
     var input = new XDocument();
       input.Add( element );
       var args = new XsltArgumentList();
       args.AddExtensionObject("urn:extensions",new XsltExtensions());
       var result = input.Transform( args, XDocument.Parse( TransformationResources.CraigslistResponse ) );
       return result;
 }
Пример #21
0
        private void RenderData()
        {
            XmlDocument xDoc = SawtyyatManager.GetAllByTypeAsXml(DataLayer.Enums.RootEnums.AudioVideoType.Video, CategoryID);

            XslTemplate xslTemplate = XslTemplateManager.GetByID(XSLID);
            if (null == xslTemplate)
                return;
            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddExtensionObject("obj:CategoryViewer", this);

            string _html = UtilitiesManager.TransformXMLWithXSLText(xDoc.OuterXml, xslTemplate.Details, arguments);
            dvdata.InnerHtml = _html;
        }
Пример #22
0
        private void RenderData()
        {
            XmlDocument xDoc = GalleryManager.GetByCategoryAsXML(CategoryID);

            XslTemplate xslTemplate = XslTemplateManager.GetByID(XSLID);
            if (null == xslTemplate)
                return;
            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddExtensionObject("obj:CategoryViewer", this);

            string _html = UtilitiesManager.TransformXMLWithXSLText(xDoc.OuterXml, xslTemplate.Details, arguments);
            dvdata.InnerHtml = _html;
        }
Пример #23
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;
            }
        }
Пример #24
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            this.viewContext = viewContext;

            string url = viewContext.HttpContext.Request.Url.ToString();
            construct.AppendPage("", url, viewData.PageVars);

            var args = new XsltArgumentList();
            args.AddExtensionObject("urn:HtmlHelper", new HtmlHelper(viewContext, this));

            args.AddParam("AjaxProScriptReferences", "", ajaxDeclaration);

            xslTransformer.Transform(new XmlInput(construct.Message.CreateNavigator()), args, new XmlOutput(writer));
        }
Пример #25
0
		public string Htmlize (XmlReader ecma_xml, Dictionary<string, string> extraArgs)
		{
			var args = new XsltArgumentList ();
			args.AddExtensionObject("monodoc:///extensions", ExtObject);
			string specialPage;
			if (extraArgs.TryGetValue ("specialpage", out specialPage) && specialPage == "root") {
				extraArgs.Remove ("specialpage");
				extraArgs["show"] = "masteroverview";
			}

			foreach (var kvp in extraArgs)
				args.AddParam (kvp.Key, string.Empty, kvp.Value);

			return Htmlize (ecma_xml, args);
		}
Пример #26
0
        /// <summary>
        /// Transforms the specified XML.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <param name="xsl">The XSL.</param>
        /// <returns></returns>
        public static string Transform(string xml, string xsl)
        {
            var transformer = new XslCompiledTransform();
            var xmlReader = XmlReader.Create(new System.IO.StringReader(xml));
            var xslReader = XmlReader.Create(new System.IO.StringReader(xsl));
            var helpers = new XsltArgumentList();

            var args = new XslHelpers();
            helpers.AddExtensionObject("urn:xsl-helpers", args);

            using (var writer = new System.IO.StringWriter())
            {
                transformer.Load(xslReader);
                transformer.Transform(xmlReader, helpers, writer);
                return writer.ToString();
            }
        }
Пример #27
0
        void LoadCatalog()
        {
            int CatalogValue = -1;
            if (base.ContainerValue > 0)
            {
                CatalogValue = base.ContainerValue;
            }
            else
            {
                if (!string.IsNullOrEmpty(CMSConfig.QueryString.CatalogID))
                {
                    int.TryParse(Request.QueryString[CMSConfig.QueryString.CatalogID], out CatalogValue);
                }
            }

            if (base.XSLTemplateID > 0)
            {
                string catalogPath = CMSWebHelper.GetCatalogPath();
                catalogPath = CatalogManager.GetCatalogXMLPath(catalogPath, CMSContext.PortalID, CMSContext.LanguageID);

                string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
                xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(catalogPath);

                if (xmlDoc.ChildNodes.Count > 1)
                {
                    XmlAttribute xmlAtt = xmlDoc.CreateAttribute("CurrentCatalog");
                    xmlAtt.Value = CatalogValue.ToString();
                    xmlDoc.ChildNodes[1].Attributes.Append(xmlAtt);

                    xmlAtt = xmlDoc.CreateAttribute("LanguageID");
                    xmlAtt.Value = CMSContext.LanguageID.ToString();
                    xmlDoc.ChildNodes[1].Attributes.Append(xmlAtt);
                }

                XsltArgumentList arguments = new XsltArgumentList();
                arguments.AddExtensionObject("CMS:UserControl", this);

                xmlCatalog.DocumentContent = xmlDoc.OuterXml;
                xmlCatalog.TransformSource = xslPath;
                xmlCatalog.TransformArgumentList = arguments;
                xmlCatalog.DataBind();
            }
        }
Пример #28
0
        public string TransformXMLWithXSLText(string xmlText, string xslText)
        {
            try
            {
                //check that there is some xml
                if (string.IsNullOrEmpty(xmlText)) return "";
                //check that there is some xsl
                if (string.IsNullOrEmpty(xslText)) return "";
                XsltArgumentList arguments = new XsltArgumentList();
                arguments.AddExtensionObject("obj:CategoryViewer", this);
                //create a stringbuilder object to hold outputted html
                var sb = new StringBuilder();
                //load a string reader from the xml data
                using (StringReader xmlStringReader = new StringReader(xmlText))
                {
                    //create an xpath document from the xml data
                    XPathDocument xPathDoc = new XPathDocument(xmlStringReader);
                    //create a string reader for the xsl data
                    using (StringReader xslStringReader = new StringReader(xslText))
                    {
                        //pass xsl text into xmltextreader
                        using (XmlReader styleSheet = new XmlTextReader(xslStringReader))
                        {
                            //create the transformation class
                            XslCompiledTransform xslTrans = new XslCompiledTransform();

                            //load the xsl into the transformer
                            xslTrans.Load(styleSheet);
                            //create a stringwriter for outputting html to
                            using (StringWriter sw = new StringWriter(sb))
                            {
                                //do the actual transform of Xml
                                xslTrans.Transform(xPathDoc, arguments, sw);
                            }
                        }
                    }
                }
                return sb.ToString();
            }
            catch (Exception e)
            {
                dvdate.InnerText = e.ToString();
            }
            return "";
        }
Пример #29
0
		/// <summary>
		/// Converts the XsltTransformationArguments to a XsltArgumentList instance
		/// </summary>
		/// <param name="arguments">The arguments.</param>
		/// <returns></returns>
		private XsltArgumentList BuildXslArgumentList(XsltTransformationArguments arguments)
		{
			XsltArgumentList list = new XsltArgumentList();

			foreach (XsltTransformationParameter param in arguments.Parameters)
			{
				list.AddParam(param.Name, param.NameSpace, param.Value);
			}

			
			foreach (object exO in arguments.ExtensionObjects)
			{
				list.AddExtensionObject("urn:" + exO.GetType().Name,
					_Engine.DynamicAdapterStore.Adapt(exO));
			}
			return list;
			
		}
    public static string Transform(string xslt, string xml, IAsyncConnection conn)
    {
      var xal = new XsltArgumentList();
      xal.AddExtensionObject(Namespace, new ArasXsltExtensions(conn));

      var xsl = new MvpXslTransform();
      xsl.SupportedFunctions = Mvp.Xml.Exslt.ExsltFunctionNamespace.All;
      using (var reader = new StringReader(xslt))
      {
        using (var xmlReader = XmlReader.Create(reader))
        {
          xsl.Load(xmlReader);
        }
      }
      using (var writer = new System.IO.StringWriter())
      {
        xsl.Transform(new XmlInput(new StringReader(xml)), xal, new XmlOutput(writer));
        return writer.ToString();
      }
    }