You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/09/12 17:40:23 UTC

[05/13] git commit: CAMEL-7220 Added Camel Schematron component with thanks to Ayache

CAMEL-7220 Added Camel Schematron component with thanks to Ayache


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a07d71fe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a07d71fe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a07d71fe

Branch: refs/heads/camel-2.14.x
Commit: a07d71feb7f4ed8506dc41977e68749244607b14
Parents: 7bbfd35
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Sep 12 21:49:12 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Sep 12 23:37:09 2014 +0800

----------------------------------------------------------------------
 components/camel-schematron/README.md           |   29 +
 components/camel-schematron/pom.xml             |   64 +
 .../schematron/SchematronComponent.java         |   43 +
 .../schematron/SchematronEndpoint.java          |  114 +
 .../schematron/SchematronProducer.java          |   99 +
 .../schematron/constant/Constants.java          |   37 +
 .../exception/SchematronConfigException.java    |   32 +
 .../SchematronValidationException.java          |   34 +
 .../processor/ClassPathURIResolver.java         |   46 +
 .../processor/SchematronProcessor.java          |   76 +
 .../processor/SchematronProcessorFactory.java   |   79 +
 .../schematron/processor/TemplatesFactory.java  |   94 +
 .../org/apache/camel/component/schematron       |   18 +
 .../ExtractSchFromRNG-2.xsl                     |   75 +
 .../ExtractSchFromXSD-2.xsl                     |   77 +
 .../iso_abstract_expand.xsl                     |  297 +++
 .../iso-schematron-xslt2/iso_dsdl_include.xsl   | 1508 ++++++++++++
 .../iso_schematron_message_xslt2.xsl            |   55 +
 .../iso_schematron_skeleton_for_saxon.xsl       | 2299 ++++++++++++++++++
 .../iso-schematron-xslt2/iso_svrl_for_xslt2.xsl |  684 ++++++
 .../resources/iso-schematron-xslt2/readme.txt   |  100 +
 .../iso-schematron-xslt2/sch-messages-cs.xhtml  |   56 +
 .../iso-schematron-xslt2/sch-messages-de.xhtml  |   57 +
 .../iso-schematron-xslt2/sch-messages-en.xhtml  |   57 +
 .../iso-schematron-xslt2/sch-messages-fr.xhtml  |   54 +
 .../iso-schematron-xslt2/sch-messages-nl.xhtml  |   58 +
 .../schematron-skeleton-api.htm                 |  723 ++++++
 .../schematron/SchematronComponentTest.java     |   85 +
 .../schematron/SchematronEndpointTest.java      |   86 +
 .../schematron/SchematronProducerTest.java      |   71 +
 .../processor/SchematronProcessorTest.java      |   76 +
 .../processor/TemplatesFactoryTest.java         |   42 +
 .../camel/component/schematron/util/Utils.java  |   63 +
 .../src/test/resources/log4j.properties         |   14 +
 .../test/resources/report/article-1-report.xml  |   21 +
 .../test/resources/report/article-2-report.xml  |   17 +
 .../src/test/resources/sch/schematron-1.sch     |   17 +
 .../src/test/resources/sch/schematron-2.sch     |   21 +
 .../src/test/resources/schema/article.xsd       |   18 +
 .../src/test/resources/xml/article-1.xml        |   15 +
 .../src/test/resources/xml/article-2.xml        |   14 +
 41 files changed, 7425 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/README.md
