Esempio n. 1
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);
             }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
               }
            }
             }
        }
Esempio n. 4
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));
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public XsltExecutable Compile(TextReader module, XsltCompileOptions options)
 {
     return Compile(this.ItemFactory.CreateNodeReadOnly(module, new XmlParsingOptions { BaseUri = options.BaseUri, XmlResolver = options.XmlResolver }), options);
 }
Esempio n. 7
0
 XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, Uri baseUri)
 {
     return new SystemXsltExecutable(transform, this, baseUri ?? options.BaseUri);
 }
Esempio n. 8
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);
        }
Esempio n. 9
0
 XsltExecutable WrapExecutable(SaxonApiXsltExecutable xsltExecutable, XsltCompileOptions options, Uri baseUri)
 {
     return new SaxonXsltExecutable(xsltExecutable, this, baseUri ?? options.BaseUri);
 }
Esempio n. 10
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);
        }
Esempio 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;
        }
Esempio n. 12
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);
             }
        }
Esempio n. 13
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);
             }
        }