Saxon feature keys for initial template and mode

Inasmuch as a “feature key” is how you configure a Java JAXP XSLT processor, it’s good to see that Saxon 9.3 has added feature keys for setting the initial template and initial mode. In fact, Saxon has gone from 30 feature keys in Saxon 9.0 to 70 in 9.2 and now 79 in 9.3.

Where this becomes useful (outside of your own Java programs) is being able to specify the initial template and/or mode in the <xslt> task in Ant build files. Previously, if you needed to specify either, you could only run the net.sf.saxon.Transform class with the <java> task and provide command line arguments or, when processing multiple files at once, both run Java as an external program using the <apply> task and handle the dependencies yourself.

So the good, and more readable, news is that this:

<target name="new.build"
        description="Make a build file for a translation.">
  <exec executable="java"
        dir="${basedir}"
        output="build.xml">
    <arg value="-cp" />
    <arg file="${saxon.jar}" />
    <arg value="net.sf.saxon.Transform" />
    <arg value="-xsl:${xsl.dir}/build.xsl" />
    <arg value="-it:build" />
    <arg value="build.properties=${basedir.converted}/build.properties"/>
  </exec>
</target>

can, with extra dependency checking added, become:

<target name="new.build"
        description="Make a build file for a translation.">
  <dependset>
    <srcfileset file="${xsl.dir}/build.xsl" />
    <srcfileset file="${basedir.converted}/build.properties" />
    <targetfileset file="${basedir}/build.xml" />
  </dependset>
  <xslt in="${xsl.dir}/build.xsl"
        out="${basedir}/build.xml"
        style="${xsl.dir}/build.xsl"
        classpath="${saxon.jar}">
    <factory name="net.sf.saxon.TransformerFactoryImpl">
      <attribute
          name="http://saxon.sf.net/feature/initialTemplate"
          value="build"/>
    </factory>
    <param name="build.properties"
           expression="${basedir.converted}/build.properties"/>
  </xslt>
</target>

But I’m still stumped over whether it’s possible (without resorting to either scripting or using <apply> to run another Ant) to use <xslt> with an initial template over a range of non-XML files where, for each in turn, the filename is passed to the transform as a parameter, i.e., to rework this to use <xslt>:

<target name="lines">
  <dependset>
    <srcfileset file="${books}" />
    <srcfileset file="${xsl.dir}/lines.xsl" />
    <targetfileset dir="${stages.dir}/${stage.lines}"
                   includes="*.tstamp" />
  </dependset>

  <echo>Stage 0: lines</echo>
  <mkdir dir="${stages.dir}/${stage.lines}" />
  <apply executable="java"
         dir="${stages.dir}/${stage.lines}"
         logerror="true">
    <arg value="-cp" />
    <arg file="${saxon.jar}" />
    <arg value="net.sf.saxon.Transform" />
    <arg value="-ext:on" />
    <arg value="-xsl:${xsl.dir}/lines.xsl" />
    <arg value="-it:doc" />
    <arg value="books=file://${books}"/>
    <arg value="encoding=${encoding}"/>
    <srcfile prefix="doc="/>
    <fileset dir="${basedir.converted}/sources"
             includes="*${suffix}"/>
    <mapper type="glob"
            from="*${suffix}"
            to="${stages.dir}/${stage.lines}/*.tstamp"/>
    <redirector>
      <!-- redirect STDOUT to make timestamp file in dest-dir -->
      <outputmapper type="glob"
                    from="*${suffix}"
                    to="${stages.dir}/${stage.lines}/*.tstamp"/>
    </redirector>
  </apply>
</target>