Skip to content
Philip Helger edited this page Dec 6, 2023 · 7 revisions

goal to convert Schematron to XSLT at build time

Maven plugin to convert Schematron (SCH) to XSLT at compile time using ph-schematron-xslt as the converter.

The conversion of Schematron to XSLT may be quite time consuming. That’s why this Maven plugin that does the conversion at build time to avoid perfoming the conversion every time.

By default the plugin is run in the Maven lifecycle phase generate-resources. The basic configuration of the plugin in the pom.xml looks like this (inside the <build>/<plugins> element), replacing x.y.z with the latest version number.

<plugin>
  <groupId>com.helger.maven</groupId>
  <artifactId>ph-schematron-maven-plugin</artifactId>
  <version>x.y.z</version>
  <executions>
    <execution>
      <goals>
        <goal>convert</goal>
      </goals>
    </execution>
  </executions>
</plugin>

The possible configuration parameters are:

  • schematronDirectory - The directory where the Schematron files reside. Defaults to ${basedir}/src/main/schematron.
  • schematronPattern - A pattern for the Schematron files. Can contain Ant-style wildcards and double wildcards. All files that match the pattern will be converted. Files in the schematronDirectory and its subdirectories will be considered. Default is **/*.sch.
  • xsltDirectory - The directory where the XSLT files will be saved. Default is ${basedir}/src/main/xslt.
  • xsltExtension - The file extension of the created XSLT files. Default is .xslt.
  • overwriteWithoutQuestion - Overwrite existing Schematron files without notice? If this is set to false than existing XSLT files are not overwritten. Default is true.
  • phaseName - Define the phase to be used for XSLT creation. By default the defaultPhase attribute of the Schematron file is used.
  • languageCode - Define the language code for the XSLT creation. Default is null which means English. Supported language codes are: cs, de, en, fr, nl.
    • parameters (since v5.0.2) - A map to provide custom parameter for the Schematron XSLTs (as in allow-foreign). Example:
<configuration>
  ...
  <parameters> 
    <allow-foreign>true</allow-foreign>
    <anything>else</anything>
  </parameters>    
  ...
</configuration>
  • forceCacheResult (since v.5.2.1) - Force the caching of results from SCH to XSLT.
  • xsltHeader (since v6.2.2) - An optional header text that is added to all created XSLT files. The text will be added as an XML comment and can be multiline.
  • showProgress (since v6.2.8) - Enable or disable the progress indicator, if the conversion takes longer then 5 seconds. Enabled by default.

goal to validate XML instances against Schematron rules

Maven plugin to validate XML files against convert Schematron (SCH) at compile time using ph-schematron as the validator.

This plugin was introduced in version 4.2.0.

By default the plugin is run in the Maven lifecycle phase process-resources. The basic configuration of the plugin in the pom.xml looks like this (inside the <build>/<plugins> element), replacing x.y.z with the latest version number:

<plugin>
  <groupId>com.helger.maven</groupId>
  <artifactId>ph-schematron-maven-plugin</artifactId>
  <version>x.y.z</version>
  <executions>
    <execution>
      <goals>
        <goal>validate</goal>
      </goals>
    </execution>
  </executions>
</plugin>

The possible configuration parameters are:

  • schematronFile - The Schematron file to be applied. This parameter is mandatory.
  • schematronProcessingEngine - The Schematron processing engine to be used. Can be one of pure (pure implementation), schematron (Schematron to XSLT engine) and xslt (pre-compiled XSLT files available). Default is schematron since v6 (was previously pure).
  • xmlDirectory - The directory where the XML files to be validated are contained. It is expected that the XML files in this directory match the Schematron rules. Either this parameter or xmlErrorDirectory parameter are mandatory.
  • xmlIncludes - A pattern for the XML files to be included. Can contain Ant-style wildcards and double wildcards. All files that match the pattern will be validated. Files in the xmlDirectory and its subdirectories will be considered. Default is **/*.xml. Since v6.2.1 this is of type String[], previously it was String.
  • xmlExcludes - A pattern for the XML files to be excluded. Can contain Ant-style wildcards and double wildcards. All files that match the pattern will NOT be validated. Files in the xmlDirectory and its subdirectories will be considered. Since v6.2.1 this is of type String[], previously it was String.
  • svrlDirectory - The directory where the SVRL (Schematron Validation Report Language) files will be saved. If this property is not specified, no SVRL files will be written. By default the name of the SVRL file corresponds to the XML file that is validated (defined by the parameters xmlDirectory, xmlIncludes and xmlExcludes) with the suffix .svrl.
  • xmlErrorDirectory (since v4.3.0) - The directory where the XML files to be validated are contained. It is expected that the XML files in this directory do not match the Schematron rules. Either this parameter or xmlDirectory parameter are mandatory.
  • xmlErrorIncludes (since v4.3.0) - A pattern for the erroneous XML files to be included. Can contain Ant-style wildcards and double wildcards. All files that match the pattern will be validated. Files in the xmlDirectory and its subdirectories will be considered. Default is **/*.xml. Since v6.2.1 this is of type String[], previously it was String.
  • xmlErrorExcludes (since v4.3.0) - A pattern for the erroneous XML files to be excluded. Can contain Ant-style wildcards and double wildcards. All files that match the pattern will NOT be validated. Files in the xmlDirectory and its subdirectories will be considered. Since v6.2.1 this is of type String[], previously it was String.
  • svrlErrorDirectory (since v4.3.0) - The directory where the erroneous SVRL files will be saved. If this property is not specified, no SVRL files will be written. By default the name of the SVRL file corresponds to the XML file that is validated (defined by the parameters xmlErrorDirectory, xmlErrorIncludes and xmlErrorExcludes) with the suffix .svrl.
  • phaseName - Define the phase to be used for XSLT creation. By default the defaultPhase attribute of the Schematron file is used.
  • languageCode - Define the language code for the XSLT creation. Default is null which means English. Supported language codes are: cs, de, en, fr, nl.
  • parameters (since v5.0.2) - Custom attributes to be used for the SCH to XSLT conversion. This parameter takes only effect when using schematronProcessingEngine "schematron" or "xslt". By default no parameter is present.
  • failFast (since v5.0.5) - If multiple XML files are validated this parameter defines whether the execution should fail at the first error (value true) or at the end only (value false). The default value is true.
  • forceCacheResult (since v5.2.1) - Force the caching of results of the conversion from SCH to XSLT (the default is false)
  • lenient (since v5.4.1) - If enabled, old deprecated Schematron namespace URIs can be read. This only has an effect when used with the "pure" engine (the default is false)
  • ignoreWarnings (since v7.1.2) - If enabled, warnings will not be emitted and will not make the validation fail (the default is false)

goal to preprocess Schematron files

Maven plugin to preprocess a Schematron file and write the resulting file to disk.

This plugin was introduced in version 5.0.9.

By default the plugin is run in the Maven lifecycle phase generate-resources. The basic configuration of the plugin in the pom.xml looks like this (inside the <build>/<plugins> element), replacing x.y.z with the latest version number:

<plugin>
  <groupId>com.helger.maven</groupId>
  <artifactId>ph-schematron-maven-plugin</artifactId>
  <version>x.y.z</version>
  <executions>
    <execution>
      <goals>
        <goal>preprocess</goal>
      </goals>
    </execution>
  </executions>
</plugin>

The possible configuration parameters are:

  • sourceFile - The source Schematron file to be preprocessed. This parameter is mandatory.
  • targetFile - The target (preprocessed) Schematron file to be written. This parameter is mandatory.
  • overwriteWithoutNotice - Overwrite existing Schematron files without notice? If this is set to false than existing Schematron files are not overwritten. The default value is true.
  • keepTitles - If this is set to false than <title> elements will be removed. The default value is false.
  • keepDiagnostics - If this is set to false than <diagnostic> elements will be removed. The default value is false.
  • keepReports - Should <report> elements be kept or should they be converted to <assert> elements? The default value is false.
  • keepEmptyPatterns - Should <pattern> elements without a single rule be kept or deleted? The default value is false.
  • schHeader (since v6.2.2) - An optional header text that is added to all created SCH files. The text will be added as an XML comment and can be multiline.