示例#1
0
        public virtual void RenderHtml(TextWriter writer, XPathDocument xmlDoc)
        {
            // Transform XLST validation
            var virtualDir = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
            var fileXslt   = Xslt.Replace("/", "\\");
            var path       = (System.IO.Path.GetDirectoryName(this.Context.Request.Path
                                                              .Replace("/", "\\")) + "\\").Replace(@"\\", @"\");

            if (System.IO.File.Exists(virtualDir + path + fileXslt))
            {
                xsltFileFull = virtualDir + path + fileXslt;
            }
            else
            {
                xsltFileFull = virtualDir + fileXslt;
            }

            xsltFileFull = System.IO.Path.GetFullPath(xsltFileFull);

            Trace.Write("Transform ID=" + this.ID, "xslt=" + xsltFileFull);

            XsltArgumentList     xslArg = new XsltArgumentList();
            XslCompiledTransform trans  = new XslCompiledTransform();

            if (Context != null && Xslt.Length > 0 && File.Exists(xsltFileFull))
            {
                string serverUrl = Context.Request.Url.Scheme + "://" + Context.Request.Url.Authority + "/";

                XsltIncludeResolver resolver = new XsltIncludeResolver(serverUrl);  // for <xsl:include>
                trans.Load(xsltFileFull, XsltSettings.TrustedXslt, resolver as XmlUrlResolver);
            }
            else
            {
                var reader = XmlReader.Create(System.IO.File.OpenRead(xsltFileFull));
                trans.Load(stylesheet: reader);
            }

            Trace.Write("Transform ID=" + this.ID, "XSLT Parse Test OK." + xsltFileFull);

            AddRequestInfo(xslArg);

            if (isDebug <= 1)
            {
                trans.Transform(xmlDoc, xslArg, writer);
            }
        }