Fork me on GitHub

Using an alternative XSLT processor

An alternative XSLT processor is important, if you want to use XSLT 2.0 stylesheets or if you would like to work around a bug in your JRE's stylesheet processor. As of this writing, Saxon is the only XSLT 2.0 compliant processor, so we take this as an example.

Changing the XSLT processor is as simple as specifying it as a dependency:

  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>transform</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <transformationSets>
            <transformationSet>
              <dir>src/main/xml</dir>
              <stylesheet>src/main/stylesheet.xsl</stylesheet>
            </transformationSet>
          </transformationSets>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>saxon</artifactId>
            <version>8.7</version>
          </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
  </build>

If you would like to know, which XSLT processor and/or version you are actually using, add code like the following to your stylesheet:

  <xsl:comment>
    XSLT Version = <xsl:copy-of select="system-property('xsl:version')"/>
    XSLT Vendor = <xsl:copy-of select="system-property('xsl:vendor')"/>
    XSLT Vendor URL = <xsl:copy-of select="system-property('xsl:vendor-url')"/>
  </xsl:comment>