Example #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SchematronValidator(string errorXPath, string errorMessageXPath)
 {
     this.logger            = LoggerFactory.Create(this.GetType());
     this.xlstUtil          = new XsltUtility();
     this.errorXPath        = errorXPath;
     this.errorMessageXPath = errorMessageXPath;
 }
Example #2
0
        /// <summary>
        /// Constructor that takes the configuration as a parameter
        /// </summary>
        /// <param name="config"></param>
        public SchematronValidator(SchematronValidationConfig config)
        {
            this.logger            = LoggerFactory.Create(this.GetType());
            this.xlstUtil          = new XsltUtility();
            this.errorXPath        = config.ErrorXPath;
            this.errorMessageXPath = config.ErrorMessageXPath;

            string stylesheetPath;
            string basePath = ConfigurationManager.AppSettings["ResourceBasePath"];

            if (string.IsNullOrEmpty(basePath))
            {
                stylesheetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.SchematronDocumentPath);
            }
            else
            {
                stylesheetPath = Path.Combine(basePath, config.SchematronDocumentPath);
            }

            this.compiledXsltEntry = new CompiledXslt(new FileInfo(stylesheetPath));
        }
Example #3
0
 /// <summary>
 /// Constructor that takes a PruningBindingExtensionElement which contains
 /// configuration information to the pruning interceptor.
 /// </summary>
 /// <param name="configuration"></param>
 public ServerXsltTransformationBindingElement(ServerXsltTransformationBindingExtensionElement configuration)
 {
     _configuration = configuration;
     _xsltUtility   = new XsltUtility();
     _searcher      = new DocumentTypeConfigSearcher();
 }
Example #4
0
 /// <summary>
 /// Constructs a new schematron validator
 /// </summary>
 public SchematronValidator()
 {
     this.logger   = LoggerFactory.Create(this.GetType());
     this.xlstUtil = new XsltUtility();
 }
Example #5
0
        public CompiledXslt(FileInfo fileInfo)
        {
            this.fileInfo = fileInfo;

            try
            {
                // Note, if not explicit marked as version 1.0, we default to SaXon
                XsltUtility xsltUtility = new XsltUtility();
                XmlDocument stylesheet  = new XmlDocument();
                stylesheet.Load(this.fileInfo.FullName);

                // Get XSLT version
                XPathNavigator    navigator = stylesheet.CreateNavigator();
                XPathNodeIterator node      = navigator.Select("/*/@version");
                node.MoveNext();
                string xsltVersionInResource = node.Current.Value;
                string xsltVersion           = string.Empty;
                if (!string.IsNullOrEmpty(xsltVersionInResource))
                {
                    xsltVersion = xsltVersionInResource;
                }

                if (xsltVersion.Equals("1.0"))
                {
                    // The XslCompiledTransform can only handle xslt version 1.0
                    transform = new XslCompiledTransform(false);
                    transform.Load(stylesheet, XsltSettings.Default, null);
                }
            }
            catch (System.Xml.Xsl.XsltException ex)
            {
                if (ex.Message.Equals("Too complex!"))
                {
                    // To complex - normally behavior
                    // using saxon
                    this.transform = null;
                }
                else if (ex.Message.Equals("XSLT compile error."))
                {
                    // To complex - normally behavior
                    // using saxon
                    this.transform = null;
                }
                else if (ex.Message.Contains("is an unknown XSLT function"))
                {
                    // To complex - normally behavior
                    // using saxon
                    this.transform = null;
                }
                else
                {
                    //Debug.Assert(false, "XslCompiledTransform failed loading stylesheet.", ex.ToString());
                    // what if the message has been translated to Danish???
                    throw;
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("XslCompiledTransform failed loading stylesheet.", ex.ToString());
                throw;
            }

            ////XDocument xmlFile = XDocument.Load(fileInfo.FullName);
            ////IEnumerable<XAttribute> attributeCollection = xmlFile.Root.Attributes();
            ////bool useDefault = false;
            ////foreach (XAttribute attribute in attributeCollection)
            ////{
            ////    if (attribute.Name.LocalName.Equals("version", StringComparison.OrdinalIgnoreCase))
            ////    {
            ////        if (attribute.Value.Equals("1") || attribute.Value.Equals("1.0"))
            ////        {
            ////            useDefault = true;
            ////            break;
            ////        }
            ////    }
            ////}

            ////if (useDefault)
            ////{
            ////    // use Microsoft default
            ////    XmlDocument xmlStylesheet = new XmlDocument();
            ////    XsltUtility xsltUtility = new XsltUtility();

            ////    DirectoryInfo directoryInfo = fileInfo.Directory;
            ////    UrlToLocalFilelResolver urlResolver = new UrlToLocalFilelResolver(directoryInfo.FullName);

            ////    xmlStylesheet.Load(fileInfo.FullName);
            ////    xmlStylesheet.XmlResolver = urlResolver;
            ////    this.transform = xsltUtility.PrecompiledStyleSheet(xmlStylesheet);
            ////}
            ////else
            ////{
            ////    // use saxon
            ////    this.transform = null;
            ////}
        }