----------------------------------------------------------------------
diff --git a/components/camel-schematron/README.md b/components/camel-schematron/README.md
new file mode 100644
index 0000000..d5dfc0e
--- /dev/null
+++ b/components/camel-schematron/README.md
@@ -0,0 +1,29 @@
+Schematron Component
+====================
+
+Schematron is an XML-based language for validating XML instance documents. Schematron is used to make assertions about data in an XML document. Schematron is used to express operational and business rules.
+Schematron is an ISO standard.
+Use Schematron to verify data interdependencies (co-constraints), check data cardinality, and perform algorithmic checks. A co-constraint is a dependency between data within an XML document or across XML documents. Cardinality refers to the presence or absence of data. An algorithmic check determines data validity by performing an algorithm on the data.
+
+Schematron engine
+======================
+
+Schemaron engine is an XSLT based implementation. XLST source code can be found here: https://code.google.com/p/schematron/
+
+
+Schematron Tutorials
+======================
+
+http://www.schematron.com/spec.html
+
+http://www.xml.com/pub/a/2003/11/12/schematron.html
+
+http://www.data2type.de/en/xml-xslt-xslfo/schematron/
+
+http://www.mulberrytech.com/papers/schematron-Philly.pdf
+
+http://www.ldodds.com/papers/schematron_xsltuk.html#c35e2592b6b7
+
+To build this project use
+
+    mvn clean install

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml
new file mode 100644
index 0000000..dae5eb4
--- /dev/null
+++ b/components/camel-schematron/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+   <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>components</artifactId>
+        <version>2.15-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-schematron</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: SCHEMATRON</name>
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.schematron.*</camel.osgi.export.pkg>
+        <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=schematron</camel.osgi.export.service>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.saxon</groupId>
+            <artifactId>Saxon-HE</artifactId>
+            <version>${saxon-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>${commons-io-version}</version>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>xmlunit</groupId>
+            <artifactId>xmlunit</artifactId>
+            <version>${xmlunit-version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java
new file mode 100644
index 0000000..c1327d4
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronComponent.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron;
+
+import java.util.Map;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Represents the component that manages {@link SchematronEndpoint}.
+ */
+public class SchematronComponent extends DefaultComponent {
+
+
+    /**
+     * Creates the Schematron Endpoint.
+     *
+     * @param uri
+     * @param remaining
+     * @param parameters
+     * @return
+     * @throws Exception
+     */
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+        Endpoint endpoint = new SchematronEndpoint(uri, remaining, this);
+        setProperties(endpoint, parameters);
+        return endpoint;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java
new file mode 100644
index 0000000..e932980
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronEndpoint.java
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron;
+
+import java.io.File;
+import java.io.InputStream;
+
+import javax.xml.transform.Templates;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.schematron.exception.SchematronConfigException;
+import org.apache.camel.component.schematron.processor.TemplatesFactory;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.util.ResourceHelper;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+
+/**
+ * Schematron Endpoint.
+ */
+public class SchematronEndpoint extends DefaultEndpoint {
+
+    private Logger logger = LoggerFactory.getLogger(SchematronEndpoint.class);
+    private String remaining;
+    private boolean abort;
+    private Templates rules;
+
+
+    public SchematronEndpoint() {
+    }
+
+    public SchematronEndpoint(String uri, String remaining, SchematronComponent component) {
+        super(uri, component);
+        this.remaining = remaining;
+    }
+
+    public SchematronEndpoint(String endpointUri) {
+        super(endpointUri);
+    }
+
+    public Producer createProducer() throws Exception {
+        return new SchematronProducer(this);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException("Consumer is not implemented for this component");
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public void setAbort(boolean abort) {
+        this.abort = abort;
+    }
+
+    public boolean isAbort() {
+        return abort;
+    }
+
+    public Templates getRules() {
+        return rules;
+    }
+
+    public void setRules(Templates rules) {
+        this.rules = rules;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if (rules == null) {
+            try {
+                // Attempt to read the schematron rules  from the class path first.
+                logger.info("Reading schematron rules from class path {}", remaining);
+                InputStream schRules = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), remaining);
+                rules = TemplatesFactory.newInstance().newTemplates(schRules);
+            } catch (Exception e) {
+                // Attempts from the file system.
+                logger.info("Schamatron rules not found in class path, attempting file system {}", remaining);
+                InputStream schRules = FileUtils.openInputStream(new File(remaining));
+                rules = TemplatesFactory.newInstance().newTemplates(schRules);
+            }
+
+            // rules not found in class path nor in file system.
+            if (rules == null) {
+                logger.error("Schematron rules not found {}", remaining);
+                throw new SchematronConfigException("Failed to load rules: " + remaining);
+            }
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java
new file mode 100644
index 0000000..e5d000b
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/SchematronProducer.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.schematron.constant.Constants;
+import org.apache.camel.component.schematron.exception.SchematronValidationException;
+import org.apache.camel.component.schematron.processor.SchematronProcessorFactory;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Schematron producer.
+ */
+public class SchematronProducer extends DefaultProducer {
+    private Logger logger = LoggerFactory.getLogger(SchematronProducer.class);
+    private SchematronEndpoint endpoint;
+
+
+    /**
+     * @param endpoint the schematron endpoint.
+     */
+    public SchematronProducer(final SchematronEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    /**
+     * Processes the payload. Validates the XML using the SchematronEngine
+     *
+     * @param exchange
+     * @throws Exception
+     */
+    public void process(Exchange exchange) throws Exception {
+
+        String payload = exchange.getIn().getBody(String.class);
+        logger.debug("Applying schematron validation on payload: {}", payload);
+        String report = SchematronProcessorFactory.newScehamtronEngine(endpoint.getRules()).validate(payload);
+        logger.debug("Schematron validation report \n {}", report);
+        String status = getValidationStatus(report);
+        logger.info("Schematron validation status : {}", status);
+        setValidationReport(exchange, report, status);
+    }
+
+    /**
+     * Sets validation report and status
+     *
+     * @param exchange
+     * @param report
+     * @param status
+     */
+    private void setValidationReport(Exchange exchange, String report, String status) {
+        // if exchange pattern is In and Out set details on the Out message.
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put(Constants.VALIDATION_STATUS, status);
+        headers.put(Constants.VALIDATION_REPORT, report);
+        exchange.getOut().setHeader(Constants.VALIDATION_REPORT, report);
+        if (exchange.getPattern().isOutCapable()) {
+            exchange.getOut().setHeaders(exchange.getIn().getHeaders());
+            exchange.getOut().getHeaders().putAll(headers);
+        } else {
+            exchange.getIn().getHeaders().putAll(headers);
+        }
+    }
+
+    /**
+     * Get validation status, SUCCESS or FAILURE
+     *
+     * @param report
+     * @return
+     */
+    private String getValidationStatus(final String report) {
+
+        String status = report.contains(Constants.FAILED_ASSERT) ? Constants.FAILED : Constants.SUCCESS;
+        if (this.endpoint.isAbort() && Constants.FAILED.equals(status)) {
+            throw new SchematronValidationException("Schematron validation failure \n" + report);
+        }
+        return status;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java
new file mode 100644
index 0000000..bd3f07a
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/constant/Constants.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.constant;
+
+/**
+ * Utility class defining all constants needed for the schematron component.
+ * <p/>
+ */
+public final class Constants {
+
+    public static final String VALIDATION_STATUS = "CamelSchematronValidationStatus";
+    public static final String VALIDATION_REPORT = "CamelSchematronValidationReport";
+    public static final String HTTP_PURL_OCLC_ORG_DSDL_SVRL = "http://purl.oclc.org/dsdl/svrl";
+    public static final String FAILED_ASSERT = "failed-assert";
+    public static final String FAILED = "FAILED";
+    public static final String SUCCESS = "SUCCESS";
+    public static final String SCHEMATRON_TEMPLATES_ROOT_DIR = "iso-schematron-xslt2";
+
+    private Constants() {
+        throw new IllegalStateException("Utility class should not be instantiated");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java
new file mode 100644
index 0000000..f94621b
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronConfigException.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.exception;
+
+import org.apache.camel.RuntimeCamelException;
+
+/**
+ * Schematron configuration Exception.
+ */
+public class SchematronConfigException extends RuntimeCamelException {
+    public SchematronConfigException(Throwable e) {
+        super(e);
+    }
+
+    public SchematronConfigException(String message) {
+        super(message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java
new file mode 100644
index 0000000..d8554d7
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/exception/SchematronValidationException.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.exception;
+
+import org.apache.camel.RuntimeCamelException;
+
+/**
+ * SchematronValidationException is thrown if option is set to true.
+ */
+public class SchematronValidationException extends RuntimeCamelException {
+
+
+    public SchematronValidationException(final String message, Throwable e) {
+        super(message, e);
+    }
+
+    public SchematronValidationException(String message) {
+        super(message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java
new file mode 100644
index 0000000..db506f7
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/ClassPathURIResolver.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.processor;
+
+import java.io.File;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+
+/**
+ * Class path resolver for schematron templates
+ *
+ */
+public class ClassPathURIResolver implements URIResolver {
+
+    private String rulesDir;
+
+    /**
+     * Constructor setter for rules directory path.
+     * @param rulesDir
+     */
+    public ClassPathURIResolver(final String rulesDir) {
+        this.rulesDir = rulesDir;
+    }
+
+    @Override
+    public Source resolve(String href, String base) throws TransformerException {
+        return new StreamSource(ClassLoader.getSystemResourceAsStream(rulesDir.concat(File.separator).concat(href)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java
new file mode 100644
index 0000000..8ba23ea
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessor.java
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.processor;
+
+import java.io.StringWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.camel.component.schematron.exception.SchematronValidationException;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+
+
+/**
+ * The schematoron Engine. Validates an XML for given scheamtron rules using an XSLT implementation of the Schematron
+ * Engine.
+ * <p/>
+ */
+public class SchematronProcessor {
+
+    private Logger logger = LoggerFactory.getLogger(SchematronProcessor.class);
+    private XMLReader reader;
+    private Templates templates;
+
+    /**
+     * Constructor setting the XSLT schematron templates.
+     *
+     * @param reader
+     * @param templates
+     */
+    public SchematronProcessor(XMLReader reader, Templates templates) {
+
+        this.reader = reader;
+        this.templates = templates;
+    }
+
+    /**
+     * Validates the given XML for given Rules.
+     *
+     * @param xml
+     * @return
+     */
+    public String validate(final String xml) {
+
+        try {
+            final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml)));
+            final StringWriter writer = new StringWriter();
+            templates.newTransformer().transform(source, new StreamResult(writer));
+            return writer.toString();
+        } catch (TransformerException e) {
+            logger.error(e.getMessage());
+            throw new SchematronValidationException("Failed to apply Schematron validation transform", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java
new file mode 100644
index 0000000..9e69b1b
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/SchematronProcessorFactory.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.processor;
+
+
+
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Templates;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.apache.camel.component.schematron.exception.SchematronConfigException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Schematron Engine Factory
+ *
+ */
+public final class SchematronProcessorFactory {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SchematronProcessorFactory.class);
+
+    /**
+     * Private constructor.
+     */
+    private SchematronProcessorFactory() {
+        throw new IllegalStateException();
+    }
+
+    /**
+     * Creates an instance of SchematronEngine
+     *
+     * @param rules the given schematron rules
+     * @return an instance of SchematronEngine
+     */
+    public static SchematronProcessor newScehamtronEngine(final Templates rules) {
+        try {
+            return new SchematronProcessor(getXMLReader(), rules);
+        } catch (Exception e) {
+            LOG.error("Failed to parse the configuration file");
+            throw new SchematronConfigException(e);
+        }
+    }
+
+    /**
+     * Gets XMLReader.
+     *
+     * @return instance of XMLReader
+     * @throws ParserConfigurationException
+     * @throws SAXException
+     */
+    private static XMLReader getXMLReader() throws ParserConfigurationException, SAXException {
+        final SAXParserFactory fac = SAXParserFactory.newInstance();
+        fac.setValidating(false);
+        final SAXParser parser = fac.newSAXParser();
+        XMLReader reader = parser.getXMLReader();
+        return reader;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java
new file mode 100644
index 0000000..b461c3b
--- /dev/null
+++ b/components/camel-schematron/src/main/java/org/apache/camel/component/schematron/processor/TemplatesFactory.java
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.processor;
+
+import org.apache.camel.component.schematron.constant.Constants;
+import org.apache.camel.component.schematron.exception.SchematronConfigException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Node;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import java.io.File;
+import java.io.InputStream;
+
+/**
+ * Class generating Templates for a given schematron rules
+ */
+public final class TemplatesFactory {
+
+    private static final String LINE_NUMBERING = "http://saxon.sf.net/feature/linenumbering";
+    private static final TemplatesFactory INSTANCE = new TemplatesFactory();
+    private static final String[] PIPELINE = new String[]{"iso_dsdl_include.xsl", "iso_abstract_expand.xsl", "iso_svrl_for_xslt2.xsl"};
+    private Logger logger = LoggerFactory.getLogger(TemplatesFactory.class);
+
+    /**
+     * Singleton constructor;
+     *
+     * @return
+     */
+    public static TemplatesFactory newInstance() {
+
+        return INSTANCE;
+    }
+
+    /**
+     * Returns an instance of compiled schematron templates.
+     *
+     * @return
+     */
+    public Templates newTemplates(final InputStream rules) {
+
+        TransformerFactory fac = TransformerFactory.newInstance();
+        fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR));
+        fac.setAttribute(LINE_NUMBERING, true);
+        return getTemplates(rules, fac);
+    }
+
+    /**
+     * Generate the schematron template for given rule.
+     *
+     * @param rules the schematron rules
+     * @param fac   the transformer factory.
+     * @return schematron template.
+     */
+    private Templates getTemplates(InputStream rules, TransformerFactory fac) {
+
+        Node node = null;
+        Source source = new StreamSource(rules);
+        try {
+            for (String template : PIPELINE) {
+                Source xsl = new StreamSource(ClassLoader.getSystemResourceAsStream(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR
+                        .concat(File.separator).concat(template)));
+                Transformer t = fac.newTransformer(xsl);
+                DOMResult result = new DOMResult();
+                t.transform(source, result);
+                source = new DOMSource(node = result.getNode());
+            }
+            return fac.newTemplates(new DOMSource(node));
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new SchematronConfigException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron b/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron
new file mode 100644
index 0000000..5f2af4c
--- /dev/null
+++ b/components/camel-schematron/src/main/resources/META-INF/services/org/apache/camel/component/schematron
@@ -0,0 +1,18 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+class=org.apache.camel.component.schematron.SchematronComponent

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl
new file mode 100644
index 0000000..38d2d8e
--- /dev/null
+++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	Stylesheet for extracting Schematron information from a RELAX-NG schema.
+	Based on the stylesheet for extracting Schematron information from W3C XML Schema.
+	Created by Eddie Robertsson 2002/06/01
+	Update for ISO Schematron using XSLT2 Rick Jelliffe 2010/04/14
+-->
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:rng="http://relaxng.org/ns/structure/1.0">
+	<!-- Set the output to be XML with an XML declaration and use indentation -->
+	<xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>
+	<!-- -->
+	<!-- match schema and call recursive template to extract included schemas -->
+	<!-- -->
+	<xsl:template match="/rng:grammar | /rng:element">
+		<!-- call the schema definition template ... -->
+		<xsl:call-template name="gatherSchema">
+			<!-- ... with current node as the $schemas parameter ... -->
+			<xsl:with-param name="schemas" select="."/>
+			<!-- ... and any includes in the $include parameter -->
+			<xsl:with-param name="includes" select="document(/rng:grammar/rng:include/@href
+| //rng:externalRef/@href)"/>
+		</xsl:call-template>
+	</xsl:template>
+	<!-- -->
+	<!-- gather all included schemas into a single parameter variable -->
+	<!-- -->
+	<xsl:template name="gatherSchema">
+		<xsl:param name="schemas"/>
+		<xsl:param name="includes"/>
+		<xsl:choose>
+			<xsl:when test="count($schemas) &lt; count($schemas | $includes)">
+				<!-- when $includes includes something new, recurse ... -->
+				<xsl:call-template name="gatherSchema">
+					<!-- ... with current $includes added to the $schemas parameter ... -->
+					<xsl:with-param name="schemas" select="$schemas | $includes"/>
+					<!-- ... and any *new* includes in the $include parameter -->
+					<xsl:with-param name="includes" select="document($includes/rng:grammar/rng:include/@href
+| $includes//rng:externalRef/@href)"/>
+				</xsl:call-template>
+			</xsl:when>
+			<xsl:otherwise>
+				<!-- we have the complete set of included schemas, so now let's output the embedded schematron -->
+				<xsl:call-template name="output">
+					<xsl:with-param name="schemas" select="$schemas"/>
+				</xsl:call-template>
+			</xsl:otherwise>
+		</xsl:choose>
+	</xsl:template>
+	<!-- -->
+	<!-- output the schematron information -->
+	<!-- -->
+	<xsl:template name="output">
+		<xsl:param name="schemas"/>
+		<!-- -->
+		<sch:schema  queryBinding="xslt2" >
+			<!-- get header-type elements - eg title and especially ns -->
+			<!-- title (just one) -->
+			<xsl:copy-of select="$schemas//sch:title[1]"/>
+			<!-- get remaining schematron schema children -->
+			<!-- get non-blank namespace elements, dropping duplicates -->
+			<xsl:for-each select="$schemas//sch:ns">
+				<xsl:if test="generate-id(.) = generate-id($schemas//sch:ns[@prefix = current()/@prefix][1])">
+					<xsl:copy-of select="."/>
+				</xsl:if>
+			</xsl:for-each>
+			<xsl:copy-of select="$schemas//sch:phase"/>
+			<xsl:copy-of select="$schemas//sch:pattern"/>
+			<sch:diagnostics>
+				<xsl:copy-of select="$schemas//sch:diagnostics/*"/>
+			</sch:diagnostics>
+		</sch:schema>
+	</xsl:template>
+	<!-- -->
+</xsl:transform>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl
new file mode 100644
index 0000000..7d1cbfb
--- /dev/null
+++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+        based on an original transform by Eddie Robertsson
+        2001/04/21      fn: added support for included schemas
+        2001/06/27      er: changed XMl Schema prefix from xsd: to xs: and changed to the Rec namespace
+        2010/04/14    	rj: Update for ISO Schematron using xslt2
+-->
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+        <!-- Set the output to be XML with an XML declaration and use indentation -->
+        <xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>
+        <!-- -->
+        <!-- match schema and call recursive template to extract included schemas -->
+        <!-- -->
+        <xsl:template match="xs:schema">
+                <!-- call the schema definition template ... -->
+                <xsl:call-template name="gatherSchema">
+                        <!-- ... with current current root as the $schemas parameter ... -->
+                        <xsl:with-param name="schemas" select="/"/>
+                        <!-- ... and any includes in the $include parameter -->
+                        <xsl:with-param name="includes" 
+						select="document(/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>
+                </xsl:call-template>
+        </xsl:template>
+        <!-- -->
+        <!-- gather all included schemas into a single parameter variable -->
+        <!-- -->
+        <xsl:template name="gatherSchema">
+                <xsl:param name="schemas"/>
+                <xsl:param name="includes"/>
+                <xsl:choose>
+                        <xsl:when test="count($schemas) &lt; count($schemas | $includes)">
+                                <!-- when $includes includes something new, recurse ... -->
+                                <xsl:call-template name="gatherSchema">
+                                        <!-- ... with current $includes added to the $schemas parameter ... -->
+                                        <xsl:with-param name="schemas" select="$schemas | $includes"/>
+                                        <!-- ... and any *new* includes in the $include parameter -->
+                                        <xsl:with-param name="includes" 
+										select="document($includes/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>
+                                </xsl:call-template>
+                        </xsl:when>
+                        <xsl:otherwise>
+                                <!-- we have the complete set of included schemas, 
+								so now let's output the embedded schematron -->
+                                <xsl:call-template name="output">
+                                        <xsl:with-param name="schemas" select="$schemas"/>
+                                </xsl:call-template>
+                        </xsl:otherwise>
+                </xsl:choose>
+        </xsl:template>
+        <!-- -->
+        <!-- output the schematron information -->
+        <!-- -->
+        <xsl:template name="output">
+                <xsl:param name="schemas"/>
+                <!-- -->
+                <sch:schema queryBinding="xslt2">
+                        <!-- get header-type elements - eg title and especially ns -->
+                        <!-- title (just one) -->
+                        <xsl:copy-of select="$schemas//xs:appinfo/sch:title[1]"/>
+                        <!-- get remaining schematron schema children -->
+                        <!-- get non-blank namespace elements, dropping duplicates -->
+                        <xsl:for-each select="$schemas//xs:appinfo/sch:ns">
+                                <xsl:if test="generate-id(.) = 
+								generate-id($schemas//xs:appinfo/sch:ns[@prefix = current()/@prefix][1])">
+                                        <xsl:copy-of select="."/>
+                                </xsl:if>
+                        </xsl:for-each>
+                        <xsl:copy-of select="$schemas//xs:appinfo/sch:phase"/>
+                        <xsl:copy-of select="$schemas//xs:appinfo/sch:pattern"/>
+                        <sch:diagnostics>
+                                <xsl:copy-of select="$schemas//xs:appinfo/sch:diagnostics/*"/>
+                        </sch:diagnostics>
+                </sch:schema>
+        </xsl:template>
+        <!-- -->
+</xsl:transform>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl
new file mode 100644
index 0000000..f2f1667
--- /dev/null
+++ b/components/camel-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl
@@ -0,0 +1,297 @@
+<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
+
+<!-- 
+     OVERVIEW - iso_abstract_expand.xsl
+     
+	    This is a preprocessor for ISO Schematron, which implements abstract patterns. 
+	    It also 
+	       	* extracts a particular schema using an ID, where there are multiple 
+	    schemas, such as when they are embedded in the same NVDL script 
+	    	* experimentally, allows parameter recognition and substitution inside
+	    	text as well as @context, @test, & @select.
+		
+		
+		This should be used after iso-dsdl-include.xsl and before the skeleton or
+		meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1.
+		 
+		Each kind of inclusion can be turned off (or on) on the command line.
+		 
+-->
+<!-- 
+  VERSION INFORMATION
+  2008-09-18 RJ
+  		* move out param test from iso:schema template  to work with XSLT 1. (Noah Fontes)
+  		
+  2008-07-29 RJ 
+  		* Create.  Pull out as distinct XSL in its own namespace from old iso_pre_pro.xsl
+  		* Put everything in private namespace
+  		* Rewrite replace_substring named template so that copyright is clear
+  	
+  2008-07-24 RJ
+       * correct abstract patterns so for correct names: param/@name and
+     param/@value
+    
+  2007-01-12  RJ 
+     * Use ISO namespace
+     * Use pattern/@id not  pattern/@name 
+     * Add Oliver Becker's suggests from old Schematron-love-in list for <copy> 
+     * Add XT -ism?
+  2003 RJ
+     * Original written for old namespace
+     * http://www.topologi.com/resources/iso-pre-pro.xsl
+-->	
+<!--
+ LEGAL INFORMATION
+ 
+ Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
+
+ This software is provided 'as-is', without any express or implied warranty. 
+ In no event will the authors be held liable for any damages arising from 
+ the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose, 
+ including commercial applications, and to alter it and redistribute it freely,
+ subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim
+ that you wrote the original software. If you use this software in a product, 
+ an acknowledgment in the product documentation would be appreciated but is 
+ not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be 
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+-->
+<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" 
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+    xmlns:iso="http://purl.oclc.org/dsdl/schematron"  
+    xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"  
+    
+    xmlns:iae="http://www.schematron.com/namespace/iae" 
+     
+      >
+	
+	<xslt:param name="schema-id"></xslt:param>
+	
+	
+	<!-- Driver for the mode -->
+	<xsl:template match="/">
+  		<xsl:apply-templates select="." mode="iae:go" />
+	</xsl:template> 
+	
+	
+	<!-- ================================================================================== -->
+	<!-- Normal processing rules                                                            -->
+	<!-- ================================================================================== -->
+	<!-- Output only the selected schema --> 
+	<xslt:template match="iso:schema" >
+	    <xsl:if test="string-length($schema-id) =0 or @id= $schema-id ">
+	    	<xslt:copy>
+				<xslt:copy-of select="@*" />
+				<xslt:apply-templates  mode="iae:go" /> 
+			</xslt:copy>
+		</xsl:if>
+	</xslt:template>
+	
+ 
+	<!-- Strip out any foreign elements above the Schematron schema .
+		-->
+	<xslt:template match="*[not(ancestor-or-self::iso:*)]"     mode="iae:go"  >
+	   <xslt:apply-templates  mode="iae:go" />
+	</xslt:template>
+	   
+	
+	<!-- ================================================================================== -->
+	<!-- Handle Schematron abstract pattern preprocessing                                   -->
+	<!-- abstract-to-real calls
+			do-pattern calls 
+				macro-expand calls 
+					multi-macro-expand
+						replace-substring                                                   -->
+	<!-- ================================================================================== -->
+	
+	<!--
+		Abstract patterns allow you to say, for example
+		
+		<pattern name="htmlTable" is-a="table">
+			<param name="row" value="html:tr"/>
+			<param name="cell" value="html:td" />
+			<param name="table" value="html:table" />
+		</pattern>
+		
+		For a good introduction, see Uche Ogbujii's article for IBM DeveloperWorks
+		"Discover the flexibility of Schematron abstract patterns"
+		  http://www-128.ibm.com/developerworks/xml/library/x-stron.html
+		However, note that ISO Schematron uses @name and @value attributes on
+		the iso:param element, and @id not @name on the pattern element.
+		
+	-->
+	
+	<!-- Suppress declarations of abstract patterns -->
+	<xslt:template match="iso:pattern[@abstract='true']"  mode="iae:go"  >
+		<xslt:comment>Suppressed abstract pattern <xslt:value-of select="@id"/> was here</xslt:comment>	
+	</xslt:template> 
+	
+	
+	<!-- Suppress uses of abstract patterns -->
+	<xslt:template match="iso:pattern[@is-a]"  mode="iae:go" >
+			
+		<xslt:comment>Start pattern based on abstract <xslt:value-of select="@is-a"/></xslt:comment>
+		
+		<xslt:call-template name="iae:abstract-to-real" >
+			<xslt:with-param name="caller" select="@id" />
+			<xslt:with-param name="is-a" select="@is-a" />
+		</xslt:call-template>
+			
+	</xslt:template>
+	 
+	 
+	
+	<!-- output everything else unchanged -->
+	<xslt:template match="*" priority="-1"  mode="iae:go" >
+	    <xslt:copy>
+			<xslt:copy-of select="@*" />
+			<xslt:apply-templates mode="iae:go"/> 
+		</xslt:copy>
+	</xslt:template>
+	
+	<!-- Templates for macro expansion of abstract patterns -->
+	<!-- Sets up the initial conditions for the recursive call -->
+	<xslt:template name="iae:macro-expand">
+		<xslt:param name="caller"/>
+		<xslt:param name="text" />
+		<xslt:call-template name="iae:multi-macro-expand">
+			<xslt:with-param name="caller" select="$caller"/>
+			<xslt:with-param name="text" select="$text"/>
+			<xslt:with-param name="paramNumber" select="1"/>
+		</xslt:call-template>
+		
+	</xslt:template>
+	
+	<!-- Template to replace the current parameter and then
+	   recurse to replace subsequent parameters. -->
+	    
+	<xslt:template name="iae:multi-macro-expand">
+		<xslt:param name="caller"/>
+		<xslt:param name="text" />
+		<xslt:param name="paramNumber" />
+
+		
+		<xslt:choose>
+			<xslt:when test="//iso:pattern[@id=$caller]/iso:param[ $paramNumber]">
+
+				<xslt:call-template name="iae:multi-macro-expand">
+					<xslt:with-param name="caller" select="$caller"/>	
+					<xslt:with-param name="paramNumber" select="$paramNumber + 1"/>		
+					<xslt:with-param name="text" >
+						<xslt:call-template name="iae:replace-substring">
+							<xslt:with-param name="original" select="$text"/>
+							<xslt:with-param name="substring"
+							select="concat('$', //iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@name)"/>
+							<xslt:with-param name="replacement"
+								select="//iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@value"/>			
+						</xslt:call-template>
+					</xslt:with-param>						
+				</xslt:call-template>
+			</xslt:when>
+			<xslt:otherwise><xslt:value-of select="$text" /></xslt:otherwise>		
+		
+		</xslt:choose>
+	</xslt:template>
+	
+	
+	<!-- generate the real pattern from an abstract pattern + parameters-->
+	<xslt:template name="iae:abstract-to-real" >
+		<xslt:param name="caller"/>
+		<xslt:param name="is-a" />
+		<xslt:for-each select="//iso:pattern[@id= $is-a]">
+		<xslt:copy>
+		
+		    <xslt:choose>
+		      <xslt:when test=" string-length( $caller ) = 0">
+		      <xslt:attribute name="id"><xslt:value-of select="concat( generate-id(.) , $is-a)" /></xslt:attribute>
+		      </xslt:when>
+		      <xslt:otherwise>
+				<xslt:attribute name="id"><xslt:value-of select="$caller" /></xslt:attribute>
+		      </xslt:otherwise>
+		    </xslt:choose> 
+			
+			<xslt:apply-templates select="*|text()" mode="iae:do-pattern"    >
+				<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+			</xslt:apply-templates>	
+			
+		</xslt:copy>
+		</xslt:for-each>
+	</xslt:template>
+		
+	
+	<!-- Generate a non-abstract pattern -->
+	<xslt:template mode="iae:do-pattern" match="*">
+		<xslt:param name="caller"/>
+		<xslt:copy>
+			<xslt:for-each select="@*[name()='test' or name()='context' or name()='select']">
+				<xslt:attribute name="{name()}">
+				<xslt:call-template name="iae:macro-expand">
+						<xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
+						<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+					</xslt:call-template>
+				</xslt:attribute>
+			</xslt:for-each>	
+			<xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select']" />
+			<xsl:for-each select="node()">
+				<xsl:choose>
+				    <!-- Experiment: replace macros in text as well, to allow parameterized assertions
+				        and so on, without having to have spurious <iso:value-of> calls and multiple
+				        delimiting -->
+					<xsl:when test="self::text()">	
+						<xslt:call-template name="iae:macro-expand">
+							<xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
+							<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+						</xslt:call-template>
+					</xsl:when>
+					<xsl:otherwise>
+						<xslt:apply-templates select="." mode="iae:do-pattern">
+							<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+						</xslt:apply-templates>		
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:for-each>			
+		</xslt:copy>
+	</xslt:template>
+	
+	<!-- UTILITIES --> 
+	<!-- Simple version of replace-substring function -->
+	<xslt:template name="iae:replace-substring">
+		<xslt:param name="original" />    
+		<xslt:param name="substring" />   
+		<xslt:param name="replacement" select="''"/>
+		
+  <xsl:choose>
+    <xsl:when test="not($original)" /> 
+    <xsl:when test="not(string($substring))">
+      <xsl:value-of select="$original" />
+    </xsl:when> 
+        <xsl:when test="contains($original, $substring)">
+          <xsl:variable name="before" select="substring-before($original, $substring)" />
+          <xsl:variable name="after" select="substring-after($original, $substring)" />
+          
+          <xsl:value-of select="$before" />
+          <xsl:value-of select="$replacement" />
+          <!-- recursion -->
+          <xsl:call-template name="iae:replace-substring">
+            <xsl:with-param name="original" select="$after" />
+            <xsl:with-param name="substring" select="$substring" />
+            <xsl:with-param name="replacement" select="$replacement" /> 
+            </xsl:call-template>
+        </xsl:when>
+        <xsl:otherwise>
+        	<!-- no substitution -->
+        	<xsl:value-of select="$original" />
+        </xsl:otherwise>
+      </xsl:choose> 
+</xslt:template>
+
+
+
+</xslt:stylesheet>
\ No newline at end of file