Ant XSLT task to build on mutiple dependencies
I have an XSL style sheet that merges external documents, this way
<xsl:copy-of select="document('snippets.xml')/snippets/xxxx/form"/>
I w开发者_运维知识库ould like that the XSLT Ant build task rebuilds if the file or any of its dependencies changed.
The current Ant task looks like this
<xslt basedir="xxxx/pages/${doc.locale}"
destdir="xxxx/dir/${doc.locale}"
includes="*.xml"
excludes="snippets.xml"
style="build/xxxx/${doc.locale}/myStyle.xsl">
<param name="lang" expression="${doc.locale}"/>
<xmlcatalog refid="docDTDs"/>
Basically I would like to rebuild if the snippets.xml document is changed.
Ant has the uptodate
task to check if a target is up-to-date, file modtime-wise, from a set of source files. I'm not completely clear on what your dependency is since the XSLT task could create multiple files (resulting in multiple targets), or if it creates a single file. One of your comments imply a single file.
The following is one way to use uptodate
. You basically use the task to set a property that can then be put in the unless
attribute of a target:
<property name="file.that.depends.on.snippets"
location="some/path"/>
<property name="snippets.file"
location="xxxx/pages/${doc.locale}/snippets.xml"/>
<target name="process-snippets"
unless="snippets.uptodate"
depends="snippets-uptodate-check">
<xslt basedir="xxxx/pages/${doc.locale}"
destdir="xxxx/dir/${doc.locale}"
includes="*.xml"
excludes="snippets.xml"
style="build/xxxx/${doc.locale}/myStyle.xsl">
<param name="lang" expression="${doc.locale}"/>
<xmlcatalog refid="docDTDs"/>
</xslt>
</target>
<target name="snippets-uptodate-check">
<uptodate property="snippets.uptodate"
targetfile="$file.that.depends.on.snippets">
<srcfiles dir="xxxx/pages/${doc.locale}"
includes="*.xml"
excludes="snippets.xml"/>
</uptodate>
</target>
The XSLT task should do this for you by default. It has an optional "force" attribute
Recreate target files, even if they are newer than their corresponding source files or the stylesheet
which is false by default. So by default, unless you override with the "force" attribute, dependencies are checked by the XSLT task.
精彩评论