public XmlReader Transform(XmlInput input, XsltArgumentList arguments, bool multiThread, int initialBufferSize)
        {
            var r = new XslReader(CompiledTransform, multiThread, initialBufferSize);

            r.StartTransform(input, AddExsltExtensionObjectsSync(arguments));
            return(r);
        }
        public XmlReader Transform(XmlInput input, XsltArgumentList arguments)
        {
            var r = new XslReader(CompiledTransform);

            r.StartTransform(input, AddExsltExtensionObjectsSync(arguments));
            return(r);
        }
 public XmlReader StartTransform(XmlInput input, XsltArgumentList args)
 {
     _defaulDocument = input;
     _args           = args;
     Start();
     return(this);
 }
        protected XmlReaderSettings GetReaderSettings(XmlInput defaultDocument)
        {
            if (defaultDocument.Resolver is DefaultXmlResolver)
            {
                return(DefaultReaderSettings);
            }
            var settings = DefaultReaderSettings.Clone();

            settings.XmlResolver = defaultDocument.Resolver;
            return(settings);
        }
        public XmlOutput Transform(XmlInput input, XsltArgumentList arguments, XmlOutput output)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            var xmlWriter   = output.Destination as XmlWriter;
            var closeWriter = false;

            if (xmlWriter == null)
            {
                closeWriter = true;
                while (true)
                {
                    var txtWriter = output.Destination as TextWriter;
                    if (txtWriter != null)
                    {
                        if (MultiOutput)
                        {
                            var mw = new MultiXmlTextWriter(txtWriter, output.XmlResolver);

                            if (CompiledTransform.OutputSettings.Indent)
                            {
                                mw.Formatting = Formatting.Indented;
                            }
                            xmlWriter = mw;
                        }
                        else
                        {
                            xmlWriter = XmlWriter.Create(txtWriter, CompiledTransform.OutputSettings);
                        }
                        break;
                    }
                    var strm = output.Destination as Stream;
                    if (strm != null)
                    {
                        if (MultiOutput)
                        {
                            var mw = new MultiXmlTextWriter(strm, CompiledTransform.OutputSettings.Encoding, output.XmlResolver);
                            if (CompiledTransform.OutputSettings.Indent)
                            {
                                mw.Formatting = Formatting.Indented;
                            }
                            xmlWriter = mw;
                        }
                        else
                        {
                            xmlWriter = XmlWriter.Create(strm, CompiledTransform.OutputSettings);
                        }
                        break;
                    }
                    var str = output.Destination as String;
                    if (str != null)
                    {
                        if (MultiOutput)
                        {
                            var mw = new MultiXmlTextWriter(str, CompiledTransform.OutputSettings.Encoding);
                            if (CompiledTransform.OutputSettings.Indent)
                            {
                                mw.Formatting = Formatting.Indented;
                            }
                            xmlWriter = mw;
                        }
                        else
                        {
                            var outputSettings = CompiledTransform.OutputSettings.Clone();
                            outputSettings.CloseOutput = true;
                            // BugBug: We should read doc before creating output file in case they are the same
                            xmlWriter = XmlWriter.Create(str, outputSettings);
                        }
                        break;
                    }
                    throw new Exception("Unexpected XmlOutput");
                }
            }
            try
            {
                TransformToWriter(input, arguments, xmlWriter);
            }
            finally
            {
                if (closeWriter)
                {
                    xmlWriter.Close();
                }
            }
            return(output);
        }
        protected void TransformToWriter(XmlInput defaultDocument, XsltArgumentList xsltArgs, XmlWriter targetWriter)
        {
            XmlWriter xmlWriter;

            if (SupportCharacterMaps && _characterMap != null && _characterMap.Count > 0)
            {
                xmlWriter = new CharacterMappingXmlWriter(targetWriter, _characterMap);
            }
            else
            {
                xmlWriter = targetWriter;
            }
            if (EnforceXHtmlOutput)
            {
                xmlWriter = new XhtmlWriter(xmlWriter);
            }
            var args      = AddExsltExtensionObjectsSync(xsltArgs);
            var xmlReader = defaultDocument.Source as XmlReader;

            if (xmlReader != null)
            {
                CompiledTransform.Transform(xmlReader, args, xmlWriter, defaultDocument.Resolver);
                return;
            }
            var nav = defaultDocument.Source as IXPathNavigable;

            if (nav != null)
            {
                if (defaultDocument.Resolver is DefaultXmlResolver)
                {
                    CompiledTransform.Transform(nav, args, xmlWriter);
                }
                else
                {
                    TransformXPathNavigable(nav, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            var str = defaultDocument.Source as string;

            if (str != null)
            {
                using (var reader = XmlReader.Create(str, GetReaderSettings(defaultDocument)))
                {
                    CompiledTransform.Transform(reader, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            var strm = defaultDocument.Source as Stream;

            if (strm != null)
            {
                using (var reader = XmlReader.Create(strm, GetReaderSettings(defaultDocument)))
                {
                    CompiledTransform.Transform(reader, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            var txtReader = defaultDocument.Source as TextReader;

            if (txtReader != null)
            {
                using (var reader = XmlReader.Create(txtReader, GetReaderSettings(defaultDocument)))
                {
                    CompiledTransform.Transform(reader, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            throw new Exception("Unexpected XmlInput");
        }