Maven XSLT Transformations

I’ve been migrating some builds away from Ant and over to Maven 3.   While in most cases I could use the maven ant plugin, to run most of the scripts, it is better to just adopt the new Maven based way of building.    Maven has an XML plugin that allows you to do both XSLT transformations as well as XML Validation; however, it does leave one import optional configuration element undocumented, where you output the files. The undocumented outputDirectory option allows you to specify where the files will be created. By default, the transformation goal will output to the target/generated-resources/xml/XSLT directory. It also binds by default to the generate-resources phase. All of which is configurable.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
           <goals>
               <goal>transform</goal>
           </goals>
        </execution>
    </executions>
    <configuration>
        <transformationSets>
             <transformationSet>
                  <dir>STAR/Rev/BODs/Developer</dir>
                  <stylesheet>STAR/Utilities/XSLTFlatten/XSLTFlatten.xsl</stylesheet>
                  <outputDir>target/generated-resources/STAR/Rev/BODs/Standalone</outputDir>
                  <parameters>
                       <parameter>
                          <name>nounLocation</name>
                              <value>file://${basedir}/STAR/Rev/Resources/Nouns</value>
                          </parameter>
                       <parameter>
                          <name>componentsLocation</name>
                          <value>file://${basedir}/STAR/Rev/Resources/Components/Common/Components.xsd</value>
                       </parameter>
                       <parameter>
                           <name>deprecatedLocation</name>
                           <value>file://${basedir}/STAR/Rev/Resources/Components/Common/DeprecatedComponents.xsd</value>
                       </parameter>
                       <parameter>
                           <name>fieldsLocation</name>
                           <value>file://${basedir}/STAR/Rev/Resources/Components/Common/Fields.xsd</value>
                       </parameter>
                       <parameter>
                           <name>metaLocation</name>
                           <value>file://${basedir}/STAR/Rev/Resources/Components/Common/Meta.xsd</value>
                       </parameter>
                   </parameters>
              </transformationSet>
          </transformationSets>
     </configuration>
     <dependencies>
       <dependency>
           <groupId>net.sf.saxon</groupId>
           <artifactId>saxon</artifactId>
           <version>8.7</version>
       </dependency>
     </dependencies>
</plugin>
Advertisements
This entry was posted in agile, maven, xml, xsl, xslt. Bookmark the permalink.

3 Responses to Maven XSLT Transformations

  1. Yan says:

    How do you catch you XSL parameters in the XSL source file ?

  2. sree says:

    i tried to access maven parameter like .. my maven has it as
    MyParam
    sree
    . i was not able to get in xsl. what am i doing wrong here?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s