public void Style(
            [ArgRequired, ArgExistingFile, ArgDescription("Full path to .xml file (mandatory)")] string xml,
            [ArgRequired, ArgExistingFile, ArgDescription("Full path to .xslt file (stylesheet) (mandatory)")] string stylesheet,
            [ArgDescription("Full path to output file (optional)")] string output)
        {
            var transformers = new List <IXsltTransformer> {
                new XslCompiledTransformer()
            };

#if SAXONSUPPORT
            transformers.Add(new SaxonTransformer());
#endif
            IXsltTransformer xsltTransformer  = new XsltTransformerSelector(transformers.ToArray());
            XsltFileProvider xsltFileProvider = null;
            try
            {
                xsltFileProvider = new XsltFileProvider(stylesheet);
            }
            catch (Exception e)
            {
                Console.WriteLine($"When loading stylesheet {stylesheet} -> {e.Message}");
                Environment.Exit(1);
            }

            try
            {
                xsltTransformer.Transform(xsltFileProvider, xml, output ?? CreateOuputFilePathFromInputFilePath(xml, "html", ""));
            }
            catch (Exception e)
            {
                Console.WriteLine($"When styling {xml} -> {e.Message}");
                Environment.Exit(1);
            }
        }
        public XsltFileProvider Schematron(
            [ArgRequired, ArgExistingFile, ArgDescription("Full path to xslt file to validate")] string schematron)
        {
            var xsltFileProvider = new XsltFileProvider(schematron);

            Console.Write("Schmatron: {0} [xsltVersion: {1}]", xsltFileProvider.Path, xsltFileProvider.XsltVersion);
            ColorConsole.Ok();
            return(xsltFileProvider);
        }
        public void Xml(
            [ArgRequired, ArgExistingFile, ArgDescription("Full path to xml file to validate.")] string file,
            [ArgExistingFile, ArgDescription("If schema is given, that schema file is used. Otherwise an inline (schemaLocation) is searched.")] string schema,
            [ArgExistingFile, ArgDescription("If schematron is given, that xslt file is used to do schematron validation.")] string schematron
            )
        {
            XmlSchemaProvider xmlSchemaProvider = null;

            if (!string.IsNullOrEmpty(schema))
            {
                Console.Write("Using ");
                xmlSchemaProvider = Schema(schema);
            }

#if NET461
            XsltFileProvider xsltFileProvider = null;
            if (!string.IsNullOrEmpty(schematron))
            {
                Console.Write("Using: ");
                xsltFileProvider = Schematron(schematron);
            }
#endif

            Console.Write($"Validating xml:\t{file}  ");

            var validateionResult = xmlSchemaProvider != null
                ? new XmlSchemaValidator(xmlSchemaProvider).Validate(file)
                : new XmlValidator().Validate(file);

            if (validateionResult.WarningCount > 0 || validateionResult.ErrorCount > 0)
            {
                Console.WriteLine();
                foreach (var warning in validateionResult.Warnings)
                {
                    Console.Write("-> ");
                    ColorConsole.Warning(warning);
                }

                foreach (var error in validateionResult.Errors)
                {
                    Console.Write("-> ");
                    ColorConsole.Error(error);
                }
            }
            else
            {
#if NET461
                if (xsltFileProvider != null)
                {
                    var saxonResult = new SaxonValidator(xsltFileProvider).Validate(file);
                }
#endif
                ColorConsole.Ok();
            }
        }
        public void StyleAll(
            [ArgRequired, ArgExistingDirectory, ArgDescription("Full path to directory containing xml files (mandatory)")] string dir,
            [ArgRequired, ArgExistingFile, ArgDescription("Full path to .xslt file (stylesheet) (mandatory)")] string stylesheet,
            [ArgExistingDirectory, ArgDescription("Full path to output directory (optional)")] string output)
        {
            var transformers = new List <IXsltTransformer> {
                new XslCompiledTransformer()
            };

#if SAXONSUPPORT
            transformers.Add(new SaxonTransformer());
#endif
            IXsltTransformer xsltTransformer  = new XsltTransformerSelector(transformers.ToArray());
            XsltFileProvider xsltFileProvider = null;
            try
            {
                xsltFileProvider = new XsltFileProvider(stylesheet);
            }
            catch (Exception e)
            {
                Console.WriteLine($"When loading stylesheet {stylesheet} -> {e.Message}");
                Environment.Exit(1);
            }

            if (string.IsNullOrEmpty(output))
            {
                output = dir;
            }

            foreach (var xml in Directory.EnumerateFiles(dir, "*.xml"))
            {
                try
                {
                    var outFile = Path.Combine(output, $"{Path.GetFileNameWithoutExtension(xml)}.html");
                    xsltTransformer.Transform(xsltFileProvider, xml, outFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"When styling {xml} -> {e.Message}");
                    Environment.Exit(1);
                }
            }
        }