Exemplo n.º 1
0
        private void ReportCompilerErrors(DynamicErrorListener listener)
        {
            Report.Warnings(
                (pub, w) => pub.DescriptionReasonLocation(ReportGenre.XsltRuntime, w.Message, this.LocationString(w.getLocator())),
                listener.Warnings);

            Report.Warnings(
                (pub, e) => pub.DescriptionReasonLocation(ReportGenre.XsltRuntime, e.Message, this.LocationString(e.getLocator())),
                listener.Errors);

            Report.Errors(
                (pub, e) => pub.DescriptionReasonLocation(ReportGenre.XsltRuntime, e.Message, this.LocationString(e.getLocator())),
                listener.FatalErrors);
        }
Exemplo n.º 2
0
        public XmlDocument Run(XNode xDocument, string baseOutputUri = null, params KeyValuePair <string, object>[] arguments)
        {
            // Load the source document from an XMLReader.
            var reader = xDocument.CreateReader();

            // Load execuable.
            var transformer = _executable.Load();

            // Set the root node of the source document to be the initial context node
            transformer.InitialContextNode = _builder.Build(reader);

            // Set where to output xsl:result-document constructs.
            if (baseOutputUri != null)
            {
                transformer.BaseOutputUri = new Uri(baseOutputUri);
            }

            // Set parameters.
            this.SetParams(ref transformer, arguments);

            // The transformation destination variable.
            var destination = new DomDestination();

            // Errors will be reported by the exception handling.
            transformer.Implementation.setErrorListener(new TransformerErrorListener());

            // Output the transform to the above variable.
            var listener = new DynamicErrorListener();

            try
            {
                transformer.Implementation.setErrorListener(listener);
                transformer.Run(destination);
            }
            catch (DynamicError)
            {
                this.ReportCompilerErrors(listener);
            }

            // Clear any set parameters.
            transformer.Reset();

            return(destination.XmlDocument);
        }