Ejemplo n.º 1
0
        public static SchematronValidator CreateSchematronValidator(this IXsltProcessor processor, IXPathNavigable schemaDoc)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }
            if (schemaDoc == null)
            {
                throw new ArgumentNullException("schemaDoc");
            }

            IXPathNavigable stylesheetDoc = processor.ItemFactory.BuildNode();

            XmlWriter builder = stylesheetDoc.CreateNavigator().AppendChild();

            processor.BuildSchematronValidatorStylesheet(schemaDoc, builder);

            builder.Close();

            var compileOptions = new XsltCompileOptions();

            XPathNavigator schemaNav = schemaDoc.CreateNavigator();

            if (!String.IsNullOrEmpty(schemaNav.BaseURI))
            {
                compileOptions.BaseUri = new Uri(schemaNav.BaseURI);
            }

            return(new XsltSchematronValidator(processor.Compile(stylesheetDoc, compileOptions)));
        }
Ejemplo n.º 2
0
        public XsltExecutable Compile(IXPathNavigable module, XsltCompileOptions options)
        {
            XsltCompiler compiler = CreateCompiler(options);

            XPathNavigator nav = module.CreateNavigator();
            XdmNode        node;

            if (SaxonExtensions.TryGetXdmNode(nav, out node))
            {
                Uri baseUri = null;

                try {
                    baseUri = node.BaseUri;
                } catch (ArgumentNullException) {
                } catch (UriFormatException) { }

                try {
                    return(WrapExecutable(compiler.Compile(node), options, baseUri));
                } catch (Exception ex) {
                    throw WrapCompileException(ex, compiler);
                }
            }
            else
            {
                return(Compile(nav.ReadSubtree(), options));
            }
        }
Ejemplo n.º 3
0
        public XsltExecutable Compile(TextReader module, XsltCompileOptions options)
        {
            XsltCompiler compiler = CreateCompiler(options);

            try {
                return(WrapExecutable(compiler.Compile(module), options, default(Uri)));
            } catch (Exception ex) {
                throw WrapCompileException(ex, compiler);
            }
        }
Ejemplo n.º 4
0
      XsltCompiler CreateCompiler(XsltCompileOptions options) {

         XsltCompiler compiler = this.processor.NewXsltCompiler();
         compiler.ErrorList = new ArrayList();
         compiler.BaseUri = options.BaseUri;

         if (options.XmlResolver != null)
            compiler.XmlResolver = options.XmlResolver;

         return compiler;
      }
Ejemplo n.º 5
0
        public XsltExecutable Compile(XmlReader module, XsltCompileOptions options)
        {
            XsltCompiler compiler = CreateCompiler(options);

            string baseUri = module.BaseURI;

            try {
                return(WrapExecutable(compiler.Compile(module), options, baseUri));
            } catch (Exception ex) {
                throw WrapCompileException(ex, compiler);
            }
        }
Ejemplo n.º 6
0
      public XsltExecutable Compile(XmlReader module, XsltCompileOptions options) {

         XslCompiledTransform transform = CreateTransform();

         try {
            transform.Load(module, this.Settings, options.XmlResolver);
         } catch (XsltException ex) {
            throw new SystemXsltException(ex);
         }

         return CreateExecutable(transform, options, module.BaseURI);
      }
Ejemplo n.º 7
0
      XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, string baseUri) {

         Uri parsedBaseUri = null;

         if (!String.IsNullOrEmpty(baseUri)) {
            try {
               parsedBaseUri = new Uri(baseUri);
            } catch (UriFormatException) { }
         }

         return CreateExecutable(transform, options, parsedBaseUri);
      }
Ejemplo n.º 8
0
        public XsltExecutable Compile(XmlReader module, XsltCompileOptions options)
        {
            XslCompiledTransform transform = CreateTransform();

            try {
                transform.Load(module, this.Settings, options.XmlResolver);
            } catch (XsltException ex) {
                throw new SystemXsltException(ex);
            }

            return(CreateExecutable(transform, options, module.BaseURI));
        }
Ejemplo n.º 9
0
        XsltExecutable WrapExecutable(SaxonApiXsltExecutable xsltExecutable, XsltCompileOptions options, string baseUri)
        {
            Uri parsedBaseUri = null;

            if (!String.IsNullOrEmpty(baseUri))
            {
                try {
                    parsedBaseUri = new Uri(baseUri);
                } catch (UriFormatException) { }
            }

            return(WrapExecutable(xsltExecutable, options, parsedBaseUri));
        }
