我最近创建了一个ANT构建文件,以便使用xslt将.xml文件转换为.fo。并且ANT构建的性能与设计一致。但是,输入文件被硬编码到XSLT任务中。
如何动态更改输入文件名,而不必每次都编辑构建文件?以下是我的代码片段。
<target name="createFO"
description="Transform using XSLT 1.0" depends="clean, copyimg, copysrc">
<xslt basedir="${srcdir}"
destdir="${dstDir}"
extension=".fo"
style="${ss}/foobar.xsl"
in="sample.xml"
out="${dstDir}/new.fo"/>
<echo>The fo file has been created!</echo>
</target>我没有提到我正在使用OxygenXML来处理我的ANT文件。抱歉的。
发布于 2014-07-10 23:56:24
您不需要in和out属性。相反,您可以使用包含要转换的文件的<fileset>。
<xslt>将从输入文件中剥离后缀,并应用extension属性中使用的后缀。
<target name="createFO"
description="Transform using XSLT 1.0" depends="clean, copyimg, copysrc">
<!-- Don't put "basedir" parameter. It comes from fileset! -->
<xslt destdir="${dstDir}"
extension=".fo"
style="${ss}/foobar.xsl">
<fileset dir="${xslt.dir}"/>
</xslt>
<echo>The fo file has been created!</echo>
</target>您还可以使用mappers将输入文件的名称转换为输出文件名称。
当然,另一种方法是使用一个属性作为输入文件名,然后让某人将文件名传递给Ant脚本:
<target name="createFO"
description="Transform using XSLT 1.0" depends="clean, copyimg, copysrc">
<fail message="You must pass in the parameter &auot;-Dxml.file=..."">
<condition>
<not>
<available file="${xml.file}">
</condition>
</fail>
<xslt basedir="${srcdir}"
destdir="${dstDir}"
extension=".fo"
style="${ss}/foobar.xsl"
in="${xml.file}"
out="${dstDir}/new.fo"/>
<echo>The fo file has been created!</echo>
</target>现在,要运行这段代码,您需要执行以下操作:
$ ant -Dxml.file=sample.xml createFOhttps://stackoverflow.com/questions/24680329
复制相似问题