Ejemplo n.º 10
0
        XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, string baseUri)
        {
            Uri parsedBaseUri = null;

            if (!String.IsNullOrEmpty(baseUri))
            {
                try {
                    parsedBaseUri = new Uri(baseUri);
                } catch (UriFormatException) { }
            }

            return(CreateExecutable(transform, options, parsedBaseUri));
        }
Ejemplo n.º 11
0
        XsltCompiler CreateCompiler(XsltCompileOptions options)
        {
            XsltCompiler compiler = this.processor.NewXsltCompiler();

            compiler.ErrorList = new ArrayList();
            compiler.BaseUri   = options.BaseUri;

            if (options.XmlResolver != null)
            {
                compiler.XmlResolver = options.XmlResolver;
            }

            return(compiler);
        }
Ejemplo n.º 12
0
      public XsltExecutable Compile(IXPathNavigable module, XsltCompileOptions options) {

         XslCompiledTransform transform = CreateTransform();

         XPathNavigator nav = module.CreateNavigator();

         try {
            transform.Load(nav, this.Settings, options.XmlResolver);
         } catch (XsltException ex) {
            throw new SystemXsltException(ex);
         }

         return CreateExecutable(transform, options, nav.BaseURI);
      }
Ejemplo n.º 13
0
        public XsltExecutable Compile(IXPathNavigable module, XsltCompileOptions options)
        {
            XslCompiledTransform transform = CreateTransform();

            XPathNavigator nav = module.CreateNavigator();

            try {
                transform.Load(nav, this.Settings, options.XmlResolver);
            } catch (XsltException ex) {
                throw new SystemXsltException(ex);
            }

            return(CreateExecutable(transform, options, nav.BaseURI));
        }
Ejemplo n.º 14
0
      public XsltExecutable Compile(IXPathNavigable module, XsltCompileOptions options) {

         XsltCompiler compiler = CreateCompiler(options);

         XPathNavigator nav = module.CreateNavigator();
         XdmNode node;

         if (SaxonExtensions.TryGetXdmNode(nav, out node)) {
            Uri baseUri = node.BaseUri;
            
            try {
               return WrapExecutable(compiler.Compile(node), options, baseUri);
            } catch (Exception ex) {
               throw WrapCompileException(ex, compiler);
            }
         } else {
            return Compile(nav.ReadSubtree(), options);
         }
      }
Ejemplo n.º 15
0
 XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, Uri baseUri) {
    return new SystemXsltExecutable(transform, this, baseUri ?? options.BaseUri);      
 }
Ejemplo n.º 16
0
      public XsltExecutable Compile(Stream module, XsltCompileOptions options) {

         XsltCompiler compiler = CreateCompiler(options);

         try {
            return WrapExecutable(compiler.Compile(module), options, default(Uri));
         } catch (Exception ex) {
            throw WrapCompileException(ex, compiler);
         }
      }
Ejemplo n.º 17
0
 XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, Uri baseUri)
 {
     return(new SystemXsltExecutable(transform, this, baseUri ?? options.BaseUri));
 }
Ejemplo n.º 18
0
 public XsltExecutable Compile(TextReader module, XsltCompileOptions options) {
    return Compile(this.ItemFactory.CreateNodeReadOnly(module, new XmlParsingOptions { BaseUri = options.BaseUri, XmlResolver = options.XmlResolver }), options);
 }
Ejemplo n.º 19
0
 XsltExecutable WrapExecutable(Saxon.Api.XsltExecutable xsltExecutable, XsltCompileOptions options, Uri baseUri) {
    return new SaxonXsltExecutable(xsltExecutable, this, baseUri ?? options.BaseUri);
 }
Ejemplo n.º 20
0
 public XsltExecutable Compile(TextReader module, XsltCompileOptions options)
 {
     return(Compile(this.ItemFactory.CreateNodeReadOnly(module, new XmlParsingOptions {
         BaseUri = options.BaseUri, XmlResolver = options.XmlResolver
     }), options));
 }
Ejemplo n.º 21
0
        public static void BuildSchematronValidatorStylesheet(this IXsltProcessor processor, IXPathNavigable schemaDoc, XmlWriter output)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }
            if (schemaDoc == null)
            {
                throw new ArgumentNullException("schemaDoc");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            XPathNavigator nav = schemaDoc.CreateNavigator();

            if (nav.NodeType != XPathNodeType.Root)
            {
                throw new ArgumentException("The schema must be a document node.", "schemaDoc");
            }

            string  queryBinding    = nav.GetAttribute("queryBinding", "");
            decimal procXsltVersion = processor.GetXsltVersion();

            string xsltVersion;

            if (String.IsNullOrEmpty(queryBinding))
            {
                int maxMajorVersion = (procXsltVersion >= 3m) ? 2
               : (int)Decimal.Floor(procXsltVersion);

                xsltVersion = "xslt" + maxMajorVersion.ToStringInvariant();
            }
            else
            {
                string qbLower = queryBinding.ToLowerInvariant();

                switch (qbLower)
                {
                case "xslt":
                case "xslt1":
                case "xpath":
                case "xpath1":
                    xsltVersion = "xslt1";
                    break;

                case "xslt2":
                case "xpath2":

                    if (procXsltVersion < 2)
                    {
                        throw new ArgumentException(
                                  "The queryBinding '{0}' is not supported by this processor. Lower the language version or use a different processor.".FormatInvariant(queryBinding),
                                  "schemaDoc"
                                  );
                    }

                    xsltVersion = "xslt2";
                    break;

                default:
                    throw new ArgumentException(
                              "The queryBinding '{0}' is not supported. Valid values are: {1}.".FormatInvariant(queryBinding, String.Join(", ", GetQueryBindings())),
                              "schemaDoc"
                              );
                }
            }

            Assembly assembly = Assembly.GetExecutingAssembly();

            Uri baseUri = new UriBuilder {
                Scheme = XmlEmbeddedResourceResolver.UriSchemeClires,
                Host   = null,
                Path   = String.Concat(assembly.GetName().Name, "/", xsltVersion, "/")
            }.Uri;

            var compileOptions = new XsltCompileOptions(baseUri)
            {
                XmlResolver = new XmlDynamicResolver() // use calling assembly as default
            };

            string[] stages = { "iso_dsdl_include.xsl", "iso_abstract_expand.xsl", String.Concat("iso_svrl_for_", xsltVersion, ".xsl") };

            IXPathNavigable input = schemaDoc;

            for (int i = 0; i < stages.Length; i++)
            {
                var stageUri = new Uri(baseUri, stages[i]);

                using (var stageDoc = (Stream)compileOptions.XmlResolver.GetEntity(stageUri, null, typeof(Stream))) {
                    XsltExecutable executable = processor.Compile(stageDoc, compileOptions);

                    var runtimeOptions = new XsltRuntimeOptions {
                        InitialContextNode = input,
                        InputXmlResolver   = compileOptions.XmlResolver
                    };

                    if (i < stages.Length - 1)
                    {
                        // output becomes the input for the next stage
                        input = executable.Run(runtimeOptions);
                    }
                    else
                    {
                        // last stage is output to writer
                        executable.Run(output, runtimeOptions);
                    }
                }
            }
        }
Ejemplo n.º 22
0
      XsltExecutable WrapExecutable(Saxon.Api.XsltExecutable xsltExecutable, XsltCompileOptions options, string baseUri) {

         Uri parsedBaseUri = null;

         if (!String.IsNullOrEmpty(baseUri)) {
            try {
               parsedBaseUri = new Uri(baseUri);
            } catch (UriFormatException) { }
         }

         return WrapExecutable(xsltExecutable, options, parsedBaseUri);
      }
Ejemplo n.º 23
0
 XsltExecutable WrapExecutable(SaxonApiXsltExecutable xsltExecutable, XsltCompileOptions options, Uri baseUri)
 {
     return(new SaxonXsltExecutable(xsltExecutable, this, baseUri ?? options.BaseUri));
 }
Ejemplo n.º 24
0
      public XsltExecutable Compile(XmlReader module, XsltCompileOptions options) {

         XsltCompiler compiler = CreateCompiler(options);

         string baseUri = module.BaseURI;

         try {
            return WrapExecutable(compiler.Compile(module), options, baseUri);
         } catch (Exception ex) {
            throw WrapCompileException(ex, compiler);
         }
